@blotoutio/edgetag-sdk-js 0.60.1 → 0.62.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 +34 -16
  2. package/index.mjs +34 -16
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -468,28 +468,39 @@ const generateEventId = (name) => {
468
468
  };
469
469
 
470
470
  const getCookieValue = (key) => {
471
+ var _a;
471
472
  try {
472
473
  if (!document || !document.cookie) {
473
474
  return '';
474
475
  }
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 '';
476
+ const cookies = parseCookies(document.cookie);
477
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
488
478
  }
489
479
  catch {
490
480
  return '';
491
481
  }
492
482
  };
483
+ const parseCookies = (cookie) => {
484
+ return Object.fromEntries(cookie
485
+ .split(/;\s+/)
486
+ .map((r) => r.split('=').map((str) => str.trim()))
487
+ .map(([cookieKey, cookieValue]) => {
488
+ if (!cookieKey) {
489
+ return [];
490
+ }
491
+ let decodedValue = '';
492
+ if (cookieValue) {
493
+ try {
494
+ decodedValue = decodeURIComponent(cookieValue);
495
+ }
496
+ catch (e) {
497
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
498
+ decodedValue = cookieValue;
499
+ }
500
+ }
501
+ return [cookieKey, decodedValue];
502
+ }));
503
+ };
493
504
 
494
505
  const getUserId$1 = (destination) => {
495
506
  const userId = getSetting(destination, 'userId');
@@ -549,7 +560,7 @@ const getStandardPayload = (destination, payload) => {
549
560
  referrer: getReferrer(destination),
550
561
  search: getSearch(destination),
551
562
  locale: getLocale(),
552
- sdkVersion: "0.60.1" ,
563
+ sdkVersion: "0.62.0" ,
553
564
  ...(payload || {}),
554
565
  };
555
566
  let storage = {};
@@ -603,11 +614,14 @@ const generateUrl = (destination, path) => {
603
614
  }
604
615
  return `${destination}${path}`;
605
616
  };
606
- const getTagURL = (destination, options) => {
617
+ const getTagURL = (destination, eventName, options) => {
607
618
  const parsedUrl = new URL(generateUrl(destination, '/tag'));
608
619
  if (options === null || options === void 0 ? void 0 : options.sync) {
609
620
  parsedUrl.searchParams.set('sync', 'true');
610
621
  }
622
+ if (eventName) {
623
+ parsedUrl.searchParams.set('name', eventName);
624
+ }
611
625
  return parsedUrl.toString();
612
626
  };
613
627
  const getInitURL = (destination) => {
@@ -669,7 +683,7 @@ const sendTag = (destination, { eventName, eventId, data, providerData, provider
669
683
  if (providers) {
670
684
  payload.providers = providers;
671
685
  }
672
- postRequest(getTagURL(destination, options), payload, options).catch(error);
686
+ postRequest(getTagURL(destination, eventName, options), payload, options).catch(error);
673
687
  };
674
688
  const processTag = (destination, eventName, data = {}, providers, options) => {
675
689
  if (!getSetting(destination, 'initialized')) {
@@ -716,6 +730,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
716
730
  sendTag: sendTag.bind(null, destination),
717
731
  manifestVariables: variable.variableSet,
718
732
  executionContext,
733
+ destination,
719
734
  });
720
735
  }
721
736
  providerData[pkg.name] = result;
@@ -1141,6 +1156,9 @@ const handleInit = (preferences) => {
1141
1156
  error('Initialization failed');
1142
1157
  return;
1143
1158
  }
1159
+ if (result.isNewUser && result.consent) {
1160
+ saveConsent(preferences.edgeURL, result.consent);
1161
+ }
1144
1162
  const providers = {};
1145
1163
  (_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
1146
1164
  const provider = browserPackages[pkg.package];
package/index.mjs CHANGED
@@ -466,28 +466,39 @@ const generateEventId = (name) => {
466
466
  };
467
467
 
468
468
  const getCookieValue = (key) => {
469
+ var _a;
469
470
  try {
470
471
  if (!document || !document.cookie) {
471
472
  return '';
472
473
  }
473
- const name = `${key}=`;
474
- const decodedCookie = decodeURIComponent(document.cookie);
475
- const ca = decodedCookie.split(';');
476
- for (let i = 0; i < ca.length; i++) {
477
- let c = ca[i];
478
- while (c.charAt(0) === ' ') {
479
- c = c.substring(1);
480
- }
481
- if (c.indexOf(name) === 0) {
482
- return c.substring(name.length, c.length);
483
- }
484
- }
485
- return '';
474
+ const cookies = parseCookies(document.cookie);
475
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
486
476
  }
487
477
  catch {
488
478
  return '';
489
479
  }
490
480
  };
481
+ const parseCookies = (cookie) => {
482
+ return Object.fromEntries(cookie
483
+ .split(/;\s+/)
484
+ .map((r) => r.split('=').map((str) => str.trim()))
485
+ .map(([cookieKey, cookieValue]) => {
486
+ if (!cookieKey) {
487
+ return [];
488
+ }
489
+ let decodedValue = '';
490
+ if (cookieValue) {
491
+ try {
492
+ decodedValue = decodeURIComponent(cookieValue);
493
+ }
494
+ catch (e) {
495
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
496
+ decodedValue = cookieValue;
497
+ }
498
+ }
499
+ return [cookieKey, decodedValue];
500
+ }));
501
+ };
491
502
 
492
503
  const getUserId$1 = (destination) => {
493
504
  const userId = getSetting(destination, 'userId');
@@ -547,7 +558,7 @@ const getStandardPayload = (destination, payload) => {
547
558
  referrer: getReferrer(destination),
548
559
  search: getSearch(destination),
549
560
  locale: getLocale(),
550
- sdkVersion: "0.60.1" ,
561
+ sdkVersion: "0.62.0" ,
551
562
  ...(payload || {}),
552
563
  };
553
564
  let storage = {};
@@ -601,11 +612,14 @@ const generateUrl = (destination, path) => {
601
612
  }
602
613
  return `${destination}${path}`;
603
614
  };
604
- const getTagURL = (destination, options) => {
615
+ const getTagURL = (destination, eventName, options) => {
605
616
  const parsedUrl = new URL(generateUrl(destination, '/tag'));
606
617
  if (options === null || options === void 0 ? void 0 : options.sync) {
607
618
  parsedUrl.searchParams.set('sync', 'true');
608
619
  }
620
+ if (eventName) {
621
+ parsedUrl.searchParams.set('name', eventName);
622
+ }
609
623
  return parsedUrl.toString();
610
624
  };
611
625
  const getInitURL = (destination) => {
@@ -667,7 +681,7 @@ const sendTag = (destination, { eventName, eventId, data, providerData, provider
667
681
  if (providers) {
668
682
  payload.providers = providers;
669
683
  }
670
- postRequest(getTagURL(destination, options), payload, options).catch(error);
684
+ postRequest(getTagURL(destination, eventName, options), payload, options).catch(error);
671
685
  };
672
686
  const processTag = (destination, eventName, data = {}, providers, options) => {
673
687
  if (!getSetting(destination, 'initialized')) {
@@ -714,6 +728,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
714
728
  sendTag: sendTag.bind(null, destination),
715
729
  manifestVariables: variable.variableSet,
716
730
  executionContext,
731
+ destination,
717
732
  });
718
733
  }
719
734
  providerData[pkg.name] = result;
@@ -1139,6 +1154,9 @@ const handleInit = (preferences) => {
1139
1154
  error('Initialization failed');
1140
1155
  return;
1141
1156
  }
1157
+ if (result.isNewUser && result.consent) {
1158
+ saveConsent(preferences.edgeURL, result.consent);
1159
+ }
1142
1160
  const providers = {};
1143
1161
  (_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
1144
1162
  const provider = browserPackages[pkg.package];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.60.1",
3
+ "version": "0.62.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",