@chordcommerce/analytics 1.12.0 → 1.12.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.
@@ -21,9 +21,21 @@ export const addCdpSnippet = (options) => __awaiter(void 0, void 0, void 0, func
21
21
  s.setAttribute('data-init-only', 'true');
22
22
  s.setAttribute('data-namespace', `_${options.namespace}`);
23
23
  s.setAttribute('data-write-key', options.cdpWriteKey);
24
- if (options.consent)
25
- yield addCdpConsent(options).init();
26
- document.head.appendChild(s);
24
+ if (options.consent) {
25
+ // If awaitConsent is true, wait for consent before loading CDP
26
+ if (options.awaitConsent) {
27
+ yield addCdpConsent(options).init();
28
+ document.head.appendChild(s);
29
+ }
30
+ else {
31
+ document.head.appendChild(s);
32
+ // If not awaiting consent, initialize in the background
33
+ addCdpConsent(options).init().catch(console.error);
34
+ }
35
+ }
36
+ else {
37
+ document.head.appendChild(s);
38
+ }
27
39
  });
28
40
  /*
29
41
  * Returns the CDP queue to hold events ahead of CDP initialization.
@@ -11,7 +11,9 @@ import { ketchConsentAdapter } from './ketch.js';
11
11
  import { onetrustConsentAdapter } from './onetrust.js';
12
12
  import { shopifyConsentAdapter } from './shopify.js';
13
13
  export const addCdpConsent = (options) => {
14
- let adapter;
14
+ let adapter = null;
15
+ const POLLING_INTERVAL_MS = 50;
16
+ const TIMEOUT_MS = 60000;
15
17
  /**
16
18
  * Returns the adapter for the specified consent management platform.
17
19
  */
@@ -29,16 +31,26 @@ export const addCdpConsent = (options) => {
29
31
  }
30
32
  };
31
33
  /**
32
- * Returns whether the CDP should be loaded based on the current consent.
34
+ * Polls if user can be tracked based on consent
35
+ * @returns Promise that resolves to true if condition is met within timeout, false otherwise
33
36
  */
34
- const shouldLoadCdp = () => __awaiter(void 0, void 0, void 0, function* () {
37
+ const checkUserCanBeTracked = () => __awaiter(void 0, void 0, void 0, function* () {
35
38
  return new Promise((resolve) => {
39
+ // Checking immediately first
40
+ if (adapter === null || adapter === void 0 ? void 0 : adapter.userCanBeTracked()) {
41
+ resolve(true);
42
+ return;
43
+ }
36
44
  const interval = setInterval(() => {
37
45
  if (adapter === null || adapter === void 0 ? void 0 : adapter.userCanBeTracked()) {
38
46
  clearInterval(interval);
39
47
  resolve(true);
40
48
  }
41
- }, 500);
49
+ }, POLLING_INTERVAL_MS);
50
+ setTimeout(() => {
51
+ clearInterval(interval);
52
+ resolve(false);
53
+ }, TIMEOUT_MS);
42
54
  });
43
55
  });
44
56
  /**
@@ -55,16 +67,40 @@ export const addCdpConsent = (options) => {
55
67
  }
56
68
  };
57
69
  /**
58
- * Adds consent management by setting defaults and handling changes.
70
+ * Sets up consent management by initializing the adapter and handling consent updates.
71
+ */
72
+ const setupConsentManagement = () => __awaiter(void 0, void 0, void 0, function* () {
73
+ if (!adapter)
74
+ return;
75
+ const isReady = yield checkUserCanBeTracked();
76
+ if (!isReady)
77
+ return;
78
+ const initialConsent = adapter.getCurrentConsent();
79
+ updateCdpConsent(initialConsent);
80
+ adapter.handleConsentUpdates((updatedConsent) => {
81
+ updateCdpConsent(updatedConsent);
82
+ });
83
+ });
84
+ /**
85
+ * Initializes consent management.
86
+ * Returns a promise that resolves to true if CDP should be loaded, false otherwise.
59
87
  */
60
88
  const init = () => __awaiter(void 0, void 0, void 0, function* () {
61
89
  adapter = getAdapter();
62
- if (adapter === null)
63
- return Promise.resolve(false);
64
- yield shouldLoadCdp();
65
- updateCdpConsent(adapter === null || adapter === void 0 ? void 0 : adapter.getCurrentConsent());
66
- adapter === null || adapter === void 0 ? void 0 : adapter.handleConsentUpdates(updateCdpConsent);
67
- return Promise.resolve(true);
90
+ if (adapter === null) {
91
+ console.error(`Consent management adapter "${options.consent}" is not supported.`);
92
+ return false;
93
+ }
94
+ if (options.awaitConsent) {
95
+ const canBeTracked = yield checkUserCanBeTracked();
96
+ if (!canBeTracked)
97
+ return false;
98
+ }
99
+ // Set up consent management in the background
100
+ setupConsentManagement().catch((error) => {
101
+ console.error('Error setting up consent management:', error);
102
+ });
103
+ return true;
68
104
  });
69
105
  return {
70
106
  init,
@@ -7,7 +7,7 @@ const getApi = () => window.ketch && window.ketchConsent;
7
7
  */
8
8
  const userCanBeTracked = () => {
9
9
  const api = getApi();
10
- return api && !!Object.keys(api).length;
10
+ return !!api && !!Object.keys(api).length;
11
11
  };
12
12
  /**
13
13
  * Returns the user's current consent configuration.
@@ -22,6 +22,11 @@ export declare class ChordAnalytics<T extends ObjectTypes = ObjectTypes> {
22
22
  */
23
23
  options: ChordAnalyticsOptions<T>;
24
24
  constructor(options: ChordAnalyticsOptions<T>);
25
+ /**
26
+ * Set debug mode for Chord Analytics
27
+ * @param enabled - Whether debug mode should be enabled
28
+ */
29
+ setDebugMode: (enabled: boolean) => void;
25
30
  cdp: () => AnyAnalytics;
26
31
  ccdp: () => AnyAnalytics;
27
32
  logger: (message?: any, ...optionalParams: any[]) => void;
@@ -10,9 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { addCdpSnippet, cdpQueue } from './cdp.js';
11
11
  import { eventSchemas } from '../validators/index.js';
12
12
  import { pruneNullValues } from '../utils.js';
13
+ const DEBUG_MODE_STORAGE_KEY = 'chordcommerce/analytics/debug';
13
14
  export class ChordAnalytics {
14
15
  constructor(options) {
15
- var _a, _b;
16
+ var _a, _b, _c;
16
17
  /**
17
18
  * Allows snippet.js to detect whether this library has been initialized yet.
18
19
  */
@@ -21,6 +22,16 @@ export class ChordAnalytics {
21
22
  * Allows snippet.js to detect whether the snippet has started running yet.
22
23
  */
23
24
  this.invoked = true;
25
+ /**
26
+ * Set debug mode for Chord Analytics
27
+ * @param enabled - Whether debug mode should be enabled
28
+ */
29
+ // eslint-disable-next-line class-methods-use-this
30
+ this.setDebugMode = (enabled) => {
31
+ if (window === null || window === void 0 ? void 0 : window.localStorage) {
32
+ window.localStorage.setItem(DEBUG_MODE_STORAGE_KEY, enabled.toString());
33
+ }
34
+ };
24
35
  /*
25
36
  * Return the CDP instance provided in `options.cdp`.
26
37
  */
@@ -94,18 +105,35 @@ export class ChordAnalytics {
94
105
  });
95
106
  }
96
107
  return new Promise((resolve) => {
108
+ const cdpPromises = [];
97
109
  try {
98
- const a = this.cdp();
110
+ const a = this.ccdp();
99
111
  if (a && typeof a.track === 'function') {
100
- a.track(event, finalEventProps, options, () => resolve());
112
+ cdpPromises.push(new Promise((cdpResolve) => {
113
+ a.track(event, finalEventProps, options, () => cdpResolve());
114
+ }));
101
115
  }
102
- const b = this.ccdp();
116
+ const b = this.cdp();
103
117
  if (b && typeof b.track === 'function') {
104
- b.track(event, finalEventProps, options, () => resolve());
118
+ cdpPromises.push(new Promise((cdpResolve) => {
119
+ b.track(event, finalEventProps, options, () => cdpResolve());
120
+ }));
121
+ }
122
+ if (cdpPromises.length > 0) {
123
+ Promise.allSettled(cdpPromises)
124
+ .then(() => resolve())
125
+ .catch((error) => {
126
+ this.logger(error);
127
+ resolve();
128
+ });
129
+ }
130
+ else {
131
+ resolve();
105
132
  }
106
133
  }
107
134
  catch (error) {
108
135
  this.logger(error);
136
+ resolve();
109
137
  }
110
138
  });
111
139
  };
@@ -114,14 +142,23 @@ export class ChordAnalytics {
114
142
  */
115
143
  this.identify = (...props) => {
116
144
  try {
117
- const a = this.cdp();
145
+ const identifyPromises = [];
146
+ const a = this.ccdp();
118
147
  if (a && typeof a.identify === 'function') {
119
- a.identify(...props);
148
+ identifyPromises.push(new Promise((resolve) => {
149
+ a.identify(...props, () => resolve());
150
+ }));
120
151
  }
121
- const b = this.ccdp();
152
+ const b = this.cdp();
122
153
  if (b && typeof b.identify === 'function') {
123
- b.identify(...props);
154
+ identifyPromises.push(new Promise((resolve) => {
155
+ b.identify(...props, () => resolve());
156
+ }));
124
157
  }
158
+ // We don't return the promise to maintain the void return type
159
+ Promise.allSettled(identifyPromises).then((results) => {
160
+ this.logger('identify event sent', results);
161
+ });
125
162
  }
126
163
  catch (error) {
127
164
  this.logger(error);
@@ -132,14 +169,23 @@ export class ChordAnalytics {
132
169
  */
133
170
  this.page = () => {
134
171
  try {
135
- const a = this.cdp();
172
+ const pagePromises = [];
173
+ const a = this.ccdp();
136
174
  if (a && typeof a.page === 'function') {
137
- a.page({ meta: this.meta() });
175
+ pagePromises.push(new Promise((resolve) => {
176
+ a.page({ meta: this.meta() }, () => resolve());
177
+ }));
138
178
  }
139
- const b = this.ccdp();
179
+ const b = this.cdp();
140
180
  if (b && typeof b.page === 'function') {
141
- b.page({ meta: this.meta() });
181
+ pagePromises.push(new Promise((resolve) => {
182
+ b.page({ meta: this.meta() }, () => resolve());
183
+ }));
142
184
  }
185
+ // We don't return the promise to maintain the void return type
186
+ Promise.allSettled(pagePromises).then((results) => {
187
+ this.logger('page event sent', results);
188
+ });
143
189
  }
144
190
  catch (error) {
145
191
  this.logger(error);
@@ -147,14 +193,21 @@ export class ChordAnalytics {
147
193
  };
148
194
  this.reset = () => {
149
195
  try {
150
- const a = this.cdp();
196
+ const resetPromises = [];
197
+ const a = this.ccdp();
151
198
  if (a && typeof a.reset === 'function') {
152
- a.reset();
199
+ resetPromises.push(new Promise((resolve) => {
200
+ a.reset(() => resolve());
201
+ }));
153
202
  }
154
- const b = this.ccdp();
203
+ const b = this.cdp();
155
204
  if (b && typeof b.reset === 'function') {
156
- b.reset();
205
+ resetPromises.push(new Promise((resolve) => {
206
+ b.reset(() => resolve());
207
+ }));
157
208
  }
209
+ // We don't return the promise to maintain the return type
210
+ Promise.allSettled(resetPromises).catch(this.logger);
158
211
  }
159
212
  catch (error) {
160
213
  this.logger(error);
@@ -162,8 +215,8 @@ export class ChordAnalytics {
162
215
  };
163
216
  // TODO: Add support for props.products
164
217
  this.trackCartViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
165
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
166
- const cart = (_f = (_e = (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.formatters) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.cart) === null || _f === void 0 ? void 0 : _f.call(_e, {
218
+ var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
219
+ const cart = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.cart) === null || _g === void 0 ? void 0 : _g.call(_f, {
167
220
  cart: props === null || props === void 0 ? void 0 : props.cart,
168
221
  });
169
222
  const payload = {
@@ -172,17 +225,17 @@ export class ChordAnalytics {
172
225
  products: cart === null || cart === void 0 ? void 0 : cart.products,
173
226
  value: cart === null || cart === void 0 ? void 0 : cart.value,
174
227
  };
175
- if ((_j = (_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.formatters) === null || _h === void 0 ? void 0 : _h.events) === null || _j === void 0 ? void 0 : _j.cartViewed) {
176
- const formattedPayload = (_m = (_l = (_k = this.options) === null || _k === void 0 ? void 0 : _k.formatters) === null || _l === void 0 ? void 0 : _l.events) === null || _m === void 0 ? void 0 : _m.cartViewed(props, payload);
228
+ if ((_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.events) === null || _k === void 0 ? void 0 : _k.cartViewed) {
229
+ const formattedPayload = (_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(props, payload);
177
230
  return this.track('Cart Viewed', formattedPayload, options);
178
231
  }
179
232
  return this.track('Cart Viewed', payload, options);
180
233
  });
181
234
  // TODO: Add support for props.products
182
235
  this.trackCheckoutStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
183
- var _o, _p, _q, _r, _s, _t, _u;
184
- const formatter = (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.formatters) === null || _p === void 0 ? void 0 : _p.events) === null || _q === void 0 ? void 0 : _q.checkoutStarted;
185
- const checkout = (_u = (_t = (_s = (_r = this.options) === null || _r === void 0 ? void 0 : _r.formatters) === null || _s === void 0 ? void 0 : _s.objects) === null || _t === void 0 ? void 0 : _t.checkout) === null || _u === void 0 ? void 0 : _u.call(_t, {
236
+ var _p, _q, _r, _s, _t, _u, _v;
237
+ const formatter = (_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.checkoutStarted;
238
+ const checkout = (_v = (_u = (_t = (_s = this.options) === null || _s === void 0 ? void 0 : _s.formatters) === null || _t === void 0 ? void 0 : _t.objects) === null || _u === void 0 ? void 0 : _u.checkout) === null || _v === void 0 ? void 0 : _v.call(_u, {
186
239
  checkout: props === null || props === void 0 ? void 0 : props.checkout,
187
240
  });
188
241
  const payload = checkout;
@@ -193,8 +246,8 @@ export class ChordAnalytics {
193
246
  return this.track('Checkout Started', payload, options);
194
247
  });
195
248
  this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
196
- var _v, _w, _x;
197
- const formatter = (_x = (_w = (_v = this.options) === null || _v === void 0 ? void 0 : _v.formatters) === null || _w === void 0 ? void 0 : _w.events) === null || _x === void 0 ? void 0 : _x.checkoutStepCompleted;
249
+ var _w, _x, _y;
250
+ const formatter = (_y = (_x = (_w = this.options) === null || _w === void 0 ? void 0 : _w.formatters) === null || _x === void 0 ? void 0 : _x.events) === null || _y === void 0 ? void 0 : _y.checkoutStepCompleted;
198
251
  const payload = {
199
252
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
200
253
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
@@ -208,8 +261,8 @@ export class ChordAnalytics {
208
261
  return this.track('Checkout Step Completed', payload, options);
209
262
  });
210
263
  this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
211
- var _y, _z, _0;
212
- const formatter = (_0 = (_z = (_y = this.options) === null || _y === void 0 ? void 0 : _y.formatters) === null || _z === void 0 ? void 0 : _z.events) === null || _0 === void 0 ? void 0 : _0.checkoutStepViewed;
264
+ var _z, _0, _1;
265
+ 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.checkoutStepViewed;
213
266
  const payload = {
214
267
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
215
268
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
@@ -223,8 +276,8 @@ export class ChordAnalytics {
223
276
  return this.track('Checkout Step Viewed', payload, options);
224
277
  });
225
278
  this.trackCouponApplied = (props, options) => __awaiter(this, void 0, void 0, function* () {
226
- var _1, _2, _3;
227
- const formatter = (_3 = (_2 = (_1 = this.options) === null || _1 === void 0 ? void 0 : _1.formatters) === null || _2 === void 0 ? void 0 : _2.events) === null || _3 === void 0 ? void 0 : _3.couponApplied;
279
+ var _2, _3, _4;
280
+ 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.couponApplied;
228
281
  const payload = {
229
282
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
230
283
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -239,8 +292,8 @@ export class ChordAnalytics {
239
292
  return this.track('Coupon Applied', payload, options);
240
293
  });
241
294
  this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
242
- var _4, _5, _6;
243
- const formatter = (_6 = (_5 = (_4 = this.options) === null || _4 === void 0 ? void 0 : _4.formatters) === null || _5 === void 0 ? void 0 : _5.events) === null || _6 === void 0 ? void 0 : _6.couponDenied;
295
+ var _5, _6, _7;
296
+ 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.couponDenied;
244
297
  const payload = {
245
298
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
246
299
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -255,8 +308,8 @@ export class ChordAnalytics {
255
308
  return this.track('Coupon Denied', payload, options);
256
309
  });
257
310
  this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
258
- var _7, _8, _9;
259
- const formatter = (_9 = (_8 = (_7 = this.options) === null || _7 === void 0 ? void 0 : _7.formatters) === null || _8 === void 0 ? void 0 : _8.events) === null || _9 === void 0 ? void 0 : _9.couponEntered;
311
+ var _8, _9, _10;
312
+ 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.couponEntered;
260
313
  const payload = {
261
314
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
262
315
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -270,8 +323,8 @@ export class ChordAnalytics {
270
323
  return this.track('Coupon Entered', payload, options);
271
324
  });
272
325
  this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
273
- var _10, _11, _12;
274
- const formatter = (_12 = (_11 = (_10 = this.options) === null || _10 === void 0 ? void 0 : _10.formatters) === null || _11 === void 0 ? void 0 : _11.events) === null || _12 === void 0 ? void 0 : _12.couponRemoved;
326
+ var _11, _12, _13;
327
+ 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.couponRemoved;
275
328
  const payload = {
276
329
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
277
330
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -286,8 +339,8 @@ export class ChordAnalytics {
286
339
  return this.track('Coupon Removed', payload, options);
287
340
  });
288
341
  this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
289
- var _13, _14, _15;
290
- const formatter = (_15 = (_14 = (_13 = this.options) === null || _13 === void 0 ? void 0 : _13.formatters) === null || _14 === void 0 ? void 0 : _14.events) === null || _15 === void 0 ? void 0 : _15.emailCaptured;
342
+ var _14, _15, _16;
343
+ 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.emailCaptured;
291
344
  const payload = {
292
345
  email: props === null || props === void 0 ? void 0 : props.email,
293
346
  placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
@@ -300,13 +353,13 @@ export class ChordAnalytics {
300
353
  return this.track('Email Captured', payload, options);
301
354
  });
302
355
  this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
303
- var _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
304
- const formatter = (_18 = (_17 = (_16 = this.options) === null || _16 === void 0 ? void 0 : _16.formatters) === null || _17 === void 0 ? void 0 : _17.events) === null || _18 === void 0 ? void 0 : _18.productAdded;
305
- const product = (_22 = (_21 = (_20 = (_19 = this.options) === null || _19 === void 0 ? void 0 : _19.formatters) === null || _20 === void 0 ? void 0 : _20.objects) === null || _21 === void 0 ? void 0 : _21.product) === null || _22 === void 0 ? void 0 : _22.call(_21, props === null || props === void 0 ? void 0 : props.product);
306
- const cart = (_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.cart) === null || _26 === void 0 ? void 0 : _26.call(_25, {
356
+ var _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28;
357
+ 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.productAdded;
358
+ const product = (_23 = (_22 = (_21 = (_20 = this.options) === null || _20 === void 0 ? void 0 : _20.formatters) === null || _21 === void 0 ? void 0 : _21.objects) === null || _22 === void 0 ? void 0 : _22.product) === null || _23 === void 0 ? void 0 : _23.call(_22, props === null || props === void 0 ? void 0 : props.product);
359
+ const cart = (_27 = (_26 = (_25 = (_24 = this.options) === null || _24 === void 0 ? void 0 : _24.formatters) === null || _25 === void 0 ? void 0 : _25.objects) === null || _26 === void 0 ? void 0 : _26.cart) === null || _27 === void 0 ? void 0 : _27.call(_26, {
307
360
  cart: props === null || props === void 0 ? void 0 : props.cart,
308
361
  });
309
- const quantity = ((_27 = props === null || props === void 0 ? void 0 : props.product) === null || _27 === void 0 ? void 0 : _27.quantity) || 1;
362
+ const quantity = ((_28 = props === null || props === void 0 ? void 0 : props.product) === null || _28 === void 0 ? void 0 : _28.quantity) || 1;
310
363
  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) });
311
364
  if (typeof formatter === 'function') {
312
365
  const formattedPayload = formatter(props, payload);
@@ -315,14 +368,14 @@ export class ChordAnalytics {
315
368
  return this.track('Product Added', payload, options);
316
369
  });
317
370
  this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
318
- var _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40;
319
- const formatter = (_30 = (_29 = (_28 = this.options) === null || _28 === void 0 ? void 0 : _28.formatters) === null || _29 === void 0 ? void 0 : _29.events) === null || _30 === void 0 ? void 0 : _30.productClicked;
320
- const product = (_34 = (_33 = (_32 = (_31 = this.options) === null || _31 === void 0 ? void 0 : _31.formatters) === null || _32 === void 0 ? void 0 : _32.objects) === null || _33 === void 0 ? void 0 : _33.product) === null || _34 === void 0 ? void 0 : _34.call(_33, props === null || props === void 0 ? void 0 : props.product);
321
- const cart = (_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.cart) === null || _38 === void 0 ? void 0 : _38.call(_37, {
371
+ var _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41;
372
+ const formatter = (_31 = (_30 = (_29 = this.options) === null || _29 === void 0 ? void 0 : _29.formatters) === null || _30 === void 0 ? void 0 : _30.events) === null || _31 === void 0 ? void 0 : _31.productClicked;
373
+ const product = (_35 = (_34 = (_33 = (_32 = this.options) === null || _32 === void 0 ? void 0 : _32.formatters) === null || _33 === void 0 ? void 0 : _33.objects) === null || _34 === void 0 ? void 0 : _34.product) === null || _35 === void 0 ? void 0 : _35.call(_34, props === null || props === void 0 ? void 0 : props.product);
374
+ const cart = (_39 = (_38 = (_37 = (_36 = this.options) === null || _36 === void 0 ? void 0 : _36.formatters) === null || _37 === void 0 ? void 0 : _37.objects) === null || _38 === void 0 ? void 0 : _38.cart) === null || _39 === void 0 ? void 0 : _39.call(_38, {
322
375
  cart: props === null || props === void 0 ? void 0 : props.cart,
323
376
  });
324
- const quantity = ((_39 = props === null || props === void 0 ? void 0 : props.product) === null || _39 === void 0 ? void 0 : _39.quantity) || 1;
325
- const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_40 = props === null || props === void 0 ? void 0 : props.listId) === null || _40 === void 0 ? void 0 : _40.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
377
+ const quantity = ((_40 = props === null || props === void 0 ? void 0 : props.product) === null || _40 === void 0 ? void 0 : _40.quantity) || 1;
378
+ const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_41 = props === null || props === void 0 ? void 0 : props.listId) === null || _41 === void 0 ? void 0 : _41.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
326
379
  if (typeof formatter === 'function') {
327
380
  const formattedPayload = formatter(props, payload);
328
381
  return this.track('Product Clicked', formattedPayload, options);
@@ -330,13 +383,13 @@ export class ChordAnalytics {
330
383
  return this.track('Product Clicked', payload, options);
331
384
  });
332
385
  this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
333
- var _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52;
334
- const formatter = (_43 = (_42 = (_41 = this.options) === null || _41 === void 0 ? void 0 : _41.formatters) === null || _42 === void 0 ? void 0 : _42.events) === null || _43 === void 0 ? void 0 : _43.variantClicked;
335
- const product = (_47 = (_46 = (_45 = (_44 = this.options) === null || _44 === void 0 ? void 0 : _44.formatters) === null || _45 === void 0 ? void 0 : _45.objects) === null || _46 === void 0 ? void 0 : _46.product) === null || _47 === void 0 ? void 0 : _47.call(_46, props === null || props === void 0 ? void 0 : props.product);
336
- const cart = (_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.cart) === null || _51 === void 0 ? void 0 : _51.call(_50, {
386
+ var _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53;
387
+ const formatter = (_44 = (_43 = (_42 = this.options) === null || _42 === void 0 ? void 0 : _42.formatters) === null || _43 === void 0 ? void 0 : _43.events) === null || _44 === void 0 ? void 0 : _44.variantClicked;
388
+ const product = (_48 = (_47 = (_46 = (_45 = this.options) === null || _45 === void 0 ? void 0 : _45.formatters) === null || _46 === void 0 ? void 0 : _46.objects) === null || _47 === void 0 ? void 0 : _47.product) === null || _48 === void 0 ? void 0 : _48.call(_47, props === null || props === void 0 ? void 0 : props.product);
389
+ const cart = (_52 = (_51 = (_50 = (_49 = this.options) === null || _49 === void 0 ? void 0 : _49.formatters) === null || _50 === void 0 ? void 0 : _50.objects) === null || _51 === void 0 ? void 0 : _51.cart) === null || _52 === void 0 ? void 0 : _52.call(_51, {
337
390
  cart: props === null || props === void 0 ? void 0 : props.cart,
338
391
  });
339
- const quantity = ((_52 = props === null || props === void 0 ? void 0 : props.product) === null || _52 === void 0 ? void 0 : _52.quantity) || 1;
392
+ const quantity = ((_53 = props === null || props === void 0 ? void 0 : props.product) === null || _53 === void 0 ? void 0 : _53.quantity) || 1;
340
393
  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 });
341
394
  if (typeof formatter === 'function') {
342
395
  const formattedPayload = formatter(props, payload);
@@ -345,13 +398,13 @@ export class ChordAnalytics {
345
398
  return this.track('Variant Clicked', payload, options);
346
399
  });
347
400
  this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
348
- var _53, _54, _55, _56, _57;
349
- const formatter = (_55 = (_54 = (_53 = this.options) === null || _53 === void 0 ? void 0 : _53.formatters) === null || _54 === void 0 ? void 0 : _54.events) === null || _55 === void 0 ? void 0 : _55.productListFiltered;
401
+ var _54, _55, _56, _57, _58;
402
+ const formatter = (_56 = (_55 = (_54 = this.options) === null || _54 === void 0 ? void 0 : _54.formatters) === null || _55 === void 0 ? void 0 : _55.events) === null || _56 === void 0 ? void 0 : _56.productListFiltered;
350
403
  const payload = {
351
404
  category: props === null || props === void 0 ? void 0 : props.category,
352
405
  filters: props === null || props === void 0 ? void 0 : props.filters,
353
- list_id: (_56 = props === null || props === void 0 ? void 0 : props.listId) === null || _56 === void 0 ? void 0 : _56.toString(),
354
- item_list_id: (_57 = props === null || props === void 0 ? void 0 : props.listId) === null || _57 === void 0 ? void 0 : _57.toString(),
406
+ list_id: (_57 = props === null || props === void 0 ? void 0 : props.listId) === null || _57 === void 0 ? void 0 : _57.toString(),
407
+ item_list_id: (_58 = props === null || props === void 0 ? void 0 : props.listId) === null || _58 === void 0 ? void 0 : _58.toString(),
355
408
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
356
409
  sorts: props === null || props === void 0 ? void 0 : props.sorts,
357
410
  };
@@ -362,14 +415,14 @@ export class ChordAnalytics {
362
415
  return this.track('Product List Filtered', payload, options);
363
416
  });
364
417
  this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
365
- var _58, _59, _60, _61, _62, _63;
366
- const formatter = (_60 = (_59 = (_58 = this.options) === null || _58 === void 0 ? void 0 : _58.formatters) === null || _59 === void 0 ? void 0 : _59.events) === null || _60 === void 0 ? void 0 : _60.productListViewed;
418
+ var _59, _60, _61, _62, _63, _64;
419
+ const formatter = (_61 = (_60 = (_59 = this.options) === null || _59 === void 0 ? void 0 : _59.formatters) === null || _60 === void 0 ? void 0 : _60.events) === null || _61 === void 0 ? void 0 : _61.productListViewed;
367
420
  const payload = {
368
421
  category: props === null || props === void 0 ? void 0 : props.category,
369
- list_id: (_61 = props === null || props === void 0 ? void 0 : props.listId) === null || _61 === void 0 ? void 0 : _61.toString(),
370
- item_list_id: (_62 = props === null || props === void 0 ? void 0 : props.listId) === null || _62 === void 0 ? void 0 : _62.toString(),
422
+ list_id: (_62 = props === null || props === void 0 ? void 0 : props.listId) === null || _62 === void 0 ? void 0 : _62.toString(),
423
+ item_list_id: (_63 = props === null || props === void 0 ? void 0 : props.listId) === null || _63 === void 0 ? void 0 : _63.toString(),
371
424
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
372
- products: (_63 = props === null || props === void 0 ? void 0 : props.products) === null || _63 === void 0 ? void 0 : _63.map((p, i) => {
425
+ products: (_64 = props === null || props === void 0 ? void 0 : props.products) === null || _64 === void 0 ? void 0 : _64.map((p, i) => {
373
426
  var _a, _b, _c, _d;
374
427
  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 }));
375
428
  }),
@@ -382,8 +435,8 @@ export class ChordAnalytics {
382
435
  return this.track('Product List Viewed', payload, options);
383
436
  });
384
437
  this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
385
- var _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78;
386
- const formatter = (_66 = (_65 = (_64 = this.options) === null || _64 === void 0 ? void 0 : _64.formatters) === null || _65 === void 0 ? void 0 : _65.events) === null || _66 === void 0 ? void 0 : _66.productRemoved;
438
+ var _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79;
439
+ const formatter = (_67 = (_66 = (_65 = this.options) === null || _65 === void 0 ? void 0 : _65.formatters) === null || _66 === void 0 ? void 0 : _66.events) === null || _67 === void 0 ? void 0 : _67.productRemoved;
387
440
  /*
388
441
  const product = this.options?.formatters?.objects?.product?.({
389
442
  position: props?.position,
@@ -392,13 +445,13 @@ export class ChordAnalytics {
392
445
  variantId: props?.variantId,
393
446
  })
394
447
  */
395
- const lineItem = (_70 = (_69 = (_68 = (_67 = this.options) === null || _67 === void 0 ? void 0 : _67.formatters) === null || _68 === void 0 ? void 0 : _68.objects) === null || _69 === void 0 ? void 0 : _69.lineItem) === null || _70 === void 0 ? void 0 : _70.call(_69, {
448
+ const lineItem = (_71 = (_70 = (_69 = (_68 = this.options) === null || _68 === void 0 ? void 0 : _68.formatters) === null || _69 === void 0 ? void 0 : _69.objects) === null || _70 === void 0 ? void 0 : _70.lineItem) === null || _71 === void 0 ? void 0 : _71.call(_70, {
396
449
  lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
397
450
  });
398
- const cart = (_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.cart) === null || _74 === void 0 ? void 0 : _74.call(_73, {
451
+ const cart = (_75 = (_74 = (_73 = (_72 = this.options) === null || _72 === void 0 ? void 0 : _72.formatters) === null || _73 === void 0 ? void 0 : _73.objects) === null || _74 === void 0 ? void 0 : _74.cart) === null || _75 === void 0 ? void 0 : _75.call(_74, {
399
452
  cart: props === null || props === void 0 ? void 0 : props.cart,
400
453
  });
401
- const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_75 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _75 !== void 0 ? _75 : 0) * ((_76 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _76 !== void 0 ? _76 : 1), value: ((_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) });
454
+ const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_76 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _76 !== void 0 ? _76 : 0) * ((_77 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _77 !== void 0 ? _77 : 1), value: ((_78 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _78 !== void 0 ? _78 : 0) * ((_79 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _79 !== void 0 ? _79 : 1) });
402
455
  if (typeof formatter === 'function') {
403
456
  const formattedPayload = formatter(props, payload);
404
457
  return this.track('Product Removed', formattedPayload, options);
@@ -406,14 +459,14 @@ export class ChordAnalytics {
406
459
  return this.track('Product Removed', payload, options);
407
460
  });
408
461
  this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
409
- var _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91;
410
- const formatter = (_81 = (_80 = (_79 = this.options) === null || _79 === void 0 ? void 0 : _79.formatters) === null || _80 === void 0 ? void 0 : _80.events) === null || _81 === void 0 ? void 0 : _81.productViewed;
411
- const product = (_85 = (_84 = (_83 = (_82 = this.options) === null || _82 === void 0 ? void 0 : _82.formatters) === null || _83 === void 0 ? void 0 : _83.objects) === null || _84 === void 0 ? void 0 : _84.product) === null || _85 === void 0 ? void 0 : _85.call(_84, props === null || props === void 0 ? void 0 : props.product);
412
- const cart = (_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.cart) === null || _89 === void 0 ? void 0 : _89.call(_88, {
462
+ var _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92;
463
+ const formatter = (_82 = (_81 = (_80 = this.options) === null || _80 === void 0 ? void 0 : _80.formatters) === null || _81 === void 0 ? void 0 : _81.events) === null || _82 === void 0 ? void 0 : _82.productViewed;
464
+ const product = (_86 = (_85 = (_84 = (_83 = this.options) === null || _83 === void 0 ? void 0 : _83.formatters) === null || _84 === void 0 ? void 0 : _84.objects) === null || _85 === void 0 ? void 0 : _85.product) === null || _86 === void 0 ? void 0 : _86.call(_85, props === null || props === void 0 ? void 0 : props.product);
465
+ const cart = (_90 = (_89 = (_88 = (_87 = this.options) === null || _87 === void 0 ? void 0 : _87.formatters) === null || _88 === void 0 ? void 0 : _88.objects) === null || _89 === void 0 ? void 0 : _89.cart) === null || _90 === void 0 ? void 0 : _90.call(_89, {
413
466
  cart: props === null || props === void 0 ? void 0 : props.cart,
414
467
  });
415
- const quantity = ((_90 = props === null || props === void 0 ? void 0 : props.product) === null || _90 === void 0 ? void 0 : _90.quantity) || 1;
416
- 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 * (((_91 = props === null || props === void 0 ? void 0 : props.product) === null || _91 === void 0 ? void 0 : _91.quantity) || 1) });
468
+ const quantity = ((_91 = props === null || props === void 0 ? void 0 : props.product) === null || _91 === void 0 ? void 0 : _91.quantity) || 1;
469
+ 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 * (((_92 = props === null || props === void 0 ? void 0 : props.product) === null || _92 === void 0 ? void 0 : _92.quantity) || 1) });
417
470
  if (typeof formatter === 'function') {
418
471
  const formattedPayload = formatter(props, payload);
419
472
  return this.track('Product Viewed', formattedPayload, options);
@@ -421,12 +474,12 @@ export class ChordAnalytics {
421
474
  return this.track('Product Viewed', payload, options);
422
475
  });
423
476
  this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
424
- var _92, _93, _94, _95;
425
- const formatter = (_94 = (_93 = (_92 = this.options) === null || _92 === void 0 ? void 0 : _92.formatters) === null || _93 === void 0 ? void 0 : _93.events) === null || _94 === void 0 ? void 0 : _94.productsSearched;
477
+ var _93, _94, _95, _96;
478
+ const formatter = (_95 = (_94 = (_93 = this.options) === null || _93 === void 0 ? void 0 : _93.formatters) === null || _94 === void 0 ? void 0 : _94.events) === null || _95 === void 0 ? void 0 : _95.productsSearched;
426
479
  const payload = {
427
480
  currency: props === null || props === void 0 ? void 0 : props.currency,
428
481
  price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
429
- product_id: (_95 = props === null || props === void 0 ? void 0 : props.productId) === null || _95 === void 0 ? void 0 : _95.toString(),
482
+ product_id: (_96 = props === null || props === void 0 ? void 0 : props.productId) === null || _96 === void 0 ? void 0 : _96.toString(),
430
483
  quantity: props === null || props === void 0 ? void 0 : props.quantity,
431
484
  query: props === null || props === void 0 ? void 0 : props.query,
432
485
  };
@@ -437,8 +490,8 @@ export class ChordAnalytics {
437
490
  return this.track('Products Searched', payload, options);
438
491
  });
439
492
  this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
440
- var _96, _97, _98;
441
- 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.signedIn;
493
+ var _97, _98, _99;
494
+ const formatter = (_99 = (_98 = (_97 = this.options) === null || _97 === void 0 ? void 0 : _97.formatters) === null || _98 === void 0 ? void 0 : _98.events) === null || _99 === void 0 ? void 0 : _99.signedIn;
442
495
  const payload = {
443
496
  email: props === null || props === void 0 ? void 0 : props.email,
444
497
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -450,8 +503,8 @@ export class ChordAnalytics {
450
503
  return this.track('Signed In', payload, options);
451
504
  });
452
505
  this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
453
- var _99, _100, _101;
454
- const formatter = (_101 = (_100 = (_99 = this.options) === null || _99 === void 0 ? void 0 : _99.formatters) === null || _100 === void 0 ? void 0 : _100.events) === null || _101 === void 0 ? void 0 : _101.signedOut;
506
+ var _100, _101, _102;
507
+ 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.signedOut;
455
508
  const payload = {
456
509
  email: props === null || props === void 0 ? void 0 : props.email,
457
510
  };
@@ -462,8 +515,8 @@ export class ChordAnalytics {
462
515
  return this.track('Signed Out', payload, options);
463
516
  });
464
517
  this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
465
- var _102, _103, _104;
466
- const formatter = (_104 = (_103 = (_102 = this.options) === null || _102 === void 0 ? void 0 : _102.formatters) === null || _103 === void 0 ? void 0 : _103.events) === null || _104 === void 0 ? void 0 : _104.signedUp;
518
+ var _103, _104, _105;
519
+ 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.signedUp;
467
520
  const payload = {
468
521
  email: props === null || props === void 0 ? void 0 : props.email,
469
522
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -475,8 +528,8 @@ export class ChordAnalytics {
475
528
  return this.track('Signed Up', payload, options);
476
529
  });
477
530
  this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
478
- var _105, _106, _107;
479
- const formatter = (_107 = (_106 = (_105 = this.options) === null || _105 === void 0 ? void 0 : _105.formatters) === null || _106 === void 0 ? void 0 : _106.events) === null || _107 === void 0 ? void 0 : _107.loginStarted;
531
+ var _106, _107, _108;
532
+ 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.loginStarted;
480
533
  const payload = {
481
534
  email: props === null || props === void 0 ? void 0 : props.email,
482
535
  };
@@ -487,8 +540,8 @@ export class ChordAnalytics {
487
540
  return this.track('Login Started', payload, options);
488
541
  });
489
542
  this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
490
- var _108, _109, _110, _111;
491
- const formatter = (_110 = (_109 = (_108 = this.options) === null || _108 === void 0 ? void 0 : _108.formatters) === null || _109 === void 0 ? void 0 : _109.events) === null || _110 === void 0 ? void 0 : _110.subscriptionCancelled;
543
+ var _109, _110, _111, _112;
544
+ 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.subscriptionCancelled;
492
545
  const payload = {
493
546
  actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
494
547
  address: props === null || props === void 0 ? void 0 : props.address,
@@ -497,7 +550,7 @@ export class ChordAnalytics {
497
550
  end_date: props === null || props === void 0 ? void 0 : props.endDate,
498
551
  interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
499
552
  interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
500
- products: (_111 = props === null || props === void 0 ? void 0 : props.products) === null || _111 === void 0 ? void 0 : _111.map((p, i) => {
553
+ products: (_112 = props === null || props === void 0 ? void 0 : props.products) === null || _112 === void 0 ? void 0 : _112.map((p, i) => {
501
554
  var _a, _b, _c, _d;
502
555
  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 }));
503
556
  }),
@@ -512,8 +565,8 @@ export class ChordAnalytics {
512
565
  return this.track('Subscription Cancelled', payload, options);
513
566
  });
514
567
  this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
515
- var _112, _113, _114;
516
- 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.navigationClicked;
568
+ var _113, _114, _115;
569
+ const formatter = (_115 = (_114 = (_113 = this.options) === null || _113 === void 0 ? void 0 : _113.formatters) === null || _114 === void 0 ? void 0 : _114.events) === null || _115 === void 0 ? void 0 : _115.navigationClicked;
517
570
  const payload = {
518
571
  category: props === null || props === void 0 ? void 0 : props.category,
519
572
  label: props === null || props === void 0 ? void 0 : props.label,
@@ -528,15 +581,15 @@ export class ChordAnalytics {
528
581
  return this.track('Navigation Clicked', payload, options);
529
582
  });
530
583
  this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
531
- var _115, _116, _117, _118;
532
- const formatter = (_117 = (_116 = (_115 = this.options) === null || _115 === void 0 ? void 0 : _115.formatters) === null || _116 === void 0 ? void 0 : _116.events) === null || _117 === void 0 ? void 0 : _117.paymentInfoEntered;
584
+ var _116, _117, _118, _119;
585
+ 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.paymentInfoEntered;
533
586
  const payload = {
534
587
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
535
588
  coupon: props === null || props === void 0 ? void 0 : props.coupon,
536
589
  currency: props === null || props === void 0 ? void 0 : props.currency,
537
590
  order_id: props === null || props === void 0 ? void 0 : props.orderId,
538
591
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
539
- products: (_118 = props === null || props === void 0 ? void 0 : props.products) === null || _118 === void 0 ? void 0 : _118.map((p, i) => {
592
+ products: (_119 = props === null || props === void 0 ? void 0 : props.products) === null || _119 === void 0 ? void 0 : _119.map((p, i) => {
540
593
  var _a, _b, _c, _d;
541
594
  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 }));
542
595
  }),
@@ -550,14 +603,16 @@ export class ChordAnalytics {
550
603
  }
551
604
  return this.track('Payment Info Entered', payload, options);
552
605
  });
606
+ const debug = ((_a = window === null || window === void 0 ? void 0 : window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(DEBUG_MODE_STORAGE_KEY)) === 'true';
553
607
  const defaults = {
554
- debug: false,
555
- enableLogging: true,
608
+ debug,
609
+ enableLogging: debug,
556
610
  namespace: 'chord',
557
611
  stripNull: true,
612
+ awaitConsent: true,
558
613
  };
559
614
  this.options = Object.assign(Object.assign({}, defaults), options);
560
- if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.cdpDomain) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.cdpWriteKey) && window) {
615
+ if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.cdpDomain) && ((_c = this.options) === null || _c === void 0 ? void 0 : _c.cdpWriteKey) && window) {
561
616
  window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
562
617
  addCdpSnippet(this.options);
563
618
  }
@@ -31,6 +31,7 @@ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
31
31
  cdpDomain?: string;
32
32
  cdpWriteKey?: string;
33
33
  consent?: 'ketch' | 'onetrust' | 'shopify';
34
+ awaitConsent?: boolean;
34
35
  debug?: boolean;
35
36
  enableLogging?: boolean;
36
37
  formatters: ChordAnalyticsFormatters<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chordcommerce/analytics",
3
3
  "description": "Chord Commerce event tracking",
4
- "version": "1.12.0",
4
+ "version": "1.12.2",
5
5
  "author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",