@azzas/azzas-tracker-web 2.0.2-preview.4 → 2.0.2-preview.6
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/dist/mod.cjs +168 -22
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +3 -2
- package/dist/mod.d.ts +3 -2
- package/dist/mod.global.js +168 -22
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +168 -22
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +162 -9
- package/package.json +1 -1
package/dist/mod.vtex.global.js
CHANGED
|
@@ -1102,6 +1102,43 @@ var AzzasTracker = function() {
|
|
|
1102
1102
|
return null;
|
|
1103
1103
|
}
|
|
1104
1104
|
};
|
|
1105
|
+
var setCookie = function setCookie(name, value) {
|
|
1106
|
+
var days = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 7, domain = arguments.length > 3 ? arguments[3] : void 0;
|
|
1107
|
+
if (typeof document === "undefined") return;
|
|
1108
|
+
var encodedValue = encodeURIComponent(value);
|
|
1109
|
+
var expires = "";
|
|
1110
|
+
if (days) {
|
|
1111
|
+
var date = /* @__PURE__ */ new Date();
|
|
1112
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
1113
|
+
expires = "; expires=" + date.toUTCString();
|
|
1114
|
+
}
|
|
1115
|
+
var domainAttr = domain ? "; domain=.".concat(domain.replace(/^\./, "")) : "";
|
|
1116
|
+
document.cookie = "".concat(name, "=").concat(encodedValue).concat(expires).concat(domainAttr, "; path=/;");
|
|
1117
|
+
};
|
|
1118
|
+
var getCookie = function getCookie(name) {
|
|
1119
|
+
if (typeof document === "undefined") return null;
|
|
1120
|
+
var match = document.cookie.split("; ").find(function(row) {
|
|
1121
|
+
return row.startsWith("".concat(name, "="));
|
|
1122
|
+
});
|
|
1123
|
+
return match ? decodeURIComponent(match.slice(name.length + 1)) : null;
|
|
1124
|
+
};
|
|
1125
|
+
var cleanPath = function cleanPath(path) {
|
|
1126
|
+
try {
|
|
1127
|
+
return decodeURIComponent(path).toLowerCase().replace(/\/+$/, "");
|
|
1128
|
+
} catch (unused) {
|
|
1129
|
+
return path.toLowerCase().replace(/\/+$/, "");
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
var matchesPromotion = function matchesPromotion(listName, promotion) {
|
|
1133
|
+
if (!listName || !promotion.promotion_url) return false;
|
|
1134
|
+
var promotionPath;
|
|
1135
|
+
try {
|
|
1136
|
+
promotionPath = new URL(promotion.promotion_url).pathname;
|
|
1137
|
+
} catch (unused) {
|
|
1138
|
+
promotionPath = promotion.promotion_url;
|
|
1139
|
+
}
|
|
1140
|
+
return cleanPath(promotionPath) === cleanPath(listName);
|
|
1141
|
+
};
|
|
1105
1142
|
var paymentTypeFromOrderForm = // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
|
|
1106
1143
|
function paymentTypeFromOrderForm(context) {
|
|
1107
1144
|
var _context_orderForm_paymentData, _context_orderForm_paymentData1, _system_name;
|
|
@@ -1350,9 +1387,95 @@ var AzzasTracker = function() {
|
|
|
1350
1387
|
});
|
|
1351
1388
|
return (selectedSla === null || selectedSla === void 0 ? void 0 : (_selectedSla_pickupStoreInfo = selectedSla.pickupStoreInfo) === null || _selectedSla_pickupStoreInfo === void 0 ? void 0 : _selectedSla_pickupStoreInfo.friendlyName) ? "retirada em loja: ".concat(selectedSla.pickupStoreInfo.friendlyName) : (selectedSla === null || selectedSla === void 0 ? void 0 : selectedSla.name) ? "Receba em casa: ".concat(selectedSla.name) : null;
|
|
1352
1389
|
};
|
|
1390
|
+
var resolveRootDomain = function resolveRootDomain() {
|
|
1391
|
+
if (cachedRootDomain !== void 0) return cachedRootDomain;
|
|
1392
|
+
if (typeof document === "undefined") return null;
|
|
1393
|
+
var hostname = window.location.hostname;
|
|
1394
|
+
var isLocalhost = hostname === "localhost";
|
|
1395
|
+
var isIpAddress = /^[\d.]+$/.test(hostname);
|
|
1396
|
+
if (!hostname || isLocalhost || isIpAddress) {
|
|
1397
|
+
cachedRootDomain = null;
|
|
1398
|
+
return null;
|
|
1399
|
+
}
|
|
1400
|
+
var parts = hostname.split(".");
|
|
1401
|
+
var PROBE = "__azzas_trk_probe";
|
|
1402
|
+
for(var i = parts.length - 2; i >= 0; i--){
|
|
1403
|
+
var candidate = parts.slice(i).join(".");
|
|
1404
|
+
document.cookie = "".concat(PROBE, "=1; domain=.").concat(candidate, "; path=/;");
|
|
1405
|
+
if (document.cookie.includes("".concat(PROBE, "="))) {
|
|
1406
|
+
document.cookie = "".concat(PROBE, "=; domain=.").concat(candidate, "; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
|
|
1407
|
+
cachedRootDomain = candidate;
|
|
1408
|
+
return candidate;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
cachedRootDomain = null;
|
|
1412
|
+
return null;
|
|
1413
|
+
};
|
|
1414
|
+
var writePromotion = function writePromotion(promotion) {
|
|
1415
|
+
var remainingDays = (promotion.saved_at + PROMO_TTL_MS - Date.now()) / (24 * 60 * 60 * 1e3);
|
|
1416
|
+
if (remainingDays <= 0) return;
|
|
1417
|
+
setCookie(PROMO_COOKIE, JSON.stringify(promotion), remainingDays, resolveRootDomain());
|
|
1418
|
+
};
|
|
1419
|
+
var savePromotion = function savePromotion(input) {
|
|
1420
|
+
writePromotion(_object_spread_props(_object_spread({}, input), {
|
|
1421
|
+
related_keys: [],
|
|
1422
|
+
saved_at: Date.now()
|
|
1423
|
+
}));
|
|
1424
|
+
};
|
|
1425
|
+
var getPromotion = function getPromotion() {
|
|
1426
|
+
var raw = getCookie(PROMO_COOKIE);
|
|
1427
|
+
if (!raw) return null;
|
|
1428
|
+
try {
|
|
1429
|
+
var promotion = JSON.parse(raw);
|
|
1430
|
+
var isExpired = !promotion.saved_at || Date.now() - promotion.saved_at > PROMO_TTL_MS;
|
|
1431
|
+
if (isExpired) {
|
|
1432
|
+
clearPromotion();
|
|
1433
|
+
return null;
|
|
1434
|
+
}
|
|
1435
|
+
return promotion;
|
|
1436
|
+
} catch (unused) {
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
var clearPromotion = function clearPromotion() {
|
|
1441
|
+
setCookie(PROMO_COOKIE, "", -1, resolveRootDomain());
|
|
1442
|
+
};
|
|
1443
|
+
var itemsWithPromotion = function itemsWithPromotion(items) {
|
|
1444
|
+
var promotion = getPromotion();
|
|
1445
|
+
if (!promotion) return items;
|
|
1446
|
+
var relatedKeys = new Set(promotion.related_keys);
|
|
1447
|
+
var newKeys = [];
|
|
1448
|
+
var enrichedItems = items.map(function(item) {
|
|
1449
|
+
var itemKeys = [
|
|
1450
|
+
item.item_id
|
|
1451
|
+
].filter(function(key) {
|
|
1452
|
+
return Boolean(key);
|
|
1453
|
+
});
|
|
1454
|
+
var alreadyRelated = itemKeys.some(function(key) {
|
|
1455
|
+
return relatedKeys.has(key);
|
|
1456
|
+
});
|
|
1457
|
+
var isRelated = alreadyRelated || matchesPromotion(item.item_list_name, promotion);
|
|
1458
|
+
if (!isRelated) return item;
|
|
1459
|
+
if (!alreadyRelated) {
|
|
1460
|
+
var _newKeys;
|
|
1461
|
+
(_newKeys = newKeys).push.apply(_newKeys, _to_consumable_array(itemKeys));
|
|
1462
|
+
}
|
|
1463
|
+
return _object_spread_props(_object_spread({}, item), {
|
|
1464
|
+
promotion_name: promotion.promotion_name,
|
|
1465
|
+
creative_name: promotion.creative_name,
|
|
1466
|
+
creative_slot: promotion.creative_slot
|
|
1467
|
+
});
|
|
1468
|
+
});
|
|
1469
|
+
if (newKeys.length) {
|
|
1470
|
+
writePromotion(_object_spread_props(_object_spread({}, promotion), {
|
|
1471
|
+
related_keys: _to_consumable_array(promotion.related_keys).concat(_to_consumable_array(newKeys)).slice(0, MAX_RELATED_KEYS)
|
|
1472
|
+
}));
|
|
1473
|
+
}
|
|
1474
|
+
return enrichedItems;
|
|
1475
|
+
};
|
|
1353
1476
|
var getParameters = function getParameters(context, eventName, config2) {
|
|
1354
1477
|
return _async_to_generator(function() {
|
|
1355
|
-
var _adapters_currentAdapter, eventConfig, currentAdapter, getters, entries;
|
|
1478
|
+
var _adapters_currentAdapter, eventConfig, currentAdapter, getters, entries, parameters;
|
|
1356
1479
|
return _ts_generator(this, function(_state) {
|
|
1357
1480
|
switch(_state.label){
|
|
1358
1481
|
case 0:
|
|
@@ -1402,9 +1525,13 @@ var AzzasTracker = function() {
|
|
|
1402
1525
|
];
|
|
1403
1526
|
case 1:
|
|
1404
1527
|
entries = _state.sent();
|
|
1528
|
+
parameters = Object.fromEntries(entries);
|
|
1529
|
+
if (Array.isArray(parameters.items) && parameters.items.length) {
|
|
1530
|
+
parameters.items = itemsWithPromotion(parameters.items);
|
|
1531
|
+
}
|
|
1405
1532
|
return [
|
|
1406
1533
|
2,
|
|
1407
|
-
|
|
1534
|
+
parameters
|
|
1408
1535
|
];
|
|
1409
1536
|
}
|
|
1410
1537
|
});
|
|
@@ -1415,7 +1542,7 @@ var AzzasTracker = function() {
|
|
|
1415
1542
|
};
|
|
1416
1543
|
var trackWebEvent = function trackWebEvent(event, context) {
|
|
1417
1544
|
return _async_to_generator(function() {
|
|
1418
|
-
var parameters, err;
|
|
1545
|
+
var parameters, _parameters_promotion_name, _parameters_creative_name, _parameters_creative_slot, _parameters_promotion_url, result, err;
|
|
1419
1546
|
return _ts_generator(this, function(_state) {
|
|
1420
1547
|
switch(_state.label){
|
|
1421
1548
|
case 0:
|
|
@@ -1431,8 +1558,17 @@ var AzzasTracker = function() {
|
|
|
1431
1558
|
];
|
|
1432
1559
|
case 1:
|
|
1433
1560
|
parameters = _state.sent();
|
|
1561
|
+
if (event === "SELECT_PROMOTION" && parameters) {
|
|
1562
|
+
;
|
|
1563
|
+
savePromotion({
|
|
1564
|
+
promotion_name: (_parameters_promotion_name = parameters.promotion_name) !== null && _parameters_promotion_name !== void 0 ? _parameters_promotion_name : null,
|
|
1565
|
+
creative_name: (_parameters_creative_name = parameters.creative_name) !== null && _parameters_creative_name !== void 0 ? _parameters_creative_name : null,
|
|
1566
|
+
creative_slot: (_parameters_creative_slot = parameters.creative_slot) !== null && _parameters_creative_slot !== void 0 ? _parameters_creative_slot : null,
|
|
1567
|
+
promotion_url: (_parameters_promotion_url = parameters.promotion_url) !== null && _parameters_promotion_url !== void 0 ? _parameters_promotion_url : null
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1434
1570
|
if (isDebugMode()) {
|
|
1435
|
-
console.log("[DT v2] ".concat(event, ",
|
|
1571
|
+
console.log("%c [DT v2] %c ".concat(event, " "), "background: #6366f1; color: #fff; font-weight: bold; padding: 2px 6px; border-radius: 4px 0 0 4px;", "background: #1e1e2e; color: #a5b4fc; font-weight: bold; padding: 2px 6px; border-radius: 0 4px 4px 0;", {
|
|
1436
1572
|
context: context,
|
|
1437
1573
|
parameters: parameters
|
|
1438
1574
|
});
|
|
@@ -1444,9 +1580,13 @@ var AzzasTracker = function() {
|
|
|
1444
1580
|
}))
|
|
1445
1581
|
];
|
|
1446
1582
|
case 2:
|
|
1583
|
+
result = _state.sent();
|
|
1584
|
+
if (event === "PURCHASE" || event === "CUSTOM_PURCHASE") {
|
|
1585
|
+
clearPromotion();
|
|
1586
|
+
}
|
|
1447
1587
|
return [
|
|
1448
1588
|
2,
|
|
1449
|
-
|
|
1589
|
+
result
|
|
1450
1590
|
];
|
|
1451
1591
|
case 3:
|
|
1452
1592
|
err = _state.sent();
|
|
@@ -1685,6 +1825,7 @@ var AzzasTracker = function() {
|
|
|
1685
1825
|
"region",
|
|
1686
1826
|
"currency",
|
|
1687
1827
|
"promotion_name",
|
|
1828
|
+
"promotion_url",
|
|
1688
1829
|
"creative_slot",
|
|
1689
1830
|
"creative_name"
|
|
1690
1831
|
]
|
|
@@ -2182,6 +2323,10 @@ var AzzasTracker = function() {
|
|
|
2182
2323
|
"lojafabula": {
|
|
2183
2324
|
"store": "https://lojafabula.myvtex.com",
|
|
2184
2325
|
"checkout": "https://secure.lojafabula.com.br"
|
|
2326
|
+
},
|
|
2327
|
+
"lojausereserva": {
|
|
2328
|
+
"store": "https://lojausereserva.myvtex.com",
|
|
2329
|
+
"checkout": "https://lojausereserva.myvtex.com"
|
|
2185
2330
|
}
|
|
2186
2331
|
};
|
|
2187
2332
|
// src/params/legacy/index.ts
|
|
@@ -2479,6 +2624,9 @@ var AzzasTracker = function() {
|
|
|
2479
2624
|
promotion_name: function(context) {
|
|
2480
2625
|
return context.meta.promotion_name || null;
|
|
2481
2626
|
},
|
|
2627
|
+
promotion_url: function(context) {
|
|
2628
|
+
return context.meta.promotion_url || null;
|
|
2629
|
+
},
|
|
2482
2630
|
creative_name: function(context) {
|
|
2483
2631
|
return context.meta.creative_name || null;
|
|
2484
2632
|
},
|
|
@@ -2651,7 +2799,7 @@ var AzzasTracker = function() {
|
|
|
2651
2799
|
var getItemCategory23 = function(item) {
|
|
2652
2800
|
var _ref, _validHierarchy_;
|
|
2653
2801
|
var _item_similarItems_, _item_similarItems;
|
|
2654
|
-
var AVOID_CATEGORIES = /^(outlet|bazar|sale|coleção)$/i;
|
|
2802
|
+
var AVOID_CATEGORIES = /^(outlet|bazar|sale|coleção|promoção)$/i;
|
|
2655
2803
|
var categories = (_ref = item === null || item === void 0 ? void 0 : (_item_similarItems = item.similarItems) === null || _item_similarItems === void 0 ? void 0 : (_item_similarItems_ = _item_similarItems[0]) === null || _item_similarItems_ === void 0 ? void 0 : _item_similarItems_.categories) !== null && _ref !== void 0 ? _ref : [];
|
|
2656
2804
|
var validHierarchy = categories.filter(function(c) {
|
|
2657
2805
|
return c && !AVOID_CATEGORIES.test(c);
|
|
@@ -3052,7 +3200,7 @@ var AzzasTracker = function() {
|
|
|
3052
3200
|
};
|
|
3053
3201
|
var getItemCategory25 = function(item) {
|
|
3054
3202
|
var _ref, _validHierarchy_;
|
|
3055
|
-
var AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
3203
|
+
var AVOID_CATEGORIES = /outlet|bazar|sale|coleção|promoção/i;
|
|
3056
3204
|
var categories = Object.values((_ref = item === null || item === void 0 ? void 0 : item.productCategories) !== null && _ref !== void 0 ? _ref : {});
|
|
3057
3205
|
var validHierarchy = categories.map(function(c) {
|
|
3058
3206
|
return c.trim();
|
|
@@ -3095,13 +3243,13 @@ var AzzasTracker = function() {
|
|
|
3095
3243
|
if ((context === null || context === void 0 ? void 0 : context.orderForm) && (context === null || context === void 0 ? void 0 : context.orderForm.items)) {
|
|
3096
3244
|
return getOrderFormItems(context.orderForm).map(function(item, index) {
|
|
3097
3245
|
var _ref, _ref1, _ref2, _ref3, _getItemCategory7, _getItemCategory25, _ref4, _ref5, _item_detailUrl, _resizeVtexImage2, _ref6, _ref7;
|
|
3098
|
-
var _item_skuName_split__split_pop, _item_skuName_split_, _item_skuName, _item_skuName_split_1, _item_skuName1, _context_orderForm, _item_additionalInfo, _context_orderForm1;
|
|
3246
|
+
var _item_skuName_split__split_pop, _item_skuName_split_, _item_skuName, _item_skuName_split_1, _item_skuName1, _context_orderForm, _item_additionalInfo_brandName, _item_additionalInfo, _context_orderForm1;
|
|
3099
3247
|
var color = context.brand === "carolbassi" ? null : item === null || item === void 0 ? void 0 : (_item_skuName = item.skuName) === null || _item_skuName === void 0 ? void 0 : (_item_skuName_split_ = _item_skuName.split(" - ")[0]) === null || _item_skuName_split_ === void 0 ? void 0 : (_item_skuName_split__split_pop = _item_skuName_split_.split("_").pop()) === null || _item_skuName_split__split_pop === void 0 ? void 0 : _item_skuName_split__split_pop.trim();
|
|
3100
3248
|
var size = context.brand === "carolbassi" ? item === null || item === void 0 ? void 0 : item.skuName : item === null || item === void 0 ? void 0 : (_item_skuName1 = item.skuName) === null || _item_skuName1 === void 0 ? void 0 : (_item_skuName_split_1 = _item_skuName1.split(" - ")[1]) === null || _item_skuName_split_1 === void 0 ? void 0 : _item_skuName_split_1.trim();
|
|
3101
3249
|
return {
|
|
3102
3250
|
quantity: (_ref = item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref !== void 0 ? _ref : 1,
|
|
3103
3251
|
index: (_ref1 = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.index) !== null && _ref1 !== void 0 ? _ref1 : index + 1,
|
|
3104
|
-
item_brand: (_ref2 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
3252
|
+
item_brand: (_ref2 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : (_item_additionalInfo_brandName = _item_additionalInfo.brandName) === null || _item_additionalInfo_brandName === void 0 ? void 0 : _item_additionalInfo_brandName.toLowerCase()) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
3105
3253
|
item_name: (_ref3 = item === null || item === void 0 ? void 0 : item.name.replace(item === null || item === void 0 ? void 0 : item.skuName, "").trim()) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
3106
3254
|
price: (item === null || item === void 0 ? void 0 : item.sellingPrice) / 100,
|
|
3107
3255
|
discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
|
|
@@ -3295,6 +3443,11 @@ var AzzasTracker = function() {
|
|
|
3295
3443
|
return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
3296
3444
|
}
|
|
3297
3445
|
});
|
|
3446
|
+
// src/core/promotion.ts
|
|
3447
|
+
var PROMO_COOKIE = "__azzas_trk_promo";
|
|
3448
|
+
var PROMO_TTL_MS = 10 * 60 * 1e3;
|
|
3449
|
+
var MAX_RELATED_KEYS = 30;
|
|
3450
|
+
var cachedRootDomain;
|
|
3298
3451
|
// src/formatter.ts
|
|
3299
3452
|
var adapters = {
|
|
3300
3453
|
DECO: decoAdapter,
|