@blotoutio/edgetag-sdk-browser 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 (2) hide show
  1. package/index.js +34 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -469,28 +469,39 @@
469
469
  };
470
470
 
471
471
  const getCookieValue = (key) => {
472
+ var _a;
472
473
  try {
473
474
  if (!document || !document.cookie) {
474
475
  return '';
475
476
  }
476
- const name = `${key}=`;
477
- const decodedCookie = decodeURIComponent(document.cookie);
478
- const ca = decodedCookie.split(';');
479
- for (let i = 0; i < ca.length; i++) {
480
- let c = ca[i];
481
- while (c.charAt(0) === ' ') {
482
- c = c.substring(1);
483
- }
484
- if (c.indexOf(name) === 0) {
485
- return c.substring(name.length, c.length);
486
- }
487
- }
488
- return '';
477
+ const cookies = parseCookies(document.cookie);
478
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
489
479
  }
490
480
  catch {
491
481
  return '';
492
482
  }
493
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
+ };
494
505
 
495
506
  const getUserId$1 = (destination) => {
496
507
  const userId = getSetting(destination, 'userId');
@@ -550,7 +561,7 @@
550
561
  referrer: getReferrer(destination),
551
562
  search: getSearch(destination),
552
563
  locale: getLocale(),
553
- sdkVersion: "0.60.1" ,
564
+ sdkVersion: "0.62.0" ,
554
565
  ...(payload || {}),
555
566
  };
556
567
  let storage = {};
@@ -604,11 +615,14 @@
604
615
  }
605
616
  return `${destination}${path}`;
606
617
  };
607
- const getTagURL = (destination, options) => {
618
+ const getTagURL = (destination, eventName, options) => {
608
619
  const parsedUrl = new URL(generateUrl(destination, '/tag'));
609
620
  if (options === null || options === void 0 ? void 0 : options.sync) {
610
621
  parsedUrl.searchParams.set('sync', 'true');
611
622
  }
623
+ if (eventName) {
624
+ parsedUrl.searchParams.set('name', eventName);
625
+ }
612
626
  return parsedUrl.toString();
613
627
  };
614
628
  const getInitURL = (destination) => {
@@ -670,7 +684,7 @@
670
684
  if (providers) {
671
685
  payload.providers = providers;
672
686
  }
673
- postRequest(getTagURL(destination, options), payload, options).catch(error);
687
+ postRequest(getTagURL(destination, eventName, options), payload, options).catch(error);
674
688
  };
675
689
  const processTag = (destination, eventName, data = {}, providers, options) => {
676
690
  if (!getSetting(destination, 'initialized')) {
@@ -717,6 +731,7 @@
717
731
  sendTag: sendTag.bind(null, destination),
718
732
  manifestVariables: variable.variableSet,
719
733
  executionContext,
734
+ destination,
720
735
  });
721
736
  }
722
737
  providerData[pkg.name] = result;
@@ -1142,6 +1157,9 @@
1142
1157
  error('Initialization failed');
1143
1158
  return;
1144
1159
  }
1160
+ if (result.isNewUser && result.consent) {
1161
+ saveConsent(preferences.edgeURL, result.consent);
1162
+ }
1145
1163
  const providers = {};
1146
1164
  (_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
1147
1165
  const provider = browserPackages[pkg.package];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.60.1",
3
+ "version": "0.62.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",