@blotoutio/edgetag-sdk-browser 0.60.0 → 0.61.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 +49 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -278,6 +278,7 @@
278
278
  const consentKey = 'consent';
279
279
  const keyPrefix = `_worker`;
280
280
  const cookieKey = 'tag_user_id';
281
+ const fallbackSessionKey = 'fallback_tag_user_id';
281
282
 
282
283
  const getMessage = (error) => {
283
284
  if (error instanceof Error) {
@@ -468,28 +469,39 @@
468
469
  };
469
470
 
470
471
  const getCookieValue = (key) => {
472
+ var _a;
471
473
  try {
472
474
  if (!document || !document.cookie) {
473
475
  return '';
474
476
  }
475
- const name = `${key}=`;
476
- const decodedCookie = decodeURIComponent(document.cookie);
477
- const ca = decodedCookie.split(';');
478
- for (let i = 0; i < ca.length; i++) {
479
- let c = ca[i];
480
- while (c.charAt(0) === ' ') {
481
- c = c.substring(1);
482
- }
483
- if (c.indexOf(name) === 0) {
484
- return c.substring(name.length, c.length);
485
- }
486
- }
487
- return '';
477
+ const cookies = parseCookies(document.cookie);
478
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
488
479
  }
489
480
  catch {
490
481
  return '';
491
482
  }
492
483
  };
484
+ const parseCookies = (cookie) => {
485
+ return Object.fromEntries(cookie
486
+ .split(/;\s+/)
487
+ .map((r) => r.split('=').map((str) => str.trim()))
488
+ .map(([cookieKey, cookieValue]) => {
489
+ if (!cookieKey) {
490
+ return [];
491
+ }
492
+ let decodedValue = '';
493
+ if (cookieValue) {
494
+ try {
495
+ decodedValue = decodeURIComponent(cookieValue);
496
+ }
497
+ catch (e) {
498
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
499
+ decodedValue = cookieValue;
500
+ }
501
+ }
502
+ return [cookieKey, decodedValue];
503
+ }));
504
+ };
493
505
 
494
506
  const getUserId$1 = (destination) => {
495
507
  const userId = getSetting(destination, 'userId');
@@ -549,7 +561,7 @@
549
561
  referrer: getReferrer(destination),
550
562
  search: getSearch(destination),
551
563
  locale: getLocale(),
552
- sdkVersion: "0.60.0" ,
564
+ sdkVersion: "0.61.0" ,
553
565
  ...(payload || {}),
554
566
  };
555
567
  let storage = {};
@@ -1097,6 +1109,26 @@
1097
1109
  if (!browserPackages) {
1098
1110
  return;
1099
1111
  }
1112
+ let fallbackId;
1113
+ try {
1114
+ fallbackId = preferences.fallbackUserId;
1115
+ if (!fallbackId) {
1116
+ const fallbackSessionValue = sessionStorage.getItem(fallbackSessionKey);
1117
+ if (!fallbackSessionValue) {
1118
+ const randomId = crypto.randomUUID();
1119
+ if (randomId) {
1120
+ fallbackId = `${randomId}-${Date.now()}`;
1121
+ sessionStorage.setItem(fallbackSessionKey, fallbackId);
1122
+ }
1123
+ }
1124
+ else {
1125
+ fallbackId = fallbackSessionValue;
1126
+ }
1127
+ }
1128
+ }
1129
+ catch {
1130
+ // do nothing
1131
+ }
1100
1132
  if (preferences.afterManifestEvents) {
1101
1133
  setSetting(preferences.edgeURL, {
1102
1134
  stubs: preferences.afterManifestEvents,
@@ -1111,6 +1143,9 @@
1111
1143
  setSetting(preferences.edgeURL, { userId: preferences.userId });
1112
1144
  url.searchParams.set('userId', preferences.userId);
1113
1145
  }
1146
+ if (fallbackId) {
1147
+ url.searchParams.set('fallbackUserId', fallbackId);
1148
+ }
1114
1149
  getRequest(url.href)
1115
1150
  .then((result) => {
1116
1151
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.60.0",
3
+ "version": "0.61.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",