@chordcommerce/analytics 1.23.1 → 1.25.0-beta.2
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 +28 -2
- package/dist/cjs/client/index.d.ts +5 -42
- package/dist/cjs/client/index.js +302 -487
- package/dist/cjs/types/client.d.ts +14 -1
- package/dist/cjs/utils.d.ts +19 -0
- package/dist/cjs/utils.js +79 -1
- package/dist/client/index.d.ts +5 -42
- package/dist/client/index.js +277 -438
- package/dist/types/client.d.ts +14 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +39 -0
- package/package.json +11 -1
package/dist/client/index.js
CHANGED
|
@@ -11,12 +11,9 @@ import { addCdpSnippet, cdpQueue } from './cdp.js';
|
|
|
11
11
|
import { addCdpConsent } from './consent/index.js';
|
|
12
12
|
import { claimConsentEmit, commitConsentEmit, forgetConsent, releaseConsentEmit, } from './consent/persistence.js';
|
|
13
13
|
import { eventSchemas } from '../validators/index.js';
|
|
14
|
-
import { pruneNullValues } from '../utils.js';
|
|
14
|
+
import { isPromise, MIDDLEWARE_TIMEOUT_MS, pruneNullValues, TIMED_OUT, withTimeout, } from '../utils.js';
|
|
15
15
|
const DEBUG_MODE_STORAGE_KEY = 'chordcommerce/analytics/debug';
|
|
16
|
-
const
|
|
17
|
-
const CONSENT_QUEUE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
18
|
-
const CONSENT_QUEUE_MAX_SIZE_BYTES = 100 * 1024; // 100KB max queue size
|
|
19
|
-
const CONSENT_QUEUE_MAX_EVENTS = 50; // Max number of events to queue
|
|
16
|
+
const OPERATION_TIMEOUT_MS = 5000;
|
|
20
17
|
export class ChordAnalytics {
|
|
21
18
|
constructor(options) {
|
|
22
19
|
var _a, _b, _c, _d;
|
|
@@ -37,138 +34,12 @@ export class ChordAnalytics {
|
|
|
37
34
|
*/
|
|
38
35
|
this.cdpReadyPromise = null;
|
|
39
36
|
this.consentConfig = null;
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*/
|
|
46
|
-
this.consentEventQueue = [];
|
|
47
|
-
/**
|
|
48
|
-
* Whether we're currently waiting for consent and watching for it
|
|
49
|
-
*/
|
|
50
|
-
this.consentWatcherActive = false;
|
|
51
|
-
/**
|
|
52
|
-
* Promise that resolves when consent is ready (shared across all queued events)
|
|
53
|
-
*/
|
|
37
|
+
// Serial queue — all outgoing operations run one at a time in call order.
|
|
38
|
+
this.operationQueue = Promise.resolve();
|
|
39
|
+
// True while a reset() operation is executing in the queue.
|
|
40
|
+
this.resetting = false;
|
|
41
|
+
// Shared promise for concurrent waitForConsent() callers.
|
|
54
42
|
this.consentReadyPromise = null;
|
|
55
|
-
/**
|
|
56
|
-
* Persist the consent event queue to sessionStorage for recovery on instance recreation.
|
|
57
|
-
* Validates queue size before storing to prevent QuotaExceededError.
|
|
58
|
-
*/
|
|
59
|
-
this.persistQueueToStorage = () => {
|
|
60
|
-
if (typeof window === 'undefined' || !window.sessionStorage)
|
|
61
|
-
return;
|
|
62
|
-
try {
|
|
63
|
-
// Limit number of events to prevent unbounded queue growth
|
|
64
|
-
const eventsToStore = this.consentEventQueue.slice(-CONSENT_QUEUE_MAX_EVENTS);
|
|
65
|
-
const persistedEvents = eventsToStore.map((item) => ({
|
|
66
|
-
type: item.type,
|
|
67
|
-
args: item.args,
|
|
68
|
-
timestamp: item.timestamp,
|
|
69
|
-
}));
|
|
70
|
-
const serialized = JSON.stringify(persistedEvents);
|
|
71
|
-
// Check serialized size before attempting to store
|
|
72
|
-
const sizeInBytes = new Blob([serialized]).size;
|
|
73
|
-
if (sizeInBytes > CONSENT_QUEUE_MAX_SIZE_BYTES) {
|
|
74
|
-
this.logger(`[Chord Analytics]: Consent queue too large (${Math.round(sizeInBytes / 1024)}KB), skipping persistence`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
window.sessionStorage.setItem(CONSENT_QUEUE_STORAGE_KEY, serialized);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
this.logger('[Chord Analytics]: Error persisting queue to storage:', error);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Restore pending events from sessionStorage (keeps events less than 5 min old).
|
|
85
|
-
* Called on new instance initialization.
|
|
86
|
-
*/
|
|
87
|
-
this.restoreQueueFromStorage = () => {
|
|
88
|
-
if (typeof window === 'undefined' || !window.sessionStorage)
|
|
89
|
-
return;
|
|
90
|
-
try {
|
|
91
|
-
const stored = window.sessionStorage.getItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
92
|
-
if (!stored)
|
|
93
|
-
return;
|
|
94
|
-
let persistedEvents;
|
|
95
|
-
try {
|
|
96
|
-
persistedEvents = JSON.parse(stored);
|
|
97
|
-
}
|
|
98
|
-
catch (parseError) {
|
|
99
|
-
this.logger('[Chord Analytics]: Invalid JSON in stored consent queue, clearing storage:', parseError);
|
|
100
|
-
window.sessionStorage.removeItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
// Validate that parsed data is an array
|
|
104
|
-
if (!Array.isArray(persistedEvents)) {
|
|
105
|
-
this.logger('[Chord Analytics]: Stored consent queue is not an array, clearing storage');
|
|
106
|
-
window.sessionStorage.removeItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const now = Date.now();
|
|
110
|
-
// Filter out expired events and events with invalid structure
|
|
111
|
-
const validEvents = persistedEvents.filter((event) => {
|
|
112
|
-
// Validate event structure
|
|
113
|
-
if (typeof event !== 'object' || event === null)
|
|
114
|
-
return false;
|
|
115
|
-
if (!['track', 'page', 'identify'].includes(event.type))
|
|
116
|
-
return false;
|
|
117
|
-
if (!Array.isArray(event.args))
|
|
118
|
-
return false;
|
|
119
|
-
if (typeof event.timestamp !== 'number')
|
|
120
|
-
return false;
|
|
121
|
-
// Filter out expired events
|
|
122
|
-
return now - event.timestamp < CONSENT_QUEUE_TTL_MS;
|
|
123
|
-
});
|
|
124
|
-
if (validEvents.length === 0) {
|
|
125
|
-
window.sessionStorage.removeItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (this.options.enableLogging && this.options.debug) {
|
|
129
|
-
// eslint-disable-next-line no-console
|
|
130
|
-
console.log(`[Chord Analytics DEBUG]: Restoring ${validEvents.length} events from sessionStorage`);
|
|
131
|
-
}
|
|
132
|
-
// Add restored events to the queue
|
|
133
|
-
validEvents.forEach((event) => {
|
|
134
|
-
this.consentEventQueue.push({
|
|
135
|
-
type: event.type,
|
|
136
|
-
args: event.args,
|
|
137
|
-
timestamp: event.timestamp,
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
139
|
-
resolve: () => { },
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
// Start watching for consent if we restored events
|
|
143
|
-
if (validEvents.length > 0 && !this.consentWatcherActive) {
|
|
144
|
-
this.consentWatcherActive = true;
|
|
145
|
-
this.watchForConsentAndFlush();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
this.logger('[Chord Analytics]: Error restoring queue from storage:', error);
|
|
150
|
-
// Clear corrupted storage
|
|
151
|
-
try {
|
|
152
|
-
window.sessionStorage.removeItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
153
|
-
}
|
|
154
|
-
catch (_a) {
|
|
155
|
-
// Ignore cleanup errors
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* Clear the persisted queue from sessionStorage after successful flush.
|
|
161
|
-
*/
|
|
162
|
-
this.clearQueueFromStorage = () => {
|
|
163
|
-
if (typeof window === 'undefined' || !window.sessionStorage)
|
|
164
|
-
return;
|
|
165
|
-
try {
|
|
166
|
-
window.sessionStorage.removeItem(CONSENT_QUEUE_STORAGE_KEY);
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
this.logger('[Chord Analytics]: Error clearing queue from storage:', error);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
43
|
/**
|
|
173
44
|
* Set debug mode for Chord Analytics
|
|
174
45
|
* @param enabled - Whether debug mode should be enabled
|
|
@@ -198,6 +69,32 @@ export class ChordAnalytics {
|
|
|
198
69
|
return null;
|
|
199
70
|
return (window === null || window === void 0 ? void 0 : window[`_${namespace}`]) || cdpQueue(namespace);
|
|
200
71
|
};
|
|
72
|
+
/*
|
|
73
|
+
* The current user and anonymous ids as the CDP knows them.
|
|
74
|
+
*
|
|
75
|
+
* Exposed to source middleware, which on Segment could read these from the
|
|
76
|
+
* event facade. Either CDP may be absent or may not implement `user()`, so
|
|
77
|
+
* every step is guarded and an unknown id is simply undefined.
|
|
78
|
+
*/
|
|
79
|
+
this.currentUser = () => {
|
|
80
|
+
const read = (analytics) => {
|
|
81
|
+
var _a, _b, _c;
|
|
82
|
+
try {
|
|
83
|
+
const user = (_a = analytics === null || analytics === void 0 ? void 0 : analytics.user) === null || _a === void 0 ? void 0 : _a.call(analytics);
|
|
84
|
+
if (!user)
|
|
85
|
+
return undefined;
|
|
86
|
+
const userId = (_b = user.userId) !== null && _b !== void 0 ? _b : undefined;
|
|
87
|
+
const anonymousId = (_c = user.anonymousId) !== null && _c !== void 0 ? _c : undefined;
|
|
88
|
+
if (userId === undefined && anonymousId === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
return { userId, anonymousId };
|
|
91
|
+
}
|
|
92
|
+
catch (_d) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return read(this.ccdp()) || read(this.cdp()) || {};
|
|
97
|
+
};
|
|
201
98
|
/*
|
|
202
99
|
* Log a message to the console if `options.enableLogging` is true.
|
|
203
100
|
*/
|
|
@@ -208,21 +105,41 @@ export class ChordAnalytics {
|
|
|
208
105
|
console.log(message, ...optionalParams);
|
|
209
106
|
};
|
|
210
107
|
this.isResetting = () => {
|
|
211
|
-
return this.
|
|
108
|
+
return this.resetting;
|
|
212
109
|
};
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
110
|
+
// Enqueues an operation to run after all previously enqueued operations
|
|
111
|
+
// complete. Errors are swallowed on the internal chain so a failed operation
|
|
112
|
+
// doesn't stall the queue.
|
|
113
|
+
this.enqueue = (operation) => {
|
|
114
|
+
const queued = this.operationQueue.then(() => operation());
|
|
115
|
+
this.operationQueue = queued.catch((err) => this.logger(err));
|
|
116
|
+
return queued;
|
|
117
|
+
};
|
|
118
|
+
// Wraps a CDP call with a timeout so a stuck or unresponsive CDP cannot
|
|
119
|
+
// block the queue indefinitely.
|
|
120
|
+
// eslint-disable-next-line class-methods-use-this
|
|
121
|
+
this.withTimeout = (promise) => {
|
|
122
|
+
return Promise.race([
|
|
123
|
+
promise,
|
|
124
|
+
new Promise((_, reject) => {
|
|
125
|
+
setTimeout(() => reject(new Error(`CDP call timed out after ${OPERATION_TIMEOUT_MS}ms`)), OPERATION_TIMEOUT_MS);
|
|
126
|
+
}),
|
|
127
|
+
]);
|
|
128
|
+
};
|
|
129
|
+
// Gate for CDP readiness and consent. Reset ordering is handled by the queue.
|
|
130
|
+
// Returns undefined when nothing needs to be awaited (common case) to avoid
|
|
131
|
+
// an unnecessary microtask yield.
|
|
216
132
|
this.waitForReadyState = () => {
|
|
217
133
|
const cdp = this.cdpReadyPromise;
|
|
218
|
-
const
|
|
219
|
-
if (!cdp && !
|
|
134
|
+
const consentPending = this.consentConfig && !this.consentConfig.isConsentReady();
|
|
135
|
+
if (!cdp && !consentPending)
|
|
220
136
|
return undefined;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
137
|
+
return (() => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
if (cdp)
|
|
139
|
+
yield cdp;
|
|
140
|
+
if (consentPending)
|
|
141
|
+
yield this.waitForConsent();
|
|
142
|
+
}))();
|
|
226
143
|
};
|
|
227
144
|
/**
|
|
228
145
|
* Wait for consent manager to be ready (no timeout - queues indefinitely).
|
|
@@ -251,72 +168,6 @@ export class ChordAnalytics {
|
|
|
251
168
|
});
|
|
252
169
|
yield this.consentReadyPromise;
|
|
253
170
|
});
|
|
254
|
-
/**
|
|
255
|
-
* Queue an event to be sent when consent is ready.
|
|
256
|
-
* Persists to sessionStorage for recovery on instance recreation.
|
|
257
|
-
* Starts a consent watcher if not already active.
|
|
258
|
-
*/
|
|
259
|
-
this.queueEventForConsent = (type, args) => {
|
|
260
|
-
return new Promise((resolve) => {
|
|
261
|
-
this.consentEventQueue.push({
|
|
262
|
-
type,
|
|
263
|
-
args,
|
|
264
|
-
timestamp: Date.now(),
|
|
265
|
-
resolve,
|
|
266
|
-
});
|
|
267
|
-
// Persist queue to sessionStorage for recovery on instance recreation
|
|
268
|
-
this.persistQueueToStorage();
|
|
269
|
-
// Start watching for consent if not already
|
|
270
|
-
if (!this.consentWatcherActive) {
|
|
271
|
-
this.consentWatcherActive = true;
|
|
272
|
-
this.watchForConsentAndFlush();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* Watch for consent to become ready, then flush the queue.
|
|
278
|
-
*/
|
|
279
|
-
this.watchForConsentAndFlush = () => __awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
yield this.waitForConsent();
|
|
281
|
-
yield this.flushConsentQueue();
|
|
282
|
-
this.consentWatcherActive = false;
|
|
283
|
-
});
|
|
284
|
-
/**
|
|
285
|
-
* Flush all queued events now that consent is ready.
|
|
286
|
-
* Clears sessionStorage after successful flush.
|
|
287
|
-
*/
|
|
288
|
-
this.flushConsentQueue = () => __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
const queue = [...this.consentEventQueue];
|
|
290
|
-
this.consentEventQueue = [];
|
|
291
|
-
// Clear persisted queue from storage since we're processing them now
|
|
292
|
-
this.clearQueueFromStorage();
|
|
293
|
-
if (this.options.enableLogging && this.options.debug) {
|
|
294
|
-
// eslint-disable-next-line no-console
|
|
295
|
-
console.log(`[Chord Analytics DEBUG]: Flushing ${queue.length} queued events`);
|
|
296
|
-
}
|
|
297
|
-
const sendPromises = queue.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
try {
|
|
299
|
-
switch (item.type) {
|
|
300
|
-
case 'track':
|
|
301
|
-
yield this.sendTrackEvent(item.args[0], item.args[1], item.args[2]);
|
|
302
|
-
break;
|
|
303
|
-
case 'page':
|
|
304
|
-
yield this.sendPageEvent(item.args[0], item.args[1]);
|
|
305
|
-
break;
|
|
306
|
-
case 'identify':
|
|
307
|
-
yield this.sendIdentifyEvent(item.args[0], item.args[1], item.args[2]);
|
|
308
|
-
break;
|
|
309
|
-
default:
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
this.logger('[Chord Analytics]: Error sending queued event:', error);
|
|
315
|
-
}
|
|
316
|
-
item.resolve();
|
|
317
|
-
}));
|
|
318
|
-
yield Promise.all(sendPromises);
|
|
319
|
-
});
|
|
320
171
|
/**
|
|
321
172
|
* Configure CDP with fresh consent categories before each event.
|
|
322
173
|
* Uses Jitsu's configure() to update privacy.consentCategories.
|
|
@@ -369,31 +220,20 @@ export class ChordAnalytics {
|
|
|
369
220
|
* Send a `track` event to the CDP with any event name and properties.
|
|
370
221
|
* If consent is not ready, the event is queued until consent is available.
|
|
371
222
|
*/
|
|
372
|
-
this.track = (event, props, options) =>
|
|
223
|
+
this.track = (event, props, options) => {
|
|
373
224
|
if (this.options.enableLogging && this.options.debug) {
|
|
374
225
|
// eslint-disable-next-line no-console
|
|
375
226
|
console.log(`[Chord Analytics DEBUG]: track() called with event: "${event}"`);
|
|
376
227
|
}
|
|
377
228
|
if (!event)
|
|
378
229
|
this.logger('No event name provided');
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
console.log(`[Chord Analytics DEBUG]: track("${event}") consent not ready, queuing event`);
|
|
387
|
-
}
|
|
388
|
-
return this.queueEventForConsent('track', [event, props, options]);
|
|
389
|
-
}
|
|
390
|
-
if (this.options.enableLogging && this.options.debug) {
|
|
391
|
-
// eslint-disable-next-line no-console
|
|
392
|
-
console.log(`[Chord Analytics DEBUG]: track("${event}") sending event now`);
|
|
393
|
-
}
|
|
394
|
-
// Consent ready (or not configured) - send immediately
|
|
395
|
-
return this.sendTrackEvent(event, props, options);
|
|
396
|
-
});
|
|
230
|
+
return this.enqueue(() => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const gate = this.waitForReadyState();
|
|
232
|
+
if (gate)
|
|
233
|
+
yield gate;
|
|
234
|
+
yield this.sendTrackEvent(event, props, options);
|
|
235
|
+
}));
|
|
236
|
+
};
|
|
397
237
|
/**
|
|
398
238
|
* Internal method to actually send a track event to CDP.
|
|
399
239
|
*/
|
|
@@ -404,11 +244,13 @@ export class ChordAnalytics {
|
|
|
404
244
|
const searchParams = typeof window !== 'undefined' ? window.location.search : '';
|
|
405
245
|
const urlSearchParams = new URLSearchParams(searchParams);
|
|
406
246
|
const searchData = Object.fromEntries(urlSearchParams.entries());
|
|
407
|
-
|
|
408
|
-
|
|
247
|
+
const { userId, anonymousId } = this.currentUser();
|
|
248
|
+
const invoke = (func) => {
|
|
409
249
|
try {
|
|
410
|
-
|
|
250
|
+
return func({
|
|
411
251
|
payload: {
|
|
252
|
+
userId,
|
|
253
|
+
anonymousId,
|
|
412
254
|
obj: {
|
|
413
255
|
properties: props,
|
|
414
256
|
event,
|
|
@@ -422,12 +264,44 @@ export class ChordAnalytics {
|
|
|
422
264
|
},
|
|
423
265
|
next: (_) => _,
|
|
424
266
|
});
|
|
425
|
-
if (result && typeof result === 'object') {
|
|
426
|
-
middlewareProps = Object.assign(Object.assign({}, middlewareProps), result);
|
|
427
|
-
}
|
|
428
267
|
}
|
|
429
268
|
catch (error) {
|
|
430
269
|
console.warn('Middleware error:', error);
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Give an asynchronous middleware until MIDDLEWARE_TIMEOUT_MS to produce
|
|
275
|
+
* its properties. Neither a timeout nor a rejection is allowed to reach
|
|
276
|
+
* the caller: a middleware must never cost the event.
|
|
277
|
+
*/
|
|
278
|
+
const settle = (returned) => {
|
|
279
|
+
if (!isPromise(returned))
|
|
280
|
+
return returned;
|
|
281
|
+
return withTimeout(returned, MIDDLEWARE_TIMEOUT_MS)
|
|
282
|
+
.then((settled) => {
|
|
283
|
+
if (settled === TIMED_OUT) {
|
|
284
|
+
console.warn(`Middleware timed out after ${MIDDLEWARE_TIMEOUT_MS}ms; its properties were dropped`);
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
return settled;
|
|
288
|
+
})
|
|
289
|
+
.catch((error) => {
|
|
290
|
+
console.warn('Middleware error:', error);
|
|
291
|
+
return undefined;
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
// Every middleware is invoked in registration order, as before. Only if
|
|
295
|
+
// one actually returned a promise is anything awaited -- so a set of
|
|
296
|
+
// purely synchronous middleware reaches the CDP on the same tick it
|
|
297
|
+
// always has, and callers that never await `track()` are unaffected.
|
|
298
|
+
const returned = this.middleware.map(invoke);
|
|
299
|
+
const results = returned.some(isPromise)
|
|
300
|
+
? yield Promise.all(returned.map(settle))
|
|
301
|
+
: returned;
|
|
302
|
+
results.forEach((result) => {
|
|
303
|
+
if (result && typeof result === 'object') {
|
|
304
|
+
middlewareProps = Object.assign(Object.assign({}, middlewareProps), result);
|
|
431
305
|
}
|
|
432
306
|
});
|
|
433
307
|
}
|
|
@@ -441,53 +315,38 @@ export class ChordAnalytics {
|
|
|
441
315
|
}
|
|
442
316
|
// Configure CDP with fresh consent before sending
|
|
443
317
|
this.configureConsentOnCdp();
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}));
|
|
452
|
-
}
|
|
453
|
-
const b = this.cdp();
|
|
454
|
-
if (b && typeof b.track === 'function') {
|
|
455
|
-
cdpPromises.push(new Promise((cdpResolve) => {
|
|
456
|
-
b.track(event, finalEventProps, options, () => cdpResolve());
|
|
457
|
-
}));
|
|
458
|
-
}
|
|
459
|
-
if (cdpPromises.length > 0) {
|
|
460
|
-
Promise.allSettled(cdpPromises).then(() => resolve());
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
resolve();
|
|
464
|
-
}
|
|
318
|
+
const cdpPromises = [];
|
|
319
|
+
try {
|
|
320
|
+
const a = this.ccdp();
|
|
321
|
+
if (a && typeof a.track === 'function') {
|
|
322
|
+
cdpPromises.push(this.withTimeout(new Promise((resolve) => {
|
|
323
|
+
a.track(event, finalEventProps, options, () => resolve());
|
|
324
|
+
})));
|
|
465
325
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
resolve
|
|
326
|
+
const b = this.cdp();
|
|
327
|
+
if (b && typeof b.track === 'function') {
|
|
328
|
+
cdpPromises.push(this.withTimeout(new Promise((resolve) => {
|
|
329
|
+
b.track(event, finalEventProps, options, () => resolve());
|
|
330
|
+
})));
|
|
469
331
|
}
|
|
470
|
-
}
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
this.logger(error);
|
|
335
|
+
}
|
|
336
|
+
yield Promise.allSettled(cdpPromises);
|
|
471
337
|
});
|
|
472
338
|
/**
|
|
473
339
|
* Send an `identify` event to the CDP with user id and traits.
|
|
474
340
|
* If consent is not ready, the event is queued until consent is available.
|
|
475
341
|
*/
|
|
476
|
-
this.identify = (userIdOrTraits, traitsOrOptions, options) =>
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
traitsOrOptions,
|
|
485
|
-
options,
|
|
486
|
-
]);
|
|
487
|
-
}
|
|
488
|
-
// Consent ready (or not configured) - send immediately
|
|
489
|
-
return this.sendIdentifyEvent(userIdOrTraits, traitsOrOptions, options);
|
|
490
|
-
});
|
|
342
|
+
this.identify = (userIdOrTraits, traitsOrOptions, options) => {
|
|
343
|
+
return this.enqueue(() => __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
const gate = this.waitForReadyState();
|
|
345
|
+
if (gate)
|
|
346
|
+
yield gate;
|
|
347
|
+
yield this.sendIdentifyEvent(userIdOrTraits, traitsOrOptions, options);
|
|
348
|
+
}));
|
|
349
|
+
};
|
|
491
350
|
/**
|
|
492
351
|
* Internal method to actually send an identify event to CDP.
|
|
493
352
|
*/
|
|
@@ -511,25 +370,25 @@ export class ChordAnalytics {
|
|
|
511
370
|
const identifyPromises = [];
|
|
512
371
|
const a = this.ccdp();
|
|
513
372
|
if (a && typeof a.identify === 'function') {
|
|
514
|
-
identifyPromises.push(new Promise((resolve) => {
|
|
373
|
+
identifyPromises.push(this.withTimeout(new Promise((resolve) => {
|
|
515
374
|
if (userId) {
|
|
516
375
|
a.identify(userId, traits, opts, () => resolve());
|
|
517
376
|
}
|
|
518
377
|
else {
|
|
519
378
|
a.identify(traits, opts, () => resolve());
|
|
520
379
|
}
|
|
521
|
-
}));
|
|
380
|
+
})));
|
|
522
381
|
}
|
|
523
382
|
const b = this.cdp();
|
|
524
383
|
if (b && typeof b.identify === 'function') {
|
|
525
|
-
identifyPromises.push(new Promise((resolve) => {
|
|
384
|
+
identifyPromises.push(this.withTimeout(new Promise((resolve) => {
|
|
526
385
|
if (userId) {
|
|
527
386
|
b.identify(userId, traits, opts, () => resolve());
|
|
528
387
|
}
|
|
529
388
|
else {
|
|
530
389
|
b.identify(traits, opts, () => resolve());
|
|
531
390
|
}
|
|
532
|
-
}));
|
|
391
|
+
})));
|
|
533
392
|
}
|
|
534
393
|
const results = yield Promise.allSettled(identifyPromises);
|
|
535
394
|
this.logger('identify event sent', results);
|
|
@@ -542,100 +401,82 @@ export class ChordAnalytics {
|
|
|
542
401
|
* Send a `page` event to the CDP.
|
|
543
402
|
* If consent is not ready, the event is queued until consent is available.
|
|
544
403
|
*/
|
|
545
|
-
this.page = (options, props = {}) =>
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
// Consent ready (or not configured) - send immediately
|
|
554
|
-
return this.sendPageEvent(options, props);
|
|
555
|
-
});
|
|
404
|
+
this.page = (options, props = {}) => {
|
|
405
|
+
return this.enqueue(() => __awaiter(this, void 0, void 0, function* () {
|
|
406
|
+
const gate = this.waitForReadyState();
|
|
407
|
+
if (gate)
|
|
408
|
+
yield gate;
|
|
409
|
+
yield this.sendPageEvent(options, props);
|
|
410
|
+
}));
|
|
411
|
+
};
|
|
556
412
|
/**
|
|
557
413
|
* Internal method to actually send a page event to CDP.
|
|
558
414
|
*/
|
|
559
415
|
this.sendPageEvent = (options, props = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
560
416
|
// Configure CDP with fresh consent before sending
|
|
561
417
|
this.configureConsentOnCdp();
|
|
562
|
-
|
|
563
|
-
const pagePromises = [];
|
|
564
|
-
try {
|
|
565
|
-
const a = this.ccdp();
|
|
566
|
-
if (a && typeof a.page === 'function') {
|
|
567
|
-
pagePromises.push(new Promise((cdpResolve) => {
|
|
568
|
-
a.page(Object.assign(Object.assign({}, props), { meta: this.meta() }), options, () => cdpResolve());
|
|
569
|
-
}));
|
|
570
|
-
}
|
|
571
|
-
const b = this.cdp();
|
|
572
|
-
if (b && typeof b.page === 'function') {
|
|
573
|
-
pagePromises.push(new Promise((cdpResolve) => {
|
|
574
|
-
b.page(Object.assign(Object.assign({}, props), { meta: this.meta() }), options, () => cdpResolve());
|
|
575
|
-
}));
|
|
576
|
-
}
|
|
577
|
-
if (pagePromises.length > 0) {
|
|
578
|
-
Promise.allSettled(pagePromises).then((results) => {
|
|
579
|
-
this.logger('page event sent', results);
|
|
580
|
-
resolve();
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
resolve();
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
catch (error) {
|
|
588
|
-
this.logger(error);
|
|
589
|
-
resolve();
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
// Coalesces concurrent reset() calls — a second caller gets the same in-flight
|
|
594
|
-
// Promise rather than triggering a duplicate reset.
|
|
595
|
-
this.reset = () => {
|
|
596
|
-
if (!this.resetCompletePromise) {
|
|
597
|
-
this.resetCompletePromise = this.performReset();
|
|
598
|
-
}
|
|
599
|
-
return this.resetCompletePromise;
|
|
600
|
-
};
|
|
601
|
-
this.performReset = () => __awaiter(this, void 0, void 0, function* () {
|
|
602
|
-
var _e;
|
|
418
|
+
const pagePromises = [];
|
|
603
419
|
try {
|
|
604
420
|
// The new identity has no consent event of its own yet, so drop the
|
|
605
421
|
// stored signature and let the next init emit a fresh baseline.
|
|
606
422
|
forgetConsent(this.options.namespace);
|
|
607
423
|
const a = this.ccdp();
|
|
608
|
-
if (a && typeof a.
|
|
609
|
-
|
|
424
|
+
if (a && typeof a.page === 'function') {
|
|
425
|
+
pagePromises.push(this.withTimeout(new Promise((resolve) => {
|
|
426
|
+
a.page(Object.assign(Object.assign({}, props), { meta: this.meta() }), options, () => resolve());
|
|
427
|
+
})));
|
|
610
428
|
}
|
|
611
429
|
const b = this.cdp();
|
|
612
|
-
if (b && typeof b.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
let attempts = 0;
|
|
617
|
-
while (attempts < maxAttempts) {
|
|
618
|
-
// eslint-disable-next-line
|
|
619
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
620
|
-
try {
|
|
621
|
-
const userState = ((_e = a === null || a === void 0 ? void 0 : a.user) === null || _e === void 0 ? void 0 : _e.call(a)) || {};
|
|
622
|
-
if (userState.userId === null || userState.userId === undefined) {
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
catch (_f) {
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
attempts++;
|
|
430
|
+
if (b && typeof b.page === 'function') {
|
|
431
|
+
pagePromises.push(this.withTimeout(new Promise((resolve) => {
|
|
432
|
+
b.page(Object.assign(Object.assign({}, props), { meta: this.meta() }), options, () => resolve());
|
|
433
|
+
})));
|
|
630
434
|
}
|
|
631
435
|
}
|
|
632
436
|
catch (error) {
|
|
633
437
|
this.logger(error);
|
|
634
438
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
439
|
+
const results = yield Promise.allSettled(pagePromises);
|
|
440
|
+
this.logger('page event sent', results);
|
|
638
441
|
});
|
|
442
|
+
this.reset = () => {
|
|
443
|
+
return this.enqueue(() => __awaiter(this, void 0, void 0, function* () {
|
|
444
|
+
var _a;
|
|
445
|
+
this.resetting = true;
|
|
446
|
+
try {
|
|
447
|
+
const a = this.ccdp();
|
|
448
|
+
if (a && typeof a.reset === 'function') {
|
|
449
|
+
a.reset();
|
|
450
|
+
}
|
|
451
|
+
const b = this.cdp();
|
|
452
|
+
if (b && typeof b.reset === 'function') {
|
|
453
|
+
b.reset();
|
|
454
|
+
}
|
|
455
|
+
const maxAttempts = 50;
|
|
456
|
+
let attempts = 0;
|
|
457
|
+
while (attempts < maxAttempts) {
|
|
458
|
+
// eslint-disable-next-line
|
|
459
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
460
|
+
try {
|
|
461
|
+
const userState = ((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.call(a)) || {};
|
|
462
|
+
if (userState.userId === null || userState.userId === undefined) {
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch (_b) {
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
attempts++;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
this.logger(error);
|
|
474
|
+
}
|
|
475
|
+
finally {
|
|
476
|
+
this.resetting = false;
|
|
477
|
+
}
|
|
478
|
+
}));
|
|
479
|
+
};
|
|
639
480
|
/**
|
|
640
481
|
* Handler for postMessage events from the Shopify Web Pixel sandbox.
|
|
641
482
|
* Bound to the instance for proper `this` context and cleanup.
|
|
@@ -726,8 +567,8 @@ export class ChordAnalytics {
|
|
|
726
567
|
};
|
|
727
568
|
// TODO: Add support for props.products
|
|
728
569
|
this.trackCartViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
729
|
-
var _g, _h, _j, _k, _l, _m, _o, _p
|
|
730
|
-
const cart = (
|
|
570
|
+
var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
571
|
+
const cart = (_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.formatters) === null || _f === void 0 ? void 0 : _f.objects) === null || _g === void 0 ? void 0 : _g.cart) === null || _h === void 0 ? void 0 : _h.call(_g, {
|
|
731
572
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
732
573
|
});
|
|
733
574
|
const payload = {
|
|
@@ -736,17 +577,17 @@ export class ChordAnalytics {
|
|
|
736
577
|
products: cart === null || cart === void 0 ? void 0 : cart.products,
|
|
737
578
|
value: cart === null || cart === void 0 ? void 0 : cart.value,
|
|
738
579
|
};
|
|
739
|
-
if ((
|
|
740
|
-
const formattedPayload = (
|
|
580
|
+
if ((_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.formatters) === null || _k === void 0 ? void 0 : _k.events) === null || _l === void 0 ? void 0 : _l.cartViewed) {
|
|
581
|
+
const formattedPayload = (_p = (_o = (_m = this.options) === null || _m === void 0 ? void 0 : _m.formatters) === null || _o === void 0 ? void 0 : _o.events) === null || _p === void 0 ? void 0 : _p.cartViewed(props, payload);
|
|
741
582
|
return this.track('Cart Viewed', formattedPayload, options);
|
|
742
583
|
}
|
|
743
584
|
return this.track('Cart Viewed', payload, options);
|
|
744
585
|
});
|
|
745
586
|
// TODO: Add support for props.products
|
|
746
587
|
this.trackCheckoutStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
747
|
-
var _s, _t, _u, _v, _w
|
|
748
|
-
const formatter = (
|
|
749
|
-
const checkout = (
|
|
588
|
+
var _q, _r, _s, _t, _u, _v, _w;
|
|
589
|
+
const formatter = (_s = (_r = (_q = this.options) === null || _q === void 0 ? void 0 : _q.formatters) === null || _r === void 0 ? void 0 : _r.events) === null || _s === void 0 ? void 0 : _s.checkoutStarted;
|
|
590
|
+
const checkout = (_w = (_v = (_u = (_t = this.options) === null || _t === void 0 ? void 0 : _t.formatters) === null || _u === void 0 ? void 0 : _u.objects) === null || _v === void 0 ? void 0 : _v.checkout) === null || _w === void 0 ? void 0 : _w.call(_v, {
|
|
750
591
|
checkout: props === null || props === void 0 ? void 0 : props.checkout,
|
|
751
592
|
});
|
|
752
593
|
const payload = checkout;
|
|
@@ -757,8 +598,8 @@ export class ChordAnalytics {
|
|
|
757
598
|
return this.track('Checkout Started', payload, options);
|
|
758
599
|
});
|
|
759
600
|
this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
760
|
-
var
|
|
761
|
-
const formatter = (
|
|
601
|
+
var _x, _y, _z;
|
|
602
|
+
const formatter = (_z = (_y = (_x = this.options) === null || _x === void 0 ? void 0 : _x.formatters) === null || _y === void 0 ? void 0 : _y.events) === null || _z === void 0 ? void 0 : _z.checkoutStepCompleted;
|
|
762
603
|
const payload = {
|
|
763
604
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
764
605
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -772,8 +613,8 @@ export class ChordAnalytics {
|
|
|
772
613
|
return this.track('Checkout Step Completed', payload, options);
|
|
773
614
|
});
|
|
774
615
|
this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
775
|
-
var
|
|
776
|
-
const formatter = (
|
|
616
|
+
var _0, _1, _2;
|
|
617
|
+
const formatter = (_2 = (_1 = (_0 = this.options) === null || _0 === void 0 ? void 0 : _0.formatters) === null || _1 === void 0 ? void 0 : _1.events) === null || _2 === void 0 ? void 0 : _2.checkoutStepViewed;
|
|
777
618
|
const payload = {
|
|
778
619
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
779
620
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -787,8 +628,8 @@ export class ChordAnalytics {
|
|
|
787
628
|
return this.track('Checkout Step Viewed', payload, options);
|
|
788
629
|
});
|
|
789
630
|
this.trackCouponApplied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
790
|
-
var
|
|
791
|
-
const formatter = (
|
|
631
|
+
var _3, _4, _5;
|
|
632
|
+
const formatter = (_5 = (_4 = (_3 = this.options) === null || _3 === void 0 ? void 0 : _3.formatters) === null || _4 === void 0 ? void 0 : _4.events) === null || _5 === void 0 ? void 0 : _5.couponApplied;
|
|
792
633
|
const payload = {
|
|
793
634
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
794
635
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -803,8 +644,8 @@ export class ChordAnalytics {
|
|
|
803
644
|
return this.track('Coupon Applied', payload, options);
|
|
804
645
|
});
|
|
805
646
|
this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
806
|
-
var
|
|
807
|
-
const formatter = (
|
|
647
|
+
var _6, _7, _8;
|
|
648
|
+
const formatter = (_8 = (_7 = (_6 = this.options) === null || _6 === void 0 ? void 0 : _6.formatters) === null || _7 === void 0 ? void 0 : _7.events) === null || _8 === void 0 ? void 0 : _8.couponDenied;
|
|
808
649
|
const payload = {
|
|
809
650
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
810
651
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -819,8 +660,8 @@ export class ChordAnalytics {
|
|
|
819
660
|
return this.track('Coupon Denied', payload, options);
|
|
820
661
|
});
|
|
821
662
|
this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
822
|
-
var
|
|
823
|
-
const formatter = (
|
|
663
|
+
var _9, _10, _11;
|
|
664
|
+
const formatter = (_11 = (_10 = (_9 = this.options) === null || _9 === void 0 ? void 0 : _9.formatters) === null || _10 === void 0 ? void 0 : _10.events) === null || _11 === void 0 ? void 0 : _11.couponEntered;
|
|
824
665
|
const payload = {
|
|
825
666
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
826
667
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -834,8 +675,8 @@ export class ChordAnalytics {
|
|
|
834
675
|
return this.track('Coupon Entered', payload, options);
|
|
835
676
|
});
|
|
836
677
|
this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
837
|
-
var
|
|
838
|
-
const formatter = (
|
|
678
|
+
var _12, _13, _14;
|
|
679
|
+
const formatter = (_14 = (_13 = (_12 = this.options) === null || _12 === void 0 ? void 0 : _12.formatters) === null || _13 === void 0 ? void 0 : _13.events) === null || _14 === void 0 ? void 0 : _14.couponRemoved;
|
|
839
680
|
const payload = {
|
|
840
681
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
841
682
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -850,8 +691,8 @@ export class ChordAnalytics {
|
|
|
850
691
|
return this.track('Coupon Removed', payload, options);
|
|
851
692
|
});
|
|
852
693
|
this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
853
|
-
var
|
|
854
|
-
const formatter = (
|
|
694
|
+
var _15, _16, _17;
|
|
695
|
+
const formatter = (_17 = (_16 = (_15 = this.options) === null || _15 === void 0 ? void 0 : _15.formatters) === null || _16 === void 0 ? void 0 : _16.events) === null || _17 === void 0 ? void 0 : _17.emailCaptured;
|
|
855
696
|
const payload = {
|
|
856
697
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
857
698
|
placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
|
|
@@ -864,13 +705,13 @@ export class ChordAnalytics {
|
|
|
864
705
|
return this.track('Email Captured', payload, options);
|
|
865
706
|
});
|
|
866
707
|
this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
867
|
-
var _20, _21, _22, _23, _24, _25, _26, _27, _28, _29
|
|
868
|
-
const formatter = (
|
|
869
|
-
const product = (
|
|
870
|
-
const cart = (
|
|
708
|
+
var _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29;
|
|
709
|
+
const formatter = (_20 = (_19 = (_18 = this.options) === null || _18 === void 0 ? void 0 : _18.formatters) === null || _19 === void 0 ? void 0 : _19.events) === null || _20 === void 0 ? void 0 : _20.productAdded;
|
|
710
|
+
const product = (_24 = (_23 = (_22 = (_21 = this.options) === null || _21 === void 0 ? void 0 : _21.formatters) === null || _22 === void 0 ? void 0 : _22.objects) === null || _23 === void 0 ? void 0 : _23.product) === null || _24 === void 0 ? void 0 : _24.call(_23, props === null || props === void 0 ? void 0 : props.product);
|
|
711
|
+
const cart = (_28 = (_27 = (_26 = (_25 = this.options) === null || _25 === void 0 ? void 0 : _25.formatters) === null || _26 === void 0 ? void 0 : _26.objects) === null || _27 === void 0 ? void 0 : _27.cart) === null || _28 === void 0 ? void 0 : _28.call(_27, {
|
|
871
712
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
872
713
|
});
|
|
873
|
-
const quantity = ((
|
|
714
|
+
const quantity = ((_29 = props === null || props === void 0 ? void 0 : props.product) === null || _29 === void 0 ? void 0 : _29.quantity) || 1;
|
|
874
715
|
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, products: [Object.assign(Object.assign({}, product), { quantity })], total: product.price * (quantity || 1), value: product.price * (quantity || 1) });
|
|
875
716
|
if (typeof formatter === 'function') {
|
|
876
717
|
const formattedPayload = formatter(props, payload);
|
|
@@ -879,14 +720,14 @@ export class ChordAnalytics {
|
|
|
879
720
|
return this.track('Product Added', payload, options);
|
|
880
721
|
});
|
|
881
722
|
this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
882
|
-
var _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42
|
|
883
|
-
const formatter = (
|
|
884
|
-
const product = (
|
|
885
|
-
const cart = (
|
|
723
|
+
var _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42;
|
|
724
|
+
const formatter = (_32 = (_31 = (_30 = this.options) === null || _30 === void 0 ? void 0 : _30.formatters) === null || _31 === void 0 ? void 0 : _31.events) === null || _32 === void 0 ? void 0 : _32.productClicked;
|
|
725
|
+
const product = (_36 = (_35 = (_34 = (_33 = this.options) === null || _33 === void 0 ? void 0 : _33.formatters) === null || _34 === void 0 ? void 0 : _34.objects) === null || _35 === void 0 ? void 0 : _35.product) === null || _36 === void 0 ? void 0 : _36.call(_35, props === null || props === void 0 ? void 0 : props.product);
|
|
726
|
+
const cart = (_40 = (_39 = (_38 = (_37 = this.options) === null || _37 === void 0 ? void 0 : _37.formatters) === null || _38 === void 0 ? void 0 : _38.objects) === null || _39 === void 0 ? void 0 : _39.cart) === null || _40 === void 0 ? void 0 : _40.call(_39, {
|
|
886
727
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
887
728
|
});
|
|
888
|
-
const quantity = ((
|
|
889
|
-
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (
|
|
729
|
+
const quantity = ((_41 = props === null || props === void 0 ? void 0 : props.product) === null || _41 === void 0 ? void 0 : _41.quantity) || 1;
|
|
730
|
+
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_42 = props === null || props === void 0 ? void 0 : props.listId) === null || _42 === void 0 ? void 0 : _42.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
|
|
890
731
|
if (typeof formatter === 'function') {
|
|
891
732
|
const formattedPayload = formatter(props, payload);
|
|
892
733
|
return this.track('Product Clicked', formattedPayload, options);
|
|
@@ -894,13 +735,13 @@ export class ChordAnalytics {
|
|
|
894
735
|
return this.track('Product Clicked', payload, options);
|
|
895
736
|
});
|
|
896
737
|
this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
897
|
-
var _45, _46, _47, _48, _49, _50, _51, _52, _53, _54
|
|
898
|
-
const formatter = (
|
|
899
|
-
const product = (
|
|
900
|
-
const cart = (
|
|
738
|
+
var _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54;
|
|
739
|
+
const formatter = (_45 = (_44 = (_43 = this.options) === null || _43 === void 0 ? void 0 : _43.formatters) === null || _44 === void 0 ? void 0 : _44.events) === null || _45 === void 0 ? void 0 : _45.variantClicked;
|
|
740
|
+
const product = (_49 = (_48 = (_47 = (_46 = this.options) === null || _46 === void 0 ? void 0 : _46.formatters) === null || _47 === void 0 ? void 0 : _47.objects) === null || _48 === void 0 ? void 0 : _48.product) === null || _49 === void 0 ? void 0 : _49.call(_48, props === null || props === void 0 ? void 0 : props.product);
|
|
741
|
+
const cart = (_53 = (_52 = (_51 = (_50 = this.options) === null || _50 === void 0 ? void 0 : _50.formatters) === null || _51 === void 0 ? void 0 : _51.objects) === null || _52 === void 0 ? void 0 : _52.cart) === null || _53 === void 0 ? void 0 : _53.call(_52, {
|
|
901
742
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
902
743
|
});
|
|
903
|
-
const quantity = ((
|
|
744
|
+
const quantity = ((_54 = props === null || props === void 0 ? void 0 : props.product) === null || _54 === void 0 ? void 0 : _54.quantity) || 1;
|
|
904
745
|
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, quantity: quantity, line_item_id: props === null || props === void 0 ? void 0 : props.lineItemId, coupon: props === null || props === void 0 ? void 0 : props.coupon });
|
|
905
746
|
if (typeof formatter === 'function') {
|
|
906
747
|
const formattedPayload = formatter(props, payload);
|
|
@@ -909,13 +750,13 @@ export class ChordAnalytics {
|
|
|
909
750
|
return this.track('Variant Clicked', payload, options);
|
|
910
751
|
});
|
|
911
752
|
this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
912
|
-
var
|
|
913
|
-
const formatter = (
|
|
753
|
+
var _55, _56, _57, _58, _59;
|
|
754
|
+
const formatter = (_57 = (_56 = (_55 = this.options) === null || _55 === void 0 ? void 0 : _55.formatters) === null || _56 === void 0 ? void 0 : _56.events) === null || _57 === void 0 ? void 0 : _57.productListFiltered;
|
|
914
755
|
const payload = {
|
|
915
756
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
916
757
|
filters: props === null || props === void 0 ? void 0 : props.filters,
|
|
917
|
-
list_id: (
|
|
918
|
-
item_list_id: (
|
|
758
|
+
list_id: (_58 = props === null || props === void 0 ? void 0 : props.listId) === null || _58 === void 0 ? void 0 : _58.toString(),
|
|
759
|
+
item_list_id: (_59 = props === null || props === void 0 ? void 0 : props.listId) === null || _59 === void 0 ? void 0 : _59.toString(),
|
|
919
760
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
920
761
|
sorts: props === null || props === void 0 ? void 0 : props.sorts,
|
|
921
762
|
};
|
|
@@ -926,14 +767,14 @@ export class ChordAnalytics {
|
|
|
926
767
|
return this.track('Product List Filtered', payload, options);
|
|
927
768
|
});
|
|
928
769
|
this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
929
|
-
var _62, _63, _64, _65
|
|
930
|
-
const formatter = (
|
|
770
|
+
var _60, _61, _62, _63, _64, _65;
|
|
771
|
+
const formatter = (_62 = (_61 = (_60 = this.options) === null || _60 === void 0 ? void 0 : _60.formatters) === null || _61 === void 0 ? void 0 : _61.events) === null || _62 === void 0 ? void 0 : _62.productListViewed;
|
|
931
772
|
const payload = {
|
|
932
773
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
933
|
-
list_id: (
|
|
934
|
-
item_list_id: (
|
|
774
|
+
list_id: (_63 = props === null || props === void 0 ? void 0 : props.listId) === null || _63 === void 0 ? void 0 : _63.toString(),
|
|
775
|
+
item_list_id: (_64 = props === null || props === void 0 ? void 0 : props.listId) === null || _64 === void 0 ? void 0 : _64.toString(),
|
|
935
776
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
936
|
-
products: (
|
|
777
|
+
products: (_65 = props === null || props === void 0 ? void 0 : props.products) === null || _65 === void 0 ? void 0 : _65.map((p, i) => {
|
|
937
778
|
var _a, _b, _c, _d;
|
|
938
779
|
return (_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.product) === null || _d === void 0 ? void 0 : _d.call(_c, Object.assign(Object.assign({}, p), { position: i + 1 }));
|
|
939
780
|
}),
|
|
@@ -946,8 +787,8 @@ export class ChordAnalytics {
|
|
|
946
787
|
return this.track('Product List Viewed', payload, options);
|
|
947
788
|
});
|
|
948
789
|
this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
949
|
-
var _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80
|
|
950
|
-
const formatter = (
|
|
790
|
+
var _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80;
|
|
791
|
+
const formatter = (_68 = (_67 = (_66 = this.options) === null || _66 === void 0 ? void 0 : _66.formatters) === null || _67 === void 0 ? void 0 : _67.events) === null || _68 === void 0 ? void 0 : _68.productRemoved;
|
|
951
792
|
/*
|
|
952
793
|
const product = this.options?.formatters?.objects?.product?.({
|
|
953
794
|
position: props?.position,
|
|
@@ -956,13 +797,13 @@ export class ChordAnalytics {
|
|
|
956
797
|
variantId: props?.variantId,
|
|
957
798
|
})
|
|
958
799
|
*/
|
|
959
|
-
const lineItem = (
|
|
800
|
+
const lineItem = (_72 = (_71 = (_70 = (_69 = this.options) === null || _69 === void 0 ? void 0 : _69.formatters) === null || _70 === void 0 ? void 0 : _70.objects) === null || _71 === void 0 ? void 0 : _71.lineItem) === null || _72 === void 0 ? void 0 : _72.call(_71, {
|
|
960
801
|
lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
|
|
961
802
|
});
|
|
962
|
-
const cart = (
|
|
803
|
+
const cart = (_76 = (_75 = (_74 = (_73 = this.options) === null || _73 === void 0 ? void 0 : _73.formatters) === null || _74 === void 0 ? void 0 : _74.objects) === null || _75 === void 0 ? void 0 : _75.cart) === null || _76 === void 0 ? void 0 : _76.call(_75, {
|
|
963
804
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
964
805
|
});
|
|
965
|
-
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((
|
|
806
|
+
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_77 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _77 !== void 0 ? _77 : 0) * ((_78 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _78 !== void 0 ? _78 : 1), value: ((_79 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _79 !== void 0 ? _79 : 0) * ((_80 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _80 !== void 0 ? _80 : 1) });
|
|
966
807
|
if (typeof formatter === 'function') {
|
|
967
808
|
const formattedPayload = formatter(props, payload);
|
|
968
809
|
return this.track('Product Removed', formattedPayload, options);
|
|
@@ -970,14 +811,14 @@ export class ChordAnalytics {
|
|
|
970
811
|
return this.track('Product Removed', payload, options);
|
|
971
812
|
});
|
|
972
813
|
this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
973
|
-
var _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93
|
|
974
|
-
const formatter = (
|
|
975
|
-
const product = (
|
|
976
|
-
const cart = (
|
|
814
|
+
var _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93;
|
|
815
|
+
const formatter = (_83 = (_82 = (_81 = this.options) === null || _81 === void 0 ? void 0 : _81.formatters) === null || _82 === void 0 ? void 0 : _82.events) === null || _83 === void 0 ? void 0 : _83.productViewed;
|
|
816
|
+
const product = (_87 = (_86 = (_85 = (_84 = this.options) === null || _84 === void 0 ? void 0 : _84.formatters) === null || _85 === void 0 ? void 0 : _85.objects) === null || _86 === void 0 ? void 0 : _86.product) === null || _87 === void 0 ? void 0 : _87.call(_86, props === null || props === void 0 ? void 0 : props.product);
|
|
817
|
+
const cart = (_91 = (_90 = (_89 = (_88 = this.options) === null || _88 === void 0 ? void 0 : _88.formatters) === null || _89 === void 0 ? void 0 : _89.objects) === null || _90 === void 0 ? void 0 : _90.cart) === null || _91 === void 0 ? void 0 : _91.call(_90, {
|
|
977
818
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
978
819
|
});
|
|
979
|
-
const quantity = ((
|
|
980
|
-
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, products: [Object.assign(Object.assign({}, product), { quantity })], value: product.price * (((
|
|
820
|
+
const quantity = ((_92 = props === null || props === void 0 ? void 0 : props.product) === null || _92 === void 0 ? void 0 : _92.quantity) || 1;
|
|
821
|
+
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, products: [Object.assign(Object.assign({}, product), { quantity })], value: product.price * (((_93 = props === null || props === void 0 ? void 0 : props.product) === null || _93 === void 0 ? void 0 : _93.quantity) || 1) });
|
|
981
822
|
if (typeof formatter === 'function') {
|
|
982
823
|
const formattedPayload = formatter(props, payload);
|
|
983
824
|
return this.track('Product Viewed', formattedPayload, options);
|
|
@@ -985,12 +826,12 @@ export class ChordAnalytics {
|
|
|
985
826
|
return this.track('Product Viewed', payload, options);
|
|
986
827
|
});
|
|
987
828
|
this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
988
|
-
var
|
|
989
|
-
const formatter = (
|
|
829
|
+
var _94, _95, _96, _97;
|
|
830
|
+
const formatter = (_96 = (_95 = (_94 = this.options) === null || _94 === void 0 ? void 0 : _94.formatters) === null || _95 === void 0 ? void 0 : _95.events) === null || _96 === void 0 ? void 0 : _96.productsSearched;
|
|
990
831
|
const payload = {
|
|
991
832
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
992
833
|
price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
|
|
993
|
-
product_id: (
|
|
834
|
+
product_id: (_97 = props === null || props === void 0 ? void 0 : props.productId) === null || _97 === void 0 ? void 0 : _97.toString(),
|
|
994
835
|
quantity: props === null || props === void 0 ? void 0 : props.quantity,
|
|
995
836
|
query: props === null || props === void 0 ? void 0 : props.query,
|
|
996
837
|
};
|
|
@@ -1001,8 +842,8 @@ export class ChordAnalytics {
|
|
|
1001
842
|
return this.track('Products Searched', payload, options);
|
|
1002
843
|
});
|
|
1003
844
|
this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1004
|
-
var
|
|
1005
|
-
const formatter = (
|
|
845
|
+
var _98, _99, _100;
|
|
846
|
+
const formatter = (_100 = (_99 = (_98 = this.options) === null || _98 === void 0 ? void 0 : _98.formatters) === null || _99 === void 0 ? void 0 : _99.events) === null || _100 === void 0 ? void 0 : _100.signedIn;
|
|
1006
847
|
const payload = {
|
|
1007
848
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1008
849
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1014,8 +855,8 @@ export class ChordAnalytics {
|
|
|
1014
855
|
return this.track('Signed In', payload, options);
|
|
1015
856
|
});
|
|
1016
857
|
this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1017
|
-
var
|
|
1018
|
-
const formatter = (
|
|
858
|
+
var _101, _102, _103;
|
|
859
|
+
const formatter = (_103 = (_102 = (_101 = this.options) === null || _101 === void 0 ? void 0 : _101.formatters) === null || _102 === void 0 ? void 0 : _102.events) === null || _103 === void 0 ? void 0 : _103.signedOut;
|
|
1019
860
|
const payload = {
|
|
1020
861
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1021
862
|
};
|
|
@@ -1026,8 +867,8 @@ export class ChordAnalytics {
|
|
|
1026
867
|
return this.track('Signed Out', payload, options);
|
|
1027
868
|
});
|
|
1028
869
|
this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1029
|
-
var
|
|
1030
|
-
const formatter = (
|
|
870
|
+
var _104, _105, _106;
|
|
871
|
+
const formatter = (_106 = (_105 = (_104 = this.options) === null || _104 === void 0 ? void 0 : _104.formatters) === null || _105 === void 0 ? void 0 : _105.events) === null || _106 === void 0 ? void 0 : _106.signedUp;
|
|
1031
872
|
const payload = {
|
|
1032
873
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1033
874
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1039,8 +880,8 @@ export class ChordAnalytics {
|
|
|
1039
880
|
return this.track('Signed Up', payload, options);
|
|
1040
881
|
});
|
|
1041
882
|
this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1042
|
-
var
|
|
1043
|
-
const formatter = (
|
|
883
|
+
var _107, _108, _109;
|
|
884
|
+
const formatter = (_109 = (_108 = (_107 = this.options) === null || _107 === void 0 ? void 0 : _107.formatters) === null || _108 === void 0 ? void 0 : _108.events) === null || _109 === void 0 ? void 0 : _109.loginStarted;
|
|
1044
885
|
const payload = {
|
|
1045
886
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1046
887
|
};
|
|
@@ -1051,8 +892,8 @@ export class ChordAnalytics {
|
|
|
1051
892
|
return this.track('Login Started', payload, options);
|
|
1052
893
|
});
|
|
1053
894
|
this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1054
|
-
var
|
|
1055
|
-
const formatter = (
|
|
895
|
+
var _110, _111, _112, _113;
|
|
896
|
+
const formatter = (_112 = (_111 = (_110 = this.options) === null || _110 === void 0 ? void 0 : _110.formatters) === null || _111 === void 0 ? void 0 : _111.events) === null || _112 === void 0 ? void 0 : _112.subscriptionCancelled;
|
|
1056
897
|
const payload = {
|
|
1057
898
|
actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
|
|
1058
899
|
address: props === null || props === void 0 ? void 0 : props.address,
|
|
@@ -1061,7 +902,7 @@ export class ChordAnalytics {
|
|
|
1061
902
|
end_date: props === null || props === void 0 ? void 0 : props.endDate,
|
|
1062
903
|
interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
|
|
1063
904
|
interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
|
|
1064
|
-
products: (
|
|
905
|
+
products: (_113 = props === null || props === void 0 ? void 0 : props.products) === null || _113 === void 0 ? void 0 : _113.map((p, i) => {
|
|
1065
906
|
var _a, _b, _c, _d;
|
|
1066
907
|
return (_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.product) === null || _d === void 0 ? void 0 : _d.call(_c, Object.assign(Object.assign({}, p), { position: i + 1 }));
|
|
1067
908
|
}),
|
|
@@ -1076,8 +917,8 @@ export class ChordAnalytics {
|
|
|
1076
917
|
return this.track('Subscription Cancelled', payload, options);
|
|
1077
918
|
});
|
|
1078
919
|
this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1079
|
-
var
|
|
1080
|
-
const formatter = (
|
|
920
|
+
var _114, _115, _116;
|
|
921
|
+
const formatter = (_116 = (_115 = (_114 = this.options) === null || _114 === void 0 ? void 0 : _114.formatters) === null || _115 === void 0 ? void 0 : _115.events) === null || _116 === void 0 ? void 0 : _116.navigationClicked;
|
|
1081
922
|
const payload = {
|
|
1082
923
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
1083
924
|
label: props === null || props === void 0 ? void 0 : props.label,
|
|
@@ -1092,15 +933,15 @@ export class ChordAnalytics {
|
|
|
1092
933
|
return this.track('Navigation Clicked', payload, options);
|
|
1093
934
|
});
|
|
1094
935
|
this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1095
|
-
var
|
|
1096
|
-
const formatter = (
|
|
936
|
+
var _117, _118, _119, _120;
|
|
937
|
+
const formatter = (_119 = (_118 = (_117 = this.options) === null || _117 === void 0 ? void 0 : _117.formatters) === null || _118 === void 0 ? void 0 : _118.events) === null || _119 === void 0 ? void 0 : _119.paymentInfoEntered;
|
|
1097
938
|
const payload = {
|
|
1098
939
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
1099
940
|
coupon: props === null || props === void 0 ? void 0 : props.coupon,
|
|
1100
941
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
1101
942
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1102
943
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
1103
|
-
products: (
|
|
944
|
+
products: (_120 = props === null || props === void 0 ? void 0 : props.products) === null || _120 === void 0 ? void 0 : _120.map((p, i) => {
|
|
1104
945
|
var _a, _b, _c, _d;
|
|
1105
946
|
return (_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.product) === null || _d === void 0 ? void 0 : _d.call(_c, Object.assign(Object.assign({}, p), { position: i + 1 }));
|
|
1106
947
|
}),
|
|
@@ -1115,8 +956,8 @@ export class ChordAnalytics {
|
|
|
1115
956
|
return this.track('Payment Info Entered', payload, options);
|
|
1116
957
|
});
|
|
1117
958
|
this.trackOrderCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1118
|
-
var
|
|
1119
|
-
const formatter = (
|
|
959
|
+
var _121, _122, _123, _124;
|
|
960
|
+
const formatter = (_123 = (_122 = (_121 = this.options) === null || _121 === void 0 ? void 0 : _121.formatters) === null || _122 === void 0 ? void 0 : _122.events) === null || _123 === void 0 ? void 0 : _123.orderCompleted;
|
|
1120
961
|
const payload = {
|
|
1121
962
|
affiliation: props === null || props === void 0 ? void 0 : props.affiliation,
|
|
1122
963
|
campaign_id: props === null || props === void 0 ? void 0 : props.campaignId,
|
|
@@ -1136,7 +977,7 @@ export class ChordAnalytics {
|
|
|
1136
977
|
order_date: props === null || props === void 0 ? void 0 : props.orderDate,
|
|
1137
978
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1138
979
|
phone: props === null || props === void 0 ? void 0 : props.phone,
|
|
1139
|
-
products: (
|
|
980
|
+
products: (_124 = props === null || props === void 0 ? void 0 : props.products) === null || _124 === void 0 ? void 0 : _124.map((p, i) => {
|
|
1140
981
|
var _a;
|
|
1141
982
|
return ({
|
|
1142
983
|
affiliation: p === null || p === void 0 ? void 0 : p.affiliation,
|
|
@@ -1202,8 +1043,6 @@ export class ChordAnalytics {
|
|
|
1202
1043
|
const consentManager = addCdpConsent(this.options);
|
|
1203
1044
|
this.consentConfig = consentManager.getConsentConfig() || null;
|
|
1204
1045
|
}
|
|
1205
|
-
// Restore any pending events from sessionStorage (survives instance recreation)
|
|
1206
|
-
this.restoreQueueFromStorage();
|
|
1207
1046
|
if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.cdpDomain) && ((_c = this.options) === null || _c === void 0 ? void 0 : _c.cdpWriteKey) && window) {
|
|
1208
1047
|
window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
|
|
1209
1048
|
this.initializeCdp();
|