@alexsab-ru/scripts 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analytics.js +24 -10
- package/lib/calltouch/calltouch-module.js +4 -9
- package/lib/form.js +8 -0
- package/package.json +1 -1
package/lib/analytics.js
CHANGED
|
@@ -15,17 +15,31 @@ export function reachGoal(eventAction, t = {}) {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
if(window.calltouch_params) {
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
// sendToCallTouch внутри проверяет eventCategory === 'Lead',
|
|
19
|
+
// поэтому вызываем только для лидов, чтобы не делать лишнюю работу.
|
|
20
|
+
if(t.eventCategory === 'Lead') {
|
|
21
|
+
// Если siteId уже задан конкретным дилером (из data-атрибута),
|
|
22
|
+
// не перезатираем его глобальным значением из calltouch_params.
|
|
23
|
+
if(!t.siteId) {
|
|
24
|
+
var rawSiteId = window.calltouch_params.site_id;
|
|
25
|
+
t.siteId = Array.isArray(rawSiteId) ? rawSiteId[0] : rawSiteId;
|
|
26
|
+
}
|
|
27
|
+
// console.log("sendToCallTouch:", t);
|
|
28
|
+
sendToCallTouch(t)
|
|
29
|
+
.then(result => {
|
|
30
|
+
console.log('Данные успешно отправлены в колтач:', eventAction, result);
|
|
31
|
+
})
|
|
32
|
+
.catch(error => {
|
|
33
|
+
console.error('Ошибка при отправке данных в колтач:', eventAction, error);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
27
36
|
if(window.ct) {
|
|
28
|
-
|
|
37
|
+
// mod_id может быть массивом (multi-project) или строкой (legacy).
|
|
38
|
+
var modIds = window.calltouch_params.mod_id;
|
|
39
|
+
var ids = Array.isArray(modIds) ? modIds : [modIds];
|
|
40
|
+
ids.forEach(function(modId) {
|
|
41
|
+
window.ct(modId, 'goal', eventAction);
|
|
42
|
+
});
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
ymGoal(eventAction, {
|
|
@@ -98,16 +98,11 @@ function processEventData(eventData, sessionId) {
|
|
|
98
98
|
function sendToCallTouch(options) {
|
|
99
99
|
return new Promise((resolve, reject) => {
|
|
100
100
|
try {
|
|
101
|
-
const { siteId,
|
|
102
|
-
|
|
103
|
-
// Проверяем, что категория события - Lead
|
|
104
|
-
if (eventCategory !== 'Lead') {
|
|
105
|
-
return resolve({ status: 'skipped', message: 'Not a Lead event' });
|
|
106
|
-
}
|
|
107
|
-
|
|
101
|
+
const { siteId, eventProperties, sessionId = window.call_value } = options;
|
|
102
|
+
|
|
108
103
|
// Проверяем обязательные параметры
|
|
109
|
-
if (!siteId) {
|
|
110
|
-
return reject(new Error('siteId is required'));
|
|
104
|
+
if (!siteId || typeof siteId !== 'string') {
|
|
105
|
+
return reject(new Error('siteId is required and must be a string'));
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
// Обрабатываем данные с помощью оптимизированной функции
|
package/lib/form.js
CHANGED
|
@@ -295,6 +295,7 @@ const submitForm = async (form) => {
|
|
|
295
295
|
// Считаем значения один раз, чтобы одинаково использовать их в try/catch и логах.
|
|
296
296
|
const dealerRouteKey = dealer && dealer.dataset ? (dealer.dataset.ctRouteKey || '').trim() : '';
|
|
297
297
|
const dealerModId = dealer && dealer.dataset ? (dealer.dataset.ctModId || '').trim() : '';
|
|
298
|
+
const dealerSiteId = dealer && dealer.dataset ? (dealer.dataset.ctSiteId || '').trim() : '';
|
|
298
299
|
const calltouchRouteKey = dealerRouteKey || props.ct_routeKey;
|
|
299
300
|
const scopedCtwName = dealerModId ? `ctw_${dealerModId}` : '';
|
|
300
301
|
const hasScopedCtw = scopedCtwName ? typeof window[scopedCtwName] !== 'undefined' : false;
|
|
@@ -310,6 +311,7 @@ const submitForm = async (form) => {
|
|
|
310
311
|
dealerValue: dealer && dealer.value ? dealer.value : '',
|
|
311
312
|
dealerRouteKey,
|
|
312
313
|
dealerModId,
|
|
314
|
+
dealerSiteId,
|
|
313
315
|
fallbackRouteKey: props.ct_routeKey,
|
|
314
316
|
calltouchRouteKey,
|
|
315
317
|
scopedCtwName,
|
|
@@ -342,6 +344,7 @@ const submitForm = async (form) => {
|
|
|
342
344
|
formId: form.id || '',
|
|
343
345
|
dealerRouteKey,
|
|
344
346
|
dealerModId,
|
|
347
|
+
dealerSiteId,
|
|
345
348
|
fallbackRouteKey: props.ct_routeKey,
|
|
346
349
|
calltouchRouteKey,
|
|
347
350
|
scopedCtwName,
|
|
@@ -349,6 +352,11 @@ const submitForm = async (form) => {
|
|
|
349
352
|
hasGlobalCtw
|
|
350
353
|
});
|
|
351
354
|
formDataObj = getFormDataObject(formData, form.id);
|
|
355
|
+
// Если известен конкретный siteId дилера, прокидываем его,
|
|
356
|
+
// чтобы reachGoal → sendToCallTouch отправил лид в нужный проект.
|
|
357
|
+
if (dealerSiteId) {
|
|
358
|
+
formDataObj.siteId = dealerSiteId;
|
|
359
|
+
}
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
const params = new URLSearchParams([...formData]);
|