@blotoutio/edgetag-sdk-browser 1.46.1 → 1.47.2
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/index.js +158 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1311,7 +1311,7 @@
|
|
|
1311
1311
|
referrer: getReferrer(destination),
|
|
1312
1312
|
search: getSearch(destination),
|
|
1313
1313
|
locale: getLocale(),
|
|
1314
|
-
sdkVersion: "1.
|
|
1314
|
+
sdkVersion: "1.47.2" ,
|
|
1315
1315
|
...(payload || {}),
|
|
1316
1316
|
};
|
|
1317
1317
|
let storage = {};
|
|
@@ -1499,8 +1499,65 @@
|
|
|
1499
1499
|
}
|
|
1500
1500
|
postRequest(getTagURL(destination, eventName, options), payload, options).catch(logger.error);
|
|
1501
1501
|
};
|
|
1502
|
-
const
|
|
1502
|
+
const getPlugins = (destination) => {
|
|
1503
|
+
var _a, _b, _c;
|
|
1504
|
+
try {
|
|
1505
|
+
const g = globalThis;
|
|
1506
|
+
return ((_c = (_b = (_a = g.edgetag) === null || _a === void 0 ? void 0 : _a.destinations) === null || _b === void 0 ? void 0 : _b[destination]) === null || _c === void 0 ? void 0 : _c.plugins) || [];
|
|
1507
|
+
}
|
|
1508
|
+
catch {
|
|
1509
|
+
return [];
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
const runPluginHook = async (plugins, hookName, baseParams) => {
|
|
1503
1513
|
var _a, _b;
|
|
1514
|
+
const payload = baseParams['payload'];
|
|
1515
|
+
let currentEventName = payload['eventName'];
|
|
1516
|
+
let currentData = payload['data'];
|
|
1517
|
+
let skip = false;
|
|
1518
|
+
for (const plugin of plugins) {
|
|
1519
|
+
const hook = plugin.rules[hookName];
|
|
1520
|
+
if (!hook)
|
|
1521
|
+
continue;
|
|
1522
|
+
try {
|
|
1523
|
+
const result = await hook({
|
|
1524
|
+
...baseParams,
|
|
1525
|
+
payload: {
|
|
1526
|
+
...payload,
|
|
1527
|
+
eventName: currentEventName,
|
|
1528
|
+
data: jsonClone(currentData),
|
|
1529
|
+
},
|
|
1530
|
+
variables: plugin.variables || {},
|
|
1531
|
+
});
|
|
1532
|
+
if (result === null || result === void 0 ? void 0 : result.skipEvent) {
|
|
1533
|
+
skip = true;
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
if ((_a = result === null || result === void 0 ? void 0 : result.payload) === null || _a === void 0 ? void 0 : _a.eventName) {
|
|
1537
|
+
currentEventName = result.payload.eventName;
|
|
1538
|
+
}
|
|
1539
|
+
if ((_b = result === null || result === void 0 ? void 0 : result.payload) === null || _b === void 0 ? void 0 : _b.data) {
|
|
1540
|
+
currentData = result.payload.data;
|
|
1541
|
+
}
|
|
1542
|
+
if (result === null || result === void 0 ? void 0 : result.additionalEvents) {
|
|
1543
|
+
for (const evt of result.additionalEvents) {
|
|
1544
|
+
handleTag(evt.eventName, evt.data, undefined, undefined);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
catch (e) {
|
|
1549
|
+
logger.error(`Plugin ${plugin.name} ${hookName} error: ${e}`);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return {
|
|
1553
|
+
eventName: currentEventName,
|
|
1554
|
+
data: currentData,
|
|
1555
|
+
skip,
|
|
1556
|
+
};
|
|
1557
|
+
};
|
|
1558
|
+
const processTag = async (destination, eventName, data = {}, providers, options) => {
|
|
1559
|
+
var _a, _b;
|
|
1560
|
+
let currentEventName = eventName;
|
|
1504
1561
|
if (!getSetting(destination, 'initialized')) {
|
|
1505
1562
|
addStub(destination, {
|
|
1506
1563
|
name: 'tag',
|
|
@@ -1510,7 +1567,7 @@
|
|
|
1510
1567
|
}
|
|
1511
1568
|
let eventId = data['eventId'];
|
|
1512
1569
|
if (!eventId) {
|
|
1513
|
-
eventId = generateEventId(
|
|
1570
|
+
eventId = generateEventId(currentEventName);
|
|
1514
1571
|
}
|
|
1515
1572
|
const providerPackages = getSetting(destination, 'browserPackages');
|
|
1516
1573
|
const configuredTags = getSetting(destination, 'channels');
|
|
@@ -1544,8 +1601,42 @@
|
|
|
1544
1601
|
// eslint-disable-next-line no-param-reassign
|
|
1545
1602
|
providers = rulesResult.updatedProviders;
|
|
1546
1603
|
}
|
|
1604
|
+
const plugins = getPlugins(destination);
|
|
1605
|
+
if (plugins.length > 0) {
|
|
1606
|
+
const pluginSettings = {
|
|
1607
|
+
userId,
|
|
1608
|
+
sessionId,
|
|
1609
|
+
geoCountry: requestCountry,
|
|
1610
|
+
geoRegion: requestRegion,
|
|
1611
|
+
isEURequest,
|
|
1612
|
+
ip,
|
|
1613
|
+
consent: consentChannel,
|
|
1614
|
+
consentCategories: consentCategory,
|
|
1615
|
+
userProperties,
|
|
1616
|
+
};
|
|
1617
|
+
const baseParams = {
|
|
1618
|
+
payload: { eventName: currentEventName, data, eventId },
|
|
1619
|
+
settings: pluginSettings,
|
|
1620
|
+
};
|
|
1621
|
+
const rootResult = await runPluginHook(plugins, 'tagRoot', baseParams);
|
|
1622
|
+
if (rootResult.skip) {
|
|
1623
|
+
sendTag(destination, {
|
|
1624
|
+
configuratorProcessed: true,
|
|
1625
|
+
eventName: currentEventName,
|
|
1626
|
+
eventId,
|
|
1627
|
+
data,
|
|
1628
|
+
providerData: {},
|
|
1629
|
+
providers,
|
|
1630
|
+
options,
|
|
1631
|
+
});
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
currentEventName = rootResult.eventName;
|
|
1635
|
+
// eslint-disable-next-line no-param-reassign
|
|
1636
|
+
data = rootResult.data;
|
|
1637
|
+
}
|
|
1547
1638
|
if (!rulesResult.skipBrowserEvent) {
|
|
1548
|
-
const
|
|
1639
|
+
const currencySettings = getSetting(destination, 'currency');
|
|
1549
1640
|
for (const pkg of providerPackages) {
|
|
1550
1641
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
1551
1642
|
continue;
|
|
@@ -1554,6 +1645,33 @@
|
|
|
1554
1645
|
logger.log(`Provider ${pkg.name} is not in allow list`);
|
|
1555
1646
|
continue;
|
|
1556
1647
|
}
|
|
1648
|
+
let providerEventName = currentEventName;
|
|
1649
|
+
let providerData = data;
|
|
1650
|
+
if (plugins.length > 0) {
|
|
1651
|
+
const channelResult = await runPluginHook(plugins, 'tagChannel', {
|
|
1652
|
+
payload: {
|
|
1653
|
+
eventName: providerEventName,
|
|
1654
|
+
data: providerData,
|
|
1655
|
+
eventId,
|
|
1656
|
+
},
|
|
1657
|
+
settings: {
|
|
1658
|
+
userId,
|
|
1659
|
+
sessionId,
|
|
1660
|
+
geoCountry: requestCountry,
|
|
1661
|
+
geoRegion: requestRegion,
|
|
1662
|
+
isEURequest,
|
|
1663
|
+
ip,
|
|
1664
|
+
consent: consentChannel,
|
|
1665
|
+
consentCategories: consentCategory,
|
|
1666
|
+
userProperties,
|
|
1667
|
+
},
|
|
1668
|
+
providerId: pkg.name,
|
|
1669
|
+
});
|
|
1670
|
+
if (channelResult.skip)
|
|
1671
|
+
continue;
|
|
1672
|
+
providerEventName = channelResult.eventName;
|
|
1673
|
+
providerData = channelResult.data;
|
|
1674
|
+
}
|
|
1557
1675
|
const variables = getProviderVariables(destination, pkg.name);
|
|
1558
1676
|
const result = {};
|
|
1559
1677
|
const executionContext = new Map();
|
|
@@ -1570,14 +1688,42 @@
|
|
|
1570
1688
|
logger.log('GEO request region does not match the filter, skipping');
|
|
1571
1689
|
continue;
|
|
1572
1690
|
}
|
|
1691
|
+
let instanceEventName = providerEventName;
|
|
1692
|
+
let instanceData = providerData;
|
|
1693
|
+
if (plugins.length > 0) {
|
|
1694
|
+
const instanceResult = await runPluginHook(plugins, 'tagInstance', {
|
|
1695
|
+
payload: {
|
|
1696
|
+
eventName: instanceEventName,
|
|
1697
|
+
data: instanceData,
|
|
1698
|
+
eventId,
|
|
1699
|
+
},
|
|
1700
|
+
settings: {
|
|
1701
|
+
userId,
|
|
1702
|
+
sessionId,
|
|
1703
|
+
geoCountry: requestCountry,
|
|
1704
|
+
geoRegion: requestRegion,
|
|
1705
|
+
isEURequest,
|
|
1706
|
+
ip,
|
|
1707
|
+
consent: consentChannel,
|
|
1708
|
+
consentCategories: consentCategory,
|
|
1709
|
+
userProperties,
|
|
1710
|
+
},
|
|
1711
|
+
providerId: pkg.name,
|
|
1712
|
+
});
|
|
1713
|
+
if (instanceResult.skip)
|
|
1714
|
+
continue;
|
|
1715
|
+
instanceEventName = instanceResult.eventName;
|
|
1716
|
+
instanceData = instanceResult.data;
|
|
1717
|
+
}
|
|
1718
|
+
const conversion = preparePayloadWithConversion(jsonClone(instanceData), currencySettings);
|
|
1573
1719
|
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
1574
1720
|
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
|
|
1575
1721
|
? conversion.payload
|
|
1576
|
-
:
|
|
1722
|
+
: instanceData;
|
|
1577
1723
|
result[variable.tagName] = pkg.tag({
|
|
1578
1724
|
userId,
|
|
1579
1725
|
sessionId,
|
|
1580
|
-
eventName,
|
|
1726
|
+
eventName: instanceEventName,
|
|
1581
1727
|
eventId,
|
|
1582
1728
|
data: jsonClone(payload),
|
|
1583
1729
|
sendTag: sendTag.bind(null, destination),
|
|
@@ -1589,6 +1735,7 @@
|
|
|
1589
1735
|
geoRegion: requestRegion,
|
|
1590
1736
|
isEURequest,
|
|
1591
1737
|
ip,
|
|
1738
|
+
pageUrl: getPageUrl(destination),
|
|
1592
1739
|
});
|
|
1593
1740
|
}
|
|
1594
1741
|
providerData[pkg.name] = result;
|
|
@@ -1602,7 +1749,7 @@
|
|
|
1602
1749
|
}
|
|
1603
1750
|
sendTag(destination, {
|
|
1604
1751
|
configuratorProcessed: true,
|
|
1605
|
-
eventName,
|
|
1752
|
+
eventName: currentEventName,
|
|
1606
1753
|
eventId,
|
|
1607
1754
|
data,
|
|
1608
1755
|
providerData,
|
|
@@ -1620,11 +1767,11 @@
|
|
|
1620
1767
|
};
|
|
1621
1768
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
1622
1769
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
1623
|
-
processTag(options.destination, eventName, data, providers, options);
|
|
1770
|
+
processTag(options.destination, eventName, data, providers, options).catch(logger.error);
|
|
1624
1771
|
return;
|
|
1625
1772
|
}
|
|
1626
1773
|
getInstances().forEach((instance) => {
|
|
1627
|
-
processTag(instance, eventName, data, providers, options);
|
|
1774
|
+
processTag(instance, eventName, data, providers, options).catch(logger.error);
|
|
1628
1775
|
});
|
|
1629
1776
|
};
|
|
1630
1777
|
const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
@@ -1789,6 +1936,7 @@
|
|
|
1789
1936
|
geoRegion: requestRegion,
|
|
1790
1937
|
isEURequest,
|
|
1791
1938
|
ip,
|
|
1939
|
+
pageUrl: getPageUrl(destination),
|
|
1792
1940
|
});
|
|
1793
1941
|
}
|
|
1794
1942
|
}
|
|
@@ -2016,6 +2164,7 @@
|
|
|
2016
2164
|
geoRegion: response.geoRegion,
|
|
2017
2165
|
isEURequest: response.isEURequest,
|
|
2018
2166
|
ip: response.ip,
|
|
2167
|
+
pageUrl: getPageUrl(destination),
|
|
2019
2168
|
});
|
|
2020
2169
|
}
|
|
2021
2170
|
}
|