@chordcommerce/analytics 1.10.0 → 1.11.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.
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { ketchConsentAdapter } from './ketch.js';
|
|
10
11
|
import { shopifyConsentAdapter } from './shopify.js';
|
|
11
12
|
export const addCdpConsent = (options) => {
|
|
12
13
|
let adapter;
|
|
@@ -16,6 +17,8 @@ export const addCdpConsent = (options) => {
|
|
|
16
17
|
const getAdapter = () => {
|
|
17
18
|
var _a;
|
|
18
19
|
switch ((_a = options.consent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) {
|
|
20
|
+
case 'ketch':
|
|
21
|
+
return ketchConsentAdapter();
|
|
19
22
|
case 'shopify':
|
|
20
23
|
return shopifyConsentAdapter();
|
|
21
24
|
default:
|
|
@@ -55,9 +58,10 @@ export const addCdpConsent = (options) => {
|
|
|
55
58
|
adapter = getAdapter();
|
|
56
59
|
if (adapter === null)
|
|
57
60
|
return Promise.resolve(false);
|
|
61
|
+
yield shouldLoadCdp();
|
|
58
62
|
updateCdpConsent(adapter === null || adapter === void 0 ? void 0 : adapter.getCurrentConsent());
|
|
59
63
|
adapter === null || adapter === void 0 ? void 0 : adapter.handleConsentUpdates(updateCdpConsent);
|
|
60
|
-
return
|
|
64
|
+
return Promise.resolve(true);
|
|
61
65
|
});
|
|
62
66
|
return {
|
|
63
67
|
init,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ConsentConfiguration } from '../../types/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
ketch?: (action: string, eventName: string, handler: () => void) => undefined;
|
|
5
|
+
ketchConsent?: KetchConsentCategories;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface KetchConsentCategories {
|
|
9
|
+
[key: string]: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const ketchConsentAdapter: () => {
|
|
12
|
+
getCurrentConsent: () => ConsentConfiguration;
|
|
13
|
+
handleConsentUpdates: (updateCdpConsent: (consent: ConsentConfiguration) => void) => void;
|
|
14
|
+
userCanBeTracked: () => boolean;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns Ketch's consent categories.
|
|
3
|
+
*/
|
|
4
|
+
const getApi = () => window.ketch && window.ketchConsent;
|
|
5
|
+
/**
|
|
6
|
+
* Returns whether the user can currently be tracked.
|
|
7
|
+
*/
|
|
8
|
+
const userCanBeTracked = () => {
|
|
9
|
+
const api = getApi();
|
|
10
|
+
return api && !!Object.keys(api).length;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Returns the user's current consent configuration.
|
|
14
|
+
*/
|
|
15
|
+
const getCurrentConsent = () => {
|
|
16
|
+
const api = getApi();
|
|
17
|
+
if (!api)
|
|
18
|
+
return {};
|
|
19
|
+
return {
|
|
20
|
+
consentCategories: Object.assign({}, api),
|
|
21
|
+
dontSend: !userCanBeTracked(),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Handles subsequent changes to consent configuration.
|
|
26
|
+
*/
|
|
27
|
+
const handleConsentUpdates = (updateCdpConsent) => {
|
|
28
|
+
window.ketch('addListener', 'consent', () => {
|
|
29
|
+
updateCdpConsent(getCurrentConsent());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const ketchConsentAdapter = () => {
|
|
33
|
+
return {
|
|
34
|
+
getCurrentConsent,
|
|
35
|
+
handleConsentUpdates,
|
|
36
|
+
userCanBeTracked,
|
|
37
|
+
};
|
|
38
|
+
};
|
package/dist/types/client.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
|
|
|
30
30
|
cdp?: AnyAnalytics | (() => AnyAnalytics);
|
|
31
31
|
cdpDomain?: string;
|
|
32
32
|
cdpWriteKey?: string;
|
|
33
|
-
consent?: 'shopify';
|
|
33
|
+
consent?: 'ketch' | 'shopify';
|
|
34
34
|
debug?: boolean;
|
|
35
35
|
enableLogging?: boolean;
|
|
36
36
|
formatters: ChordAnalyticsFormatters<T>;
|
package/package.json
CHANGED