@blotoutio/edgetag-sdk-browser 1.36.1 → 1.37.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 (2) hide show
  1. package/index.js +35 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -132,6 +132,18 @@
132
132
  ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
133
133
  ]);
134
134
 
135
+ function tryParse(json, fallbackValue) {
136
+ try {
137
+ if (json) {
138
+ return JSON.parse(json);
139
+ }
140
+ }
141
+ catch {
142
+ /* do nothing */
143
+ }
144
+ return fallbackValue;
145
+ }
146
+
135
147
  const isZeroPurchaseEvent = (payload) => {
136
148
  var _a;
137
149
  if (payload.eventName != 'Purchase') {
@@ -814,7 +826,7 @@
814
826
  * this function when cloning user-provided objects since structuredClone
815
827
  * will throw an error if given an object with functions.
816
828
  */
817
- const jsonClone = (json) => JSON.parse(JSON.stringify(json));
829
+ const jsonClone = (json) => tryParse(JSON.stringify(json), undefined);
818
830
 
819
831
  // eslint-disable-next-line @nx/enforce-module-boundaries
820
832
  const getGlobalSettings = () => {
@@ -981,6 +993,25 @@
981
993
  consentSetting: manifestResult.consentSetting,
982
994
  session: manifestResult.session,
983
995
  });
996
+ const updateUserProperties = (destination, data) => {
997
+ const configuratorSetting = getSetting(destination, 'configuratorSetting');
998
+ if (configuratorSetting === null || configuratorSetting === void 0 ? void 0 : configuratorSetting.length) {
999
+ const latestUserProperties = {};
1000
+ if (data['email']) {
1001
+ latestUserProperties['hasEmail'] = true;
1002
+ }
1003
+ if (data['phone']) {
1004
+ latestUserProperties['hasPhone'] = true;
1005
+ }
1006
+ if (typeof data['isNewCustomer'] === 'string') {
1007
+ latestUserProperties['isNewCustomer'] = data['isNewCustomer'] === 'true';
1008
+ }
1009
+ const userProperties = getSetting(destination, 'userProperties');
1010
+ setSetting(destination, {
1011
+ userProperties: { ...userProperties, ...latestUserProperties },
1012
+ });
1013
+ }
1014
+ };
984
1015
 
985
1016
  const tagStorage = 'edgeTag';
986
1017
  const consentKey = 'consent';
@@ -1272,7 +1303,7 @@
1272
1303
  referrer: getReferrer(destination),
1273
1304
  search: getSearch(destination),
1274
1305
  locale: getLocale(),
1275
- sdkVersion: "1.36.1" ,
1306
+ sdkVersion: "1.37.0" ,
1276
1307
  ...(payload || {}),
1277
1308
  };
1278
1309
  let storage = {};
@@ -1597,6 +1628,7 @@
1597
1628
 
1598
1629
  const processData = (destination, data, providers, options) => {
1599
1630
  saveKV(destination, data);
1631
+ updateUserProperties(destination, data);
1600
1632
  const providerPackages = getSetting(destination, 'browserPackages');
1601
1633
  const configuredTags = getSetting(destination, 'channels');
1602
1634
  const userId = getUserId$1(destination);
@@ -2127,6 +2159,7 @@
2127
2159
  saveKV(destination, {
2128
2160
  [key]: value,
2129
2161
  });
2162
+ updateUserProperties(destination, { [key]: value });
2130
2163
  const providerPackages = getSetting(destination, 'browserPackages');
2131
2164
  const configuredTags = getSetting(destination, 'channels');
2132
2165
  const userId = getUserId$1(destination);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "1.36.1",
3
+ "version": "1.37.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",