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