@chordcommerce/analytics 1.24.3 → 1.24.4
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.
|
@@ -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
|
}
|
|
@@ -2,9 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shopifyConsentAdapter = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Returns Shopify's Customer Privacy API.
|
|
5
|
+
* Returns Shopify's Customer Privacy API, or undefined until its methods load.
|
|
6
|
+
*
|
|
7
|
+
* Shopify puts a placeholder `customerPrivacy` object on every storefront that
|
|
8
|
+
* holds only cached values. The methods appear once a script requests the
|
|
9
|
+
* `consent-tracking-api` feature, so the placeholder alone is not usable.
|
|
10
|
+
*/
|
|
11
|
+
var getApi = function () {
|
|
12
|
+
var _a;
|
|
13
|
+
var api = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy;
|
|
14
|
+
if (typeof (api === null || api === void 0 ? void 0 : api.analyticsProcessingAllowed) !== 'function' ||
|
|
15
|
+
typeof api.marketingAllowed !== 'function' ||
|
|
16
|
+
typeof api.preferencesProcessingAllowed !== 'function' ||
|
|
17
|
+
typeof api.saleOfDataAllowed !== 'function') {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return api;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Requests the Customer Privacy API from Shopify when no other script has.
|
|
24
|
+
* CMPs such as CookieYes load it themselves; Shopify's own banner does not
|
|
25
|
+
* expose it, which left every event waiting on a consent check that threw.
|
|
6
26
|
*/
|
|
7
|
-
var
|
|
27
|
+
var loadApi = function () {
|
|
28
|
+
var _a;
|
|
29
|
+
if (getApi() || typeof ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.loadFeatures) !== 'function')
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.1' }], function (error) {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
if (error)
|
|
35
|
+
console.error('Could not load Shopify consent API', error);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.error('Could not load Shopify consent API', error);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
8
43
|
/**
|
|
9
44
|
* Returns whether the user can currently be tracked.
|
|
10
45
|
*
|
|
@@ -20,21 +55,28 @@ var userCanBeTracked = function () {
|
|
|
20
55
|
return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
|
|
21
56
|
};
|
|
22
57
|
/**
|
|
23
|
-
* Returns the user's current consent
|
|
58
|
+
* Returns the user's current consent categories, or an empty object until the
|
|
59
|
+
* API has loaded.
|
|
24
60
|
*/
|
|
25
|
-
var
|
|
61
|
+
var getCategories = function () {
|
|
26
62
|
var api = getApi();
|
|
27
63
|
if (!api)
|
|
28
64
|
return {};
|
|
29
65
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
sale_of_data: api.saleOfDataAllowed(),
|
|
35
|
-
},
|
|
66
|
+
analytics: api.analyticsProcessingAllowed(),
|
|
67
|
+
marketing: api.marketingAllowed(),
|
|
68
|
+
preferences: api.preferencesProcessingAllowed(),
|
|
69
|
+
sale_of_data: api.saleOfDataAllowed(),
|
|
36
70
|
};
|
|
37
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Returns the user's current consent configuration.
|
|
74
|
+
*/
|
|
75
|
+
var getCurrentConsent = function () {
|
|
76
|
+
if (!getApi())
|
|
77
|
+
return {};
|
|
78
|
+
return { consentCategories: getCategories() };
|
|
79
|
+
};
|
|
38
80
|
/**
|
|
39
81
|
* Handles subsequent changes to consent configuration.
|
|
40
82
|
*/
|
|
@@ -44,22 +86,29 @@ var handleConsentUpdates = function (updateCdpConsent) {
|
|
|
44
86
|
});
|
|
45
87
|
};
|
|
46
88
|
var shopifyConsentAdapter = function () {
|
|
89
|
+
// Requested once per adapter. Retried from isConsentReady() because the
|
|
90
|
+
// SDK can start before Shopify defines loadFeatures.
|
|
91
|
+
var apiRequested = false;
|
|
92
|
+
var requestApi = function () {
|
|
93
|
+
var _a;
|
|
94
|
+
if (apiRequested || typeof ((_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.loadFeatures) !== 'function') {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
apiRequested = true;
|
|
98
|
+
loadApi();
|
|
99
|
+
};
|
|
100
|
+
requestApi();
|
|
47
101
|
return {
|
|
48
102
|
getCurrentConsent: getCurrentConsent,
|
|
49
103
|
handleConsentUpdates: handleConsentUpdates,
|
|
50
104
|
userCanBeTracked: userCanBeTracked,
|
|
51
|
-
getCategories:
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
marketing: api.marketingAllowed(),
|
|
58
|
-
preferences: api.preferencesProcessingAllowed(),
|
|
59
|
-
sale_of_data: api.saleOfDataAllowed(),
|
|
60
|
-
};
|
|
105
|
+
getCategories: getCategories,
|
|
106
|
+
isConsentReady: function () {
|
|
107
|
+
if (getApi())
|
|
108
|
+
return true;
|
|
109
|
+
requestApi();
|
|
110
|
+
return false;
|
|
61
111
|
},
|
|
62
|
-
isConsentReady: function () { return !!getApi(); },
|
|
63
112
|
};
|
|
64
113
|
};
|
|
65
114
|
exports.shopifyConsentAdapter = shopifyConsentAdapter;
|
|
@@ -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
|
};
|
package/package.json
CHANGED