@blotoutio/edgetag-sdk-js 1.46.1 → 1.47.0

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