@modulbank/sendamo
Advanced tools
Comparing version 0.0.25 to 0.0.26-beta-sm-8778-integration-with-cityes-add-119f0707
@@ -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,3 +74,4 @@ const url = amoUrl; | ||
// Идентификатор, если пришел в поисковых систем | ||
const searchEngine = (_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.referrer; | ||
const utmSource = getCookie("utm_source"); | ||
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 = { | ||
@@ -64,3 +83,3 @@ // @ts-ignore | ||
utmMedium: current.mdm, | ||
utmSource: searchEngine || current.src, | ||
utmSource: searchEngine, | ||
utmTerm: current.trm, | ||
@@ -81,2 +100,11 @@ google_id: (_c = (_b = window.digitalData) === null || _b === void 0 ? void 0 : _b.user) === null || _c === void 0 ? void 0 : _c.googleClientId, | ||
} | ||
function sendPostBack(clickId, orderId) { | ||
return new Promise((resolve, reject) => { | ||
const url = new URL('https://postback.cityads.com/service/postback/'); | ||
url.searchParams.set('campaign_secret', 'oPBnE0'); | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', `https://postback.cityads.com/service/postback/?campaign_secret=oPBnE0&order_id=${orderId}&click_id=${clickId}`, true); | ||
xhr.send(); | ||
}); | ||
} | ||
function sendAmo(params) { | ||
@@ -94,2 +122,13 @@ return new Promise((resolve, reject) => { | ||
if (response.status === 200) { | ||
const responseData = yield response.json(); | ||
const utmSource = getCookie("utm_source"); | ||
if (utmSource === "cityads") { | ||
let orderId = getCookie("order_id"); | ||
if (!orderId) { | ||
orderId = responseData.lead_id; | ||
cookieSet([['order_id', orderId]], 720); | ||
} | ||
const clickId = getCookie("click_id"); | ||
sendPostBack(clickId, orderId); | ||
} | ||
resolve(response); | ||
@@ -96,0 +135,0 @@ } |
{ | ||
"name": "@modulbank/sendamo", | ||
"version": "0.0.25", | ||
"version": "0.0.26-beta-sm-8778-integration-with-cityes-add-119f0707", | ||
"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
8635
188