@chordcommerce/analytics 1.24.3 → 1.24.5
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/README.md +1 -1
- package/dist/cjs/client/cdp.js +2 -2
- package/dist/cjs/client/consent/index.js +2 -2
- package/dist/cjs/client/consent/onetrust-api.d.ts +1 -1
- package/dist/cjs/client/consent/onetrust.d.ts +2 -2
- package/dist/cjs/client/consent/segment.js +19 -6
- package/dist/cjs/client/consent/shopify.d.ts +5 -1
- package/dist/cjs/client/consent/shopify.js +70 -21
- package/dist/cjs/client/index.js +16 -8
- package/dist/cjs/client/utils.js +1 -2
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validators/custom.d.ts +4 -38
- package/dist/cjs/validators/custom.js +5 -5
- package/dist/cjs/validators/objects.d.ts +73 -584
- package/dist/cjs/validators/objects.js +110 -111
- package/dist/cjs/validators/tracking-plan-map.d.ts +172 -5126
- package/dist/cjs/validators/tracking-plan.d.ts +272 -7008
- package/dist/cjs/validators/tracking-plan.js +1722 -1649
- package/dist/client/consent/onetrust-api.d.ts +1 -1
- package/dist/client/consent/onetrust.d.ts +2 -2
- package/dist/client/consent/segment.js +1 -1
- package/dist/client/consent/shopify.d.ts +5 -1
- package/dist/client/consent/shopify.js +70 -21
- package/dist/client/index.js +84 -84
- package/dist/tsconfig-build-cjs.tsbuildinfo +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/validators/custom.d.ts +4 -38
- package/dist/validators/custom.js +1 -1
- package/dist/validators/objects.d.ts +73 -584
- package/dist/validators/objects.js +27 -28
- package/dist/validators/tracking-plan-map.d.ts +172 -5126
- package/dist/validators/tracking-plan.d.ts +272 -7008
- package/dist/validators/tracking-plan.js +219 -146
- package/package.json +4 -4
|
@@ -109,5 +109,5 @@ export declare const getNormalizedCategories: () => Record<string, boolean>;
|
|
|
109
109
|
* @param model - OneTrust consent model name
|
|
110
110
|
* @returns 'opt-in' or 'opt-out'
|
|
111
111
|
*/
|
|
112
|
-
export declare const coerceConsentModel: (model: OtConsentModel | string) =>
|
|
112
|
+
export declare const coerceConsentModel: (model: OtConsentModel | string) => "opt-in" | "opt-out";
|
|
113
113
|
export {};
|
|
@@ -5,6 +5,6 @@ export declare const onetrustConsentAdapter: (options: ChordAnalyticsOptions) =>
|
|
|
5
5
|
userCanBeTracked: () => boolean;
|
|
6
6
|
getCategories: () => Record<string, boolean>;
|
|
7
7
|
isConsentReady: () => boolean;
|
|
8
|
-
getConsentModel: () =>
|
|
9
|
-
getApi: () => import("./onetrust-api.js").OneTrustGlobal;
|
|
8
|
+
getConsentModel: () => "opt-in" | "opt-out";
|
|
9
|
+
getApi: () => import("./onetrust-api.js").OneTrustGlobal | undefined;
|
|
10
10
|
};
|
|
@@ -11,7 +11,7 @@ const getApi = () => window.segmentConsent;
|
|
|
11
11
|
/**
|
|
12
12
|
* Waits for the Segment consent API to be populated with retry logic.
|
|
13
13
|
*/
|
|
14
|
-
const waitForApi = (
|
|
14
|
+
const waitForApi = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (maxRetries = 10, baseDelay = 100) {
|
|
15
15
|
let attempt = 0;
|
|
16
16
|
const checkAndWait = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
const api = getApi();
|
|
@@ -2,7 +2,11 @@ import type { ConsentConfiguration } from '../../types/index.js';
|
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
Shopify?: {
|
|
5
|
-
customerPrivacy?: ShopifyCustomerPrivacyApi
|
|
5
|
+
customerPrivacy?: Partial<ShopifyCustomerPrivacyApi>;
|
|
6
|
+
loadFeatures?: (features: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
}[], callback?: (error?: unknown) => void) => void;
|
|
6
10
|
};
|
|
7
11
|
}
|
|
8
12
|
}
|
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns Shopify's Customer Privacy API.
|
|
2
|
+
* Returns Shopify's Customer Privacy API, or undefined until its methods load.
|
|
3
|
+
*
|
|
4
|
+
* Shopify puts a placeholder `customerPrivacy` object on every storefront that
|
|
5
|
+
* holds only cached values. The methods appear once a script requests the
|
|
6
|
+
* `consent-tracking-api` feature, so the placeholder alone is not usable.
|
|
7
|
+
*/
|
|
8
|
+
const getApi = () => {
|
|
9
|
+
var _a;
|
|
10
|
+
const api = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy;
|
|
11
|
+
if (typeof (api === null || api === void 0 ? void 0 : api.analyticsProcessingAllowed) !== 'function' ||
|
|
12
|
+
typeof api.marketingAllowed !== 'function' ||
|
|
13
|
+
typeof api.preferencesProcessingAllowed !== 'function' ||
|
|
14
|
+
typeof api.saleOfDataAllowed !== 'function') {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return api;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Requests the Customer Privacy API from Shopify when no other script has.
|
|
21
|
+
* CMPs such as CookieYes load it themselves; Shopify's own banner does not
|
|
22
|
+
* expose it, which left every event waiting on a consent check that threw.
|
|
3
23
|
*/
|
|
4
|
-
const
|
|
24
|
+
const loadApi = () => {
|
|
25
|
+
var _a;
|
|
26
|
+
if (getApi() || typeof ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.loadFeatures) !== 'function')
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], (error) => {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
if (error)
|
|
32
|
+
console.error('Could not load Shopify consent API', error);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.error('Could not load Shopify consent API', error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
5
40
|
/**
|
|
6
41
|
* Returns whether the user can currently be tracked.
|
|
7
42
|
*
|
|
@@ -17,21 +52,28 @@ const userCanBeTracked = () => {
|
|
|
17
52
|
return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
|
|
18
53
|
};
|
|
19
54
|
/**
|
|
20
|
-
* Returns the user's current consent
|
|
55
|
+
* Returns the user's current consent categories, or an empty object until the
|
|
56
|
+
* API has loaded.
|
|
21
57
|
*/
|
|
22
|
-
const
|
|
58
|
+
const getCategories = () => {
|
|
23
59
|
const api = getApi();
|
|
24
60
|
if (!api)
|
|
25
61
|
return {};
|
|
26
62
|
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
sale_of_data: api.saleOfDataAllowed(),
|
|
32
|
-
},
|
|
63
|
+
analytics: api.analyticsProcessingAllowed(),
|
|
64
|
+
marketing: api.marketingAllowed(),
|
|
65
|
+
preferences: api.preferencesProcessingAllowed(),
|
|
66
|
+
sale_of_data: api.saleOfDataAllowed(),
|
|
33
67
|
};
|
|
34
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Returns the user's current consent configuration.
|
|
71
|
+
*/
|
|
72
|
+
const getCurrentConsent = () => {
|
|
73
|
+
if (!getApi())
|
|
74
|
+
return {};
|
|
75
|
+
return { consentCategories: getCategories() };
|
|
76
|
+
};
|
|
35
77
|
/**
|
|
36
78
|
* Handles subsequent changes to consent configuration.
|
|
37
79
|
*/
|
|
@@ -41,21 +83,28 @@ const handleConsentUpdates = (updateCdpConsent) => {
|
|
|
41
83
|
});
|
|
42
84
|
};
|
|
43
85
|
export const shopifyConsentAdapter = () => {
|
|
86
|
+
// Requested once per adapter. Retried from isConsentReady() because the
|
|
87
|
+
// SDK can start before Shopify defines loadFeatures.
|
|
88
|
+
let apiRequested = false;
|
|
89
|
+
const requestApi = () => {
|
|
90
|
+
var _a;
|
|
91
|
+
if (apiRequested || typeof ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.loadFeatures) !== 'function') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
apiRequested = true;
|
|
95
|
+
loadApi();
|
|
96
|
+
};
|
|
97
|
+
requestApi();
|
|
44
98
|
return {
|
|
45
99
|
getCurrentConsent,
|
|
46
100
|
handleConsentUpdates,
|
|
47
101
|
userCanBeTracked,
|
|
48
|
-
getCategories
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
marketing: api.marketingAllowed(),
|
|
55
|
-
preferences: api.preferencesProcessingAllowed(),
|
|
56
|
-
sale_of_data: api.saleOfDataAllowed(),
|
|
57
|
-
};
|
|
102
|
+
getCategories,
|
|
103
|
+
isConsentReady: () => {
|
|
104
|
+
if (getApi())
|
|
105
|
+
return true;
|
|
106
|
+
requestApi();
|
|
107
|
+
return false;
|
|
58
108
|
},
|
|
59
|
-
isConsentReady: () => !!getApi(),
|
|
60
109
|
};
|
|
61
110
|
};
|