@chordcommerce/analytics 1.24.1 → 1.24.3
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 +2 -2
- package/dist/cjs/client/consent/index.js +18 -9
- package/dist/cjs/client/consent/shopify.js +6 -3
- package/dist/cjs/utils.d.ts +10 -1
- package/dist/cjs/utils.js +10 -1
- package/dist/client/consent/index.js +8 -0
- package/dist/client/consent/shopify.js +6 -3
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ event in that order.
|
|
|
127
127
|
|
|
128
128
|
A middleware may be synchronous or asynchronous. Synchronous middleware is never
|
|
129
129
|
awaited, so it adds no delay to event delivery. Asynchronous middleware is
|
|
130
|
-
awaited before the event is sent, capped at
|
|
130
|
+
awaited before the event is sent, capped at three seconds — a middleware that has
|
|
131
131
|
not resolved by then is abandoned, a warning is logged, and the event is sent
|
|
132
132
|
without its properties. A middleware that throws or rejects is logged and
|
|
133
133
|
skipped. A middleware never prevents an event from being sent.
|
|
@@ -174,7 +174,7 @@ Useage Example
|
|
|
174
174
|
};
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
// Asynchronous middleware: the event waits for the lookup, up to
|
|
177
|
+
// Asynchronous middleware: the event waits for the lookup, up to three seconds.
|
|
178
178
|
analytics.addSourceMiddleware(async ({ payload }) => {
|
|
179
179
|
if (payload.obj.event !== 'Order Completed') return;
|
|
180
180
|
|
|
@@ -171,7 +171,7 @@ var addCdpConsent = function (options) {
|
|
|
171
171
|
* or null if consent setup failed or was blocked.
|
|
172
172
|
*/
|
|
173
173
|
var init = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
174
|
-
var canBeTracked, error_2;
|
|
174
|
+
var canBeTracked, error_2, error_3;
|
|
175
175
|
return __generator(this, function (_a) {
|
|
176
176
|
switch (_a.label) {
|
|
177
177
|
case 0:
|
|
@@ -182,29 +182,38 @@ var addCdpConsent = function (options) {
|
|
|
182
182
|
console.error("Consent management adapter \"".concat(options.consent, "\" is not supported."));
|
|
183
183
|
return [2 /*return*/, null];
|
|
184
184
|
}
|
|
185
|
-
if (!options.awaitConsent) return [3 /*break*/,
|
|
185
|
+
if (!options.awaitConsent) return [3 /*break*/, 6];
|
|
186
186
|
if (options.debug && options.enableLogging) {
|
|
187
187
|
console.log('[Chord Analytics DEBUG]: awaitConsent is true, checking if user can be tracked');
|
|
188
188
|
}
|
|
189
189
|
return [4 /*yield*/, checkUserCanBeTracked()];
|
|
190
190
|
case 1:
|
|
191
191
|
canBeTracked = _a.sent();
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
return [2 /*return*/, null];
|
|
192
|
+
if (!!canBeTracked) return [3 /*break*/, 6];
|
|
193
|
+
if (options.debug && options.enableLogging) {
|
|
194
|
+
console.log('[Chord Analytics DEBUG]: User cannot be tracked, returning null');
|
|
197
195
|
}
|
|
198
196
|
_a.label = 2;
|
|
199
197
|
case 2:
|
|
200
198
|
_a.trys.push([2, 4, , 5]);
|
|
201
199
|
return [4 /*yield*/, setupConsentManagement()];
|
|
202
|
-
case 3:
|
|
200
|
+
case 3:
|
|
201
|
+
_a.sent();
|
|
202
|
+
return [3 /*break*/, 5];
|
|
203
203
|
case 4:
|
|
204
204
|
error_2 = _a.sent();
|
|
205
205
|
console.error('Error setting up consent management:', error_2);
|
|
206
|
+
return [3 /*break*/, 5];
|
|
207
|
+
case 5: return [2 /*return*/, null];
|
|
208
|
+
case 6:
|
|
209
|
+
_a.trys.push([6, 8, , 9]);
|
|
210
|
+
return [4 /*yield*/, setupConsentManagement()];
|
|
211
|
+
case 7: return [2 /*return*/, _a.sent()];
|
|
212
|
+
case 8:
|
|
213
|
+
error_3 = _a.sent();
|
|
214
|
+
console.error('Error setting up consent management:', error_3);
|
|
206
215
|
return [2 /*return*/, null];
|
|
207
|
-
case
|
|
216
|
+
case 9: return [2 /*return*/];
|
|
208
217
|
}
|
|
209
218
|
});
|
|
210
219
|
}); };
|
|
@@ -7,14 +7,17 @@ exports.shopifyConsentAdapter = void 0;
|
|
|
7
7
|
var getApi = function () { var _a; return (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy; };
|
|
8
8
|
/**
|
|
9
9
|
* Returns whether the user can currently be tracked.
|
|
10
|
+
*
|
|
11
|
+
* Region is deliberately not checked: Shopify returns an empty region for
|
|
12
|
+
* visitors it hasn't geolocated (e.g. US visitors who never see a banner),
|
|
13
|
+
* even when analytics and marketing are both allowed. Opt-in regions already
|
|
14
|
+
* report both as not allowed until the visitor accepts.
|
|
10
15
|
*/
|
|
11
16
|
var userCanBeTracked = function () {
|
|
12
17
|
var api = getApi();
|
|
13
18
|
if (!api)
|
|
14
19
|
return false;
|
|
15
|
-
return !!(api.
|
|
16
|
-
api.analyticsProcessingAllowed() &&
|
|
17
|
-
api.marketingAllowed());
|
|
20
|
+
return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
|
|
18
21
|
};
|
|
19
22
|
/**
|
|
20
23
|
* Returns the user's current consent configuration.
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -7,8 +7,17 @@ export declare const pruneNullValues: (props: EventProperties) => EventPropertie
|
|
|
7
7
|
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
8
8
|
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
9
9
|
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
10
|
+
*
|
|
11
|
+
* The cap has to clear the work real middleware does. The case this was built
|
|
12
|
+
* for looks up an order count to decide whether a shopper is new, which costs
|
|
13
|
+
* an auth token and then the lookup itself -- two sequential round trips. That
|
|
14
|
+
* measured 811ms from a warm browser console, and an order confirmation page,
|
|
15
|
+
* still mounting and with other events in flight, is slower than a console. At
|
|
16
|
+
* one second it was dropping its properties in the field; three gives the
|
|
17
|
+
* round trips room without holding an event long enough for a shopper to
|
|
18
|
+
* navigate away from it.
|
|
10
19
|
*/
|
|
11
|
-
export declare const MIDDLEWARE_TIMEOUT_MS =
|
|
20
|
+
export declare const MIDDLEWARE_TIMEOUT_MS = 3000;
|
|
12
21
|
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
13
22
|
export declare const TIMED_OUT: unique symbol;
|
|
14
23
|
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -66,8 +66,17 @@ exports.pruneNullValues = pruneNullValues;
|
|
|
66
66
|
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
67
67
|
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
68
68
|
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
69
|
+
*
|
|
70
|
+
* The cap has to clear the work real middleware does. The case this was built
|
|
71
|
+
* for looks up an order count to decide whether a shopper is new, which costs
|
|
72
|
+
* an auth token and then the lookup itself -- two sequential round trips. That
|
|
73
|
+
* measured 811ms from a warm browser console, and an order confirmation page,
|
|
74
|
+
* still mounting and with other events in flight, is slower than a console. At
|
|
75
|
+
* one second it was dropping its properties in the field; three gives the
|
|
76
|
+
* round trips room without holding an event long enough for a shopper to
|
|
77
|
+
* navigate away from it.
|
|
69
78
|
*/
|
|
70
|
-
exports.MIDDLEWARE_TIMEOUT_MS =
|
|
79
|
+
exports.MIDDLEWARE_TIMEOUT_MS = 3000;
|
|
71
80
|
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
72
81
|
exports.TIMED_OUT = Symbol('timed-out');
|
|
73
82
|
var isPromise = function (value) {
|
|
@@ -136,6 +136,14 @@ export const addCdpConsent = (options) => {
|
|
|
136
136
|
if (options.debug && options.enableLogging) {
|
|
137
137
|
console.log('[Chord Analytics DEBUG]: User cannot be tracked, returning null');
|
|
138
138
|
}
|
|
139
|
+
// Still listen for consent changes, so a visitor who accepts after
|
|
140
|
+
// the timeout is picked up instead of being lost for the whole visit.
|
|
141
|
+
try {
|
|
142
|
+
yield setupConsentManagement();
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('Error setting up consent management:', error);
|
|
146
|
+
}
|
|
139
147
|
return null;
|
|
140
148
|
}
|
|
141
149
|
}
|
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
const getApi = () => { var _a; return (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.customerPrivacy; };
|
|
5
5
|
/**
|
|
6
6
|
* Returns whether the user can currently be tracked.
|
|
7
|
+
*
|
|
8
|
+
* Region is deliberately not checked: Shopify returns an empty region for
|
|
9
|
+
* visitors it hasn't geolocated (e.g. US visitors who never see a banner),
|
|
10
|
+
* even when analytics and marketing are both allowed. Opt-in regions already
|
|
11
|
+
* report both as not allowed until the visitor accepts.
|
|
7
12
|
*/
|
|
8
13
|
const userCanBeTracked = () => {
|
|
9
14
|
const api = getApi();
|
|
10
15
|
if (!api)
|
|
11
16
|
return false;
|
|
12
|
-
return !!(api.
|
|
13
|
-
api.analyticsProcessingAllowed() &&
|
|
14
|
-
api.marketingAllowed());
|
|
17
|
+
return !!(api.analyticsProcessingAllowed() && api.marketingAllowed());
|
|
15
18
|
};
|
|
16
19
|
/**
|
|
17
20
|
* Returns the user's current consent configuration.
|
package/dist/utils.d.ts
CHANGED
|
@@ -7,8 +7,17 @@ export declare const pruneNullValues: (props: EventProperties) => EventPropertie
|
|
|
7
7
|
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
8
8
|
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
9
9
|
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
10
|
+
*
|
|
11
|
+
* The cap has to clear the work real middleware does. The case this was built
|
|
12
|
+
* for looks up an order count to decide whether a shopper is new, which costs
|
|
13
|
+
* an auth token and then the lookup itself -- two sequential round trips. That
|
|
14
|
+
* measured 811ms from a warm browser console, and an order confirmation page,
|
|
15
|
+
* still mounting and with other events in flight, is slower than a console. At
|
|
16
|
+
* one second it was dropping its properties in the field; three gives the
|
|
17
|
+
* round trips room without holding an event long enough for a shopper to
|
|
18
|
+
* navigate away from it.
|
|
10
19
|
*/
|
|
11
|
-
export declare const MIDDLEWARE_TIMEOUT_MS =
|
|
20
|
+
export declare const MIDDLEWARE_TIMEOUT_MS = 3000;
|
|
12
21
|
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
13
22
|
export declare const TIMED_OUT: unique symbol;
|
|
14
23
|
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
package/dist/utils.js
CHANGED
|
@@ -35,8 +35,17 @@ export const pruneNullValues = (props) => {
|
|
|
35
35
|
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
36
36
|
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
37
37
|
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
38
|
+
*
|
|
39
|
+
* The cap has to clear the work real middleware does. The case this was built
|
|
40
|
+
* for looks up an order count to decide whether a shopper is new, which costs
|
|
41
|
+
* an auth token and then the lookup itself -- two sequential round trips. That
|
|
42
|
+
* measured 811ms from a warm browser console, and an order confirmation page,
|
|
43
|
+
* still mounting and with other events in flight, is slower than a console. At
|
|
44
|
+
* one second it was dropping its properties in the field; three gives the
|
|
45
|
+
* round trips room without holding an event long enough for a shopper to
|
|
46
|
+
* navigate away from it.
|
|
38
47
|
*/
|
|
39
|
-
export const MIDDLEWARE_TIMEOUT_MS =
|
|
48
|
+
export const MIDDLEWARE_TIMEOUT_MS = 3000;
|
|
40
49
|
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
41
50
|
export const TIMED_OUT = Symbol('timed-out');
|
|
42
51
|
export const isPromise = (value) => typeof (value === null || value === void 0 ? void 0 : value.then) === 'function';
|
package/package.json
CHANGED