@blotoutio/edgetag-sdk-browser 0.36.1 → 0.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 +36 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -27,7 +27,8 @@
27
27
  let referrer = '';
28
28
  try {
29
29
  const referrerUrl = new URL(document.referrer);
30
- if (referrerUrl.host !== window.location.host) {
30
+ const pageUrl = new URL(getPageUrl());
31
+ if (referrerUrl.host !== pageUrl.host) {
31
32
  referrer = referrerUrl.href;
32
33
  }
33
34
  return referrer;
@@ -49,7 +50,7 @@
49
50
  };
50
51
  const getSearch = () => {
51
52
  try {
52
- return window.location.search;
53
+ return new URL(getPageUrl()).search;
53
54
  }
54
55
  catch {
55
56
  return '';
@@ -71,6 +72,33 @@
71
72
  return '';
72
73
  }
73
74
  };
75
+ const areEqual = (a, b) => {
76
+ if (typeof a !== typeof b ||
77
+ Array.isArray(a) !== Array.isArray(b) ||
78
+ isNaN(a) !== isNaN(b)) {
79
+ return false;
80
+ }
81
+ if (typeof a !== 'object' || a === null) {
82
+ return a === b;
83
+ }
84
+ const as = Object.keys(a);
85
+ const bs = Object.keys(b);
86
+ if (as.length !== bs.length)
87
+ return false;
88
+ for (const key of as) {
89
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
90
+ // @ts-ignore
91
+ if (!(key in b)) {
92
+ return false;
93
+ }
94
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
95
+ // @ts-ignore
96
+ if (!areEqual(a[key], b[key])) {
97
+ return false;
98
+ }
99
+ }
100
+ return true;
101
+ };
74
102
 
75
103
  const tagStorage = 'edgeTag';
76
104
  const consentKey = 'consent';
@@ -336,7 +364,7 @@
336
364
  referrer: getReferrer(),
337
365
  search: getSearch(),
338
366
  locale: getLocale(),
339
- sdkVersion: "0.36.1" ,
367
+ sdkVersion: "0.37.0" ,
340
368
  ...(payload || {}),
341
369
  };
342
370
  let storage = {};
@@ -724,6 +752,10 @@
724
752
  savePerKey('local', tagStorage, consent, consentKey);
725
753
  };
726
754
  const handleConsent = (consent, options) => {
755
+ const existingConsent = getConsent$1();
756
+ if (areEqual(existingConsent, consent)) {
757
+ return;
758
+ }
727
759
  const payload = {
728
760
  consentString: consent,
729
761
  };
@@ -808,7 +840,7 @@
808
840
  catch {
809
841
  return;
810
842
  }
811
- const params = new URLSearchParams(window.location.search);
843
+ const params = new URLSearchParams(getSearch());
812
844
  if (!params || !params.get(key)) {
813
845
  return;
814
846
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",