@modulbank/sendamo
Advanced tools
Comparing version 0.0.26-beta-sm-8778-integration-with-cityes-add-d0eb089e to 0.0.26-beta-sm-8778-integration-with-cityes-add-f179c01e
@@ -15,2 +15,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
function cookieSet(array, hour, domain) { | ||
const getExpires = () => { | ||
const date = new Date(); | ||
if (hour) { | ||
date.setTime(date.getTime() + hour * 3600 * 1000); | ||
return `expires=${date.toUTCString()};`; | ||
} | ||
return ''; | ||
}; | ||
const getDomain = () => { | ||
if (domain) | ||
return `domain=${domain};`; | ||
return ''; | ||
}; | ||
for (const pair of array) { | ||
document.cookie = `${pair[0]}=${pair[1]}; ${getDomain()} ${getExpires()} path=/`; | ||
} | ||
} | ||
export default function SandAmo(amoUrl) { | ||
@@ -56,7 +74,4 @@ const url = amoUrl; | ||
// Идентификатор, если пришел в поисковых систем | ||
let searchEngine = ((_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.referrer) || current.src; | ||
const utmSource = getCookie("utm_source"); | ||
if (utmSource) { | ||
searchEngine = utmSource; | ||
} | ||
const searchEngine = utmSource !== undefined && utmSource !== '' ? utmSource : (((_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.referrer) || current.src); | ||
const params = { | ||
@@ -86,21 +101,16 @@ // @ts-ignore | ||
return new Promise((resolve, reject) => { | ||
const url = new URL('https://postback.cityads.com/service/postback/'); | ||
url.searchParams.set('campaign_secret', 'oPBnE0'); | ||
url.searchParams.set('order_id', orderId); | ||
url.searchParams.set('click_id', clickId); | ||
// @ts-ignore | ||
fetch(url.toString(), { | ||
method: 'GET' | ||
}) | ||
.then((response) => __awaiter(this, void 0, void 0, function* () { | ||
if (response.status === 200) { | ||
resolve(response); | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', `https://postback.cityads.com/service/postback/?campaign_secret=oPBnE0&order_id=${orderId}&click_id=${clickId}`, true); | ||
xhr.onload = function () { | ||
if (xhr.status === 200) { | ||
resolve(xhr.responseText); | ||
} | ||
else { | ||
throw new Error(yield response.json()); | ||
reject(new Error(`Postback request failed with status: ${xhr.status}`)); | ||
} | ||
})) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}; | ||
xhr.onerror = function () { | ||
reject(new Error('Network error occurred during postback request.')); | ||
}; | ||
xhr.send(); | ||
}); | ||
@@ -120,8 +130,14 @@ } | ||
if (response.status === 200) { | ||
const orderId = getCookie("order_id"); | ||
const clickId = getCookie("click_id"); | ||
const responseData = yield response.json(); | ||
const utmSource = getCookie("utm_source"); | ||
console.log(response); | ||
if (utmSource === "cityads") { | ||
sendPostBack(clickId, orderId); | ||
let orderId = getCookie("order_id"); | ||
if (!orderId) { | ||
orderId = responseData.lead_id; | ||
cookieSet([['order_id', orderId]], 720); | ||
} | ||
const clickId = getCookie("click_id"); | ||
sendPostBack(clickId, orderId).then(() => { | ||
resolve(response); | ||
}); | ||
} | ||
@@ -128,0 +144,0 @@ resolve(response); |
{ | ||
"name": "@modulbank/sendamo", | ||
"version": "0.0.26-beta-sm-8778-integration-with-cityes-add-d0eb089e", | ||
"version": "0.0.26-beta-sm-8778-integration-with-cityes-add-f179c01e", | ||
"description": "send to amocrm method", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9012
199
1