@chordcommerce/analytics 1.18.0 → 1.18.1
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.
- package/dist/cjs/client/consent/index.js +1 -1
- package/dist/cjs/client/consent/onetrust.d.ts +2 -2
- package/dist/cjs/client/consent/onetrust.js +30 -6
- package/dist/client/consent/index.js +1 -1
- package/dist/client/consent/onetrust.d.ts +2 -2
- package/dist/client/consent/onetrust.js +30 -6
- package/package.json +1 -1
|
@@ -57,7 +57,7 @@ var addCdpConsent = function (options) {
|
|
|
57
57
|
case 'ketch':
|
|
58
58
|
return (0, ketch_js_1.ketchConsentAdapter)();
|
|
59
59
|
case 'onetrust':
|
|
60
|
-
return (0, onetrust_js_1.onetrustConsentAdapter)();
|
|
60
|
+
return (0, onetrust_js_1.onetrustConsentAdapter)(options);
|
|
61
61
|
case 'shopify':
|
|
62
62
|
return (0, shopify_js_1.shopifyConsentAdapter)();
|
|
63
63
|
case 'segment':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConsentConfiguration } from '../../types/index.js';
|
|
1
|
+
import type { ChordAnalyticsOptions, ConsentConfiguration } from '../../types/index.js';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
OneTrust?: OneTrustApi;
|
|
@@ -14,7 +14,7 @@ interface OneTrustApi {
|
|
|
14
14
|
interface OneTrustGroup {
|
|
15
15
|
CustomGroupId: string;
|
|
16
16
|
}
|
|
17
|
-
export declare const onetrustConsentAdapter: () => {
|
|
17
|
+
export declare const onetrustConsentAdapter: (options: ChordAnalyticsOptions) => {
|
|
18
18
|
getCurrentConsent: () => ConsentConfiguration;
|
|
19
19
|
handleConsentUpdates: (updateCdpConsent: (consent: ConsentConfiguration) => void) => void;
|
|
20
20
|
userCanBeTracked: () => boolean;
|
|
@@ -46,15 +46,39 @@ var getCurrentConsent = function () {
|
|
|
46
46
|
/**
|
|
47
47
|
* Handles subsequent changes to consent configuration.
|
|
48
48
|
*/
|
|
49
|
-
var handleConsentUpdates = function (updateCdpConsent) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
var handleConsentUpdates = function (updateCdpConsent, options) {
|
|
50
|
+
var maxRetries = 100;
|
|
51
|
+
var retryInterval = 50;
|
|
52
|
+
var attempts = 0;
|
|
53
|
+
var setupHandler = function () {
|
|
54
|
+
var api = getApi();
|
|
55
|
+
if (!api) {
|
|
56
|
+
attempts++;
|
|
57
|
+
if (attempts < maxRetries) {
|
|
58
|
+
if (options.debug && options.enableLogging) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log('OneTrust API not found, retrying...');
|
|
61
|
+
}
|
|
62
|
+
setTimeout(setupHandler, retryInterval);
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (options.debug && options.enableLogging) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.log('OneTrust API found, setting up consent changed handler');
|
|
69
|
+
}
|
|
70
|
+
api.OnConsentChanged(function () {
|
|
71
|
+
updateCdpConsent(getCurrentConsent());
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
setupHandler();
|
|
53
75
|
};
|
|
54
|
-
var onetrustConsentAdapter = function () {
|
|
76
|
+
var onetrustConsentAdapter = function (options) {
|
|
55
77
|
return {
|
|
56
78
|
getCurrentConsent: getCurrentConsent,
|
|
57
|
-
handleConsentUpdates:
|
|
79
|
+
handleConsentUpdates: function (updateCdpConsent) {
|
|
80
|
+
handleConsentUpdates(updateCdpConsent, options);
|
|
81
|
+
},
|
|
58
82
|
userCanBeTracked: userCanBeTracked,
|
|
59
83
|
};
|
|
60
84
|
};
|
|
@@ -27,7 +27,7 @@ export const addCdpConsent = (options) => {
|
|
|
27
27
|
case 'ketch':
|
|
28
28
|
return ketchConsentAdapter();
|
|
29
29
|
case 'onetrust':
|
|
30
|
-
return onetrustConsentAdapter();
|
|
30
|
+
return onetrustConsentAdapter(options);
|
|
31
31
|
case 'shopify':
|
|
32
32
|
return shopifyConsentAdapter();
|
|
33
33
|
case 'segment':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConsentConfiguration } from '../../types/index.js';
|
|
1
|
+
import type { ChordAnalyticsOptions, ConsentConfiguration } from '../../types/index.js';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
OneTrust?: OneTrustApi;
|
|
@@ -14,7 +14,7 @@ interface OneTrustApi {
|
|
|
14
14
|
interface OneTrustGroup {
|
|
15
15
|
CustomGroupId: string;
|
|
16
16
|
}
|
|
17
|
-
export declare const onetrustConsentAdapter: () => {
|
|
17
|
+
export declare const onetrustConsentAdapter: (options: ChordAnalyticsOptions) => {
|
|
18
18
|
getCurrentConsent: () => ConsentConfiguration;
|
|
19
19
|
handleConsentUpdates: (updateCdpConsent: (consent: ConsentConfiguration) => void) => void;
|
|
20
20
|
userCanBeTracked: () => boolean;
|
|
@@ -42,15 +42,39 @@ const getCurrentConsent = () => {
|
|
|
42
42
|
/**
|
|
43
43
|
* Handles subsequent changes to consent configuration.
|
|
44
44
|
*/
|
|
45
|
-
const handleConsentUpdates = (updateCdpConsent) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const handleConsentUpdates = (updateCdpConsent, options) => {
|
|
46
|
+
const maxRetries = 100;
|
|
47
|
+
const retryInterval = 50;
|
|
48
|
+
let attempts = 0;
|
|
49
|
+
const setupHandler = () => {
|
|
50
|
+
const api = getApi();
|
|
51
|
+
if (!api) {
|
|
52
|
+
attempts++;
|
|
53
|
+
if (attempts < maxRetries) {
|
|
54
|
+
if (options.debug && options.enableLogging) {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.log('OneTrust API not found, retrying...');
|
|
57
|
+
}
|
|
58
|
+
setTimeout(setupHandler, retryInterval);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (options.debug && options.enableLogging) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.log('OneTrust API found, setting up consent changed handler');
|
|
65
|
+
}
|
|
66
|
+
api.OnConsentChanged(() => {
|
|
67
|
+
updateCdpConsent(getCurrentConsent());
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
setupHandler();
|
|
49
71
|
};
|
|
50
|
-
export const onetrustConsentAdapter = () => {
|
|
72
|
+
export const onetrustConsentAdapter = (options) => {
|
|
51
73
|
return {
|
|
52
74
|
getCurrentConsent,
|
|
53
|
-
handleConsentUpdates
|
|
75
|
+
handleConsentUpdates: (updateCdpConsent) => {
|
|
76
|
+
handleConsentUpdates(updateCdpConsent, options);
|
|
77
|
+
},
|
|
54
78
|
userCanBeTracked,
|
|
55
79
|
};
|
|
56
80
|
};
|
package/package.json
CHANGED