@chordcommerce/analytics 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,13 +2,11 @@
2
2
 
3
3
  The `@chordcommerce/analytics` library provides simple methods for sending tracking events to Chord from your website, with an optional debugging mode to validate event properties.
4
4
 
5
- `@chordcommerce/analytics` is intended to be installed alongside a customer data platform (CDP) tracking library like Segment's [analytics.js](https://www.npmjs.com/package/@segment/analytics-next). `@chordcommerce/analytics` sends Chord tracking events to the CDP tracking library, so they’re available for all connected integrations.
6
-
7
- Visit [docs.chord.co](https://docs.chord.co/analytics-getting-started) for guides, examples, and an API reference.
5
+ Visit [docs.chord.co](https://docs.chord.co/installing-chord-analytics) for guides, examples, and an API reference.
8
6
 
9
7
  ## Requirements
10
8
 
11
- A CDP Javascript library must be installed in your project. Currently, only Segment's [analytics.js](https://www.npmjs.com/package/@segment/analytics-next) library is supported.
9
+ The library supports sending events via Chord CDP or Segment. If using Segment, [analytics.js](https://www.npmjs.com/package/@segment/analytics-next) must also be installed in your project.
12
10
 
13
11
  ## Installation
14
12
 
@@ -22,7 +20,7 @@ yarn add @chordcommerce/analytics
22
20
 
23
21
  ## Usage
24
22
 
25
- First, ensure that a CDP Javascript library is installed and configured in your project. Then, initialize `@chordcommerce/analytics` as follows:
23
+ Initialize `@chordcommerce/analytics` as follows:
26
24
 
27
25
  ```jsx
28
26
  import ChordAnalytics from '@chordcommerce/analytics'
@@ -36,14 +34,19 @@ chord.trackCartViewed({ cart }) // sends a "Cart Viewed" event to the CDP
36
34
 
37
35
  `@chordcommerce/analytics` can be initialized with the following options:
38
36
 
39
- | Property | Required | Description |
40
- | --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41
- | `cdp` | true | A reference to the CDP library, or a function that returns a reference to the CDP library. For example, if using Segment's [analytics.js](https://www.npmjs.com/package/@segment/analytics-next) library, this could be `window.analytics` or `() => window.analytics`. If omitted, no tracking events are sent. |
42
- | `debug` | false | Defaults to `false`. When set to `true`, events are validated against Chord's tracking plan and errors are logged. We recommend enabling this for development and disabling for production. |
43
- | `enableLogging` | false | Defaults to `true`. When set to `true`, errors are logged using `console.log`. |
44
- | `formatters` | true | Functions that are used to construct tracking events. There are two types of formatters, objects and events. `formatters.objects` is required. See below for details. |
45
- | `metadata` | true | Event metadata. See below for details. |
46
- | `stripNull` | false | Defaults to `true`. When set to `true`, event properties with a `null` value are removed. CDPs typically treat `null` and `undefined` as separate values, so be sure you intend to send `null` values before setting to false. |
37
+ | Property | Required | Description |
38
+ | --------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39
+ | `cdp` | false | _Required when using a CDP other than Chord._ A reference to the CDP library, or a function that returns a reference to the CDP library. For example, if using Segment's [analytics.js](https://www.npmjs.com/package/@segment/analytics-next) library, this could be `window.analytics` or `() => window.analytics`. |
40
+ | `cdpDomain` | false | _Required when using Chord CDP._ The Chord CDP domain. To be provided by the Chord team. |
41
+ | `cdpWriteKey` | false | _Required when using Chord CDP._ The Chord CDP write key. To be provided by the Chord team. |
42
+ | `debug` | false | Defaults to `false`. When set to `true`, events are validated against Chord's tracking plan and errors are logged. We recommend enabling this for development and disabling for production. |
43
+ | `enableLogging` | false | Defaults to `true`. When set to `true`, errors are logged using `console.log`. |
44
+ | `formatters` | true | Functions that are used to construct tracking events. There are two types of formatters, objects and events. `formatters.objects` is required. See below for details. |
45
+ | `metadata` | true | Event metadata. See below for details. |
46
+ | `namespace` | false | Defaults to `chord`. Changes where Chord is globally available (e.g. `window.chord`). _Only applicable when using Chord CDP._ |
47
+ | `stripNull` | false | Defaults to `true`. When set to `true`, event properties with a `null` value are removed. CDPs typically treat `null` and `undefined` as separate values, so be sure you intend to send `null` values before setting to false. |
48
+
49
+ If `cdp`, `cdpDomain`, and `cdpWriteKey` are all omitted, no tracking events are sent.
47
50
 
48
51
  **Metadata**
49
52
 
@@ -109,7 +112,7 @@ export const cartFormatter: CartFormatter<StorefrontCart> = (props) => {
109
112
 
110
113
  ## API Reference
111
114
 
112
- See [Chord’s documentation](https://docs.chord.co/analytics-getting-started) for a full API reference.
115
+ See [Chord’s documentation](https://docs.chord.co/api-reference) for a full API reference.
113
116
 
114
117
  ## Support
115
118
 
@@ -0,0 +1,3 @@
1
+ import type { ChordAnalyticsOptions, ChordAnalyticsQueue } from '../types/index.js';
2
+ export declare const addCdpSnippet: (options: ChordAnalyticsOptions) => void;
3
+ export declare const cdpQueue: (namespace: string) => ChordAnalyticsQueue;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Adds the Chord CDP snippet to the page.
3
+ */
4
+ export const addCdpSnippet = (options) => {
5
+ if (!document || typeof document.createElement === 'undefined')
6
+ return;
7
+ const s = document.createElement('script');
8
+ s.async = true;
9
+ s.src = `${options.cdpDomain}/p.js`;
10
+ s.setAttribute('data-debug', `${!!options.debug}`);
11
+ s.setAttribute('data-init-only', 'true');
12
+ s.setAttribute('data-namespace', `_${options.namespace}`);
13
+ s.setAttribute('data-write-key', options.cdpWriteKey);
14
+ document.head.appendChild(s);
15
+ };
16
+ /*
17
+ * Returns the CDP queue to hold events ahead of CDP initialization.
18
+ */
19
+ export const cdpQueue = (namespace) => {
20
+ var _a;
21
+ const q = window && (window[_a = `_${namespace}Q`] || (window[_a] = []));
22
+ return {
23
+ track: (...args) => q.push((cdp) => cdp.track(...args)),
24
+ identify: (...args) => q.push((cdp) => cdp.identify(...args)),
25
+ page: (...args) => q.push((cdp) => cdp.page(...args)),
26
+ reset: (...args) => q.push((cdp) => cdp.reset(...args)),
27
+ };
28
+ };
@@ -23,6 +23,7 @@ export declare class ChordAnalytics<T extends ObjectTypes = ObjectTypes> {
23
23
  options: ChordAnalyticsOptions<T>;
24
24
  constructor(options: ChordAnalyticsOptions<T>);
25
25
  cdp: () => AnyAnalytics;
26
+ ccdp: () => AnyAnalytics;
26
27
  logger: (message?: any, ...optionalParams: any[]) => void;
27
28
  /**
28
29
  * Validate the body of a `track` event against the Chord tracking plan.
@@ -7,10 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { addCdpSnippet, cdpQueue } from './cdp.js';
10
11
  import { eventSchemas } from '../validators/index.js';
11
12
  import { pruneNullValues } from '../utils.js';
12
13
  export class ChordAnalytics {
13
14
  constructor(options) {
15
+ var _a, _b;
14
16
  /**
15
17
  * Allows snippet.js to detect whether this library has been initialized yet.
16
18
  */
@@ -29,6 +31,15 @@ export class ChordAnalytics {
29
31
  return a();
30
32
  return a;
31
33
  };
34
+ /*
35
+ * Return the Chord CDP instance or queue.
36
+ */
37
+ this.ccdp = () => {
38
+ const { cdpDomain, cdpWriteKey, namespace } = this.options;
39
+ if (!cdpDomain || !cdpWriteKey)
40
+ return null;
41
+ return (window === null || window === void 0 ? void 0 : window[`_${namespace}`]) || cdpQueue(namespace);
42
+ };
32
43
  /*
33
44
  * Log a message to the console if `options.enableLogging` is true.
34
45
  */
@@ -88,6 +99,10 @@ export class ChordAnalytics {
88
99
  if (a && typeof a.track === 'function') {
89
100
  a.track(event, finalEventProps, options, () => resolve());
90
101
  }
102
+ const b = this.ccdp();
103
+ if (b && typeof b.track === 'function') {
104
+ b.track(event, finalEventProps, options, () => resolve());
105
+ }
91
106
  }
92
107
  catch (error) {
93
108
  this.logger(error);
@@ -103,6 +118,10 @@ export class ChordAnalytics {
103
118
  if (a && typeof a.identify === 'function') {
104
119
  a.identify(...props);
105
120
  }
121
+ const b = this.ccdp();
122
+ if (b && typeof b.identify === 'function') {
123
+ b.identify(...props);
124
+ }
106
125
  }
107
126
  catch (error) {
108
127
  this.logger(error);
@@ -117,6 +136,10 @@ export class ChordAnalytics {
117
136
  if (a && typeof a.page === 'function') {
118
137
  a.page({ meta: this.meta() });
119
138
  }
139
+ const b = this.ccdp();
140
+ if (b && typeof b.page === 'function') {
141
+ b.page({ meta: this.meta() });
142
+ }
120
143
  }
121
144
  catch (error) {
122
145
  this.logger(error);
@@ -128,6 +151,10 @@ export class ChordAnalytics {
128
151
  if (a && typeof a.reset === 'function') {
129
152
  a.reset();
130
153
  }
154
+ const b = this.ccdp();
155
+ if (b && typeof b.reset === 'function') {
156
+ b.reset();
157
+ }
131
158
  }
132
159
  catch (error) {
133
160
  this.logger(error);
@@ -135,8 +162,8 @@ export class ChordAnalytics {
135
162
  };
136
163
  // TODO: Add support for props.products
137
164
  this.trackCartViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
138
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
139
- const cart = (_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.cart) === null || _d === void 0 ? void 0 : _d.call(_c, {
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, {
140
167
  cart: props === null || props === void 0 ? void 0 : props.cart,
141
168
  });
142
169
  const payload = {
@@ -145,17 +172,17 @@ export class ChordAnalytics {
145
172
  products: cart === null || cart === void 0 ? void 0 : cart.products,
146
173
  value: cart === null || cart === void 0 ? void 0 : cart.value,
147
174
  };
148
- if ((_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.formatters) === null || _f === void 0 ? void 0 : _f.events) === null || _g === void 0 ? void 0 : _g.cartViewed) {
149
- const formattedPayload = (_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(props, payload);
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);
150
177
  return this.track('Cart Viewed', formattedPayload, options);
151
178
  }
152
179
  return this.track('Cart Viewed', payload, options);
153
180
  });
154
181
  // TODO: Add support for props.products
155
182
  this.trackCheckoutStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
156
- var _l, _m, _o, _p, _q, _r, _s;
157
- const formatter = (_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.checkoutStarted;
158
- const checkout = (_s = (_r = (_q = (_p = this.options) === null || _p === void 0 ? void 0 : _p.formatters) === null || _q === void 0 ? void 0 : _q.objects) === null || _r === void 0 ? void 0 : _r.checkout) === null || _s === void 0 ? void 0 : _s.call(_r, {
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, {
159
186
  checkout: props === null || props === void 0 ? void 0 : props.checkout,
160
187
  });
161
188
  const payload = checkout;
@@ -166,8 +193,8 @@ export class ChordAnalytics {
166
193
  return this.track('Checkout Started', payload, options);
167
194
  });
168
195
  this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
169
- var _t, _u, _v;
170
- const formatter = (_v = (_u = (_t = this.options) === null || _t === void 0 ? void 0 : _t.formatters) === null || _u === void 0 ? void 0 : _u.events) === null || _v === void 0 ? void 0 : _v.checkoutStepCompleted;
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;
171
198
  const payload = {
172
199
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
173
200
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
@@ -181,8 +208,8 @@ export class ChordAnalytics {
181
208
  return this.track('Checkout Step Completed', payload, options);
182
209
  });
183
210
  this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
184
- var _w, _x, _y;
185
- 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.checkoutStepViewed;
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;
186
213
  const payload = {
187
214
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
188
215
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
@@ -196,8 +223,8 @@ export class ChordAnalytics {
196
223
  return this.track('Checkout Step Viewed', payload, options);
197
224
  });
198
225
  this.trackCouponApplied = (props, options) => __awaiter(this, void 0, void 0, function* () {
199
- var _z, _0, _1;
200
- 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.couponApplied;
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;
201
228
  const payload = {
202
229
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
203
230
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -212,8 +239,8 @@ export class ChordAnalytics {
212
239
  return this.track('Coupon Applied', payload, options);
213
240
  });
214
241
  this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
215
- var _2, _3, _4;
216
- 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.couponDenied;
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;
217
244
  const payload = {
218
245
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
219
246
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -228,8 +255,8 @@ export class ChordAnalytics {
228
255
  return this.track('Coupon Denied', payload, options);
229
256
  });
230
257
  this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
231
- var _5, _6, _7;
232
- 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.couponEntered;
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;
233
260
  const payload = {
234
261
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
235
262
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -243,8 +270,8 @@ export class ChordAnalytics {
243
270
  return this.track('Coupon Entered', payload, options);
244
271
  });
245
272
  this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
246
- var _8, _9, _10;
247
- 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.couponRemoved;
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;
248
275
  const payload = {
249
276
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
250
277
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -259,8 +286,8 @@ export class ChordAnalytics {
259
286
  return this.track('Coupon Removed', payload, options);
260
287
  });
261
288
  this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
262
- var _11, _12, _13;
263
- 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.emailCaptured;
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;
264
291
  const payload = {
265
292
  email: props === null || props === void 0 ? void 0 : props.email,
266
293
  placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
@@ -273,13 +300,13 @@ export class ChordAnalytics {
273
300
  return this.track('Email Captured', payload, options);
274
301
  });
275
302
  this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
276
- var _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
277
- 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.productAdded;
278
- const product = (_20 = (_19 = (_18 = (_17 = this.options) === null || _17 === void 0 ? void 0 : _17.formatters) === null || _18 === void 0 ? void 0 : _18.objects) === null || _19 === void 0 ? void 0 : _19.product) === null || _20 === void 0 ? void 0 : _20.call(_19, props === null || props === void 0 ? void 0 : props.product);
279
- const cart = (_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.cart) === null || _24 === void 0 ? void 0 : _24.call(_23, {
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, {
280
307
  cart: props === null || props === void 0 ? void 0 : props.cart,
281
308
  });
282
- const quantity = ((_25 = props === null || props === void 0 ? void 0 : props.product) === null || _25 === void 0 ? void 0 : _25.quantity) || 1;
309
+ const quantity = ((_27 = props === null || props === void 0 ? void 0 : props.product) === null || _27 === void 0 ? void 0 : _27.quantity) || 1;
283
310
  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) });
284
311
  if (typeof formatter === 'function') {
285
312
  const formattedPayload = formatter(props, payload);
@@ -288,14 +315,14 @@ export class ChordAnalytics {
288
315
  return this.track('Product Added', payload, options);
289
316
  });
290
317
  this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
291
- var _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38;
292
- const formatter = (_28 = (_27 = (_26 = this.options) === null || _26 === void 0 ? void 0 : _26.formatters) === null || _27 === void 0 ? void 0 : _27.events) === null || _28 === void 0 ? void 0 : _28.productClicked;
293
- const product = (_32 = (_31 = (_30 = (_29 = this.options) === null || _29 === void 0 ? void 0 : _29.formatters) === null || _30 === void 0 ? void 0 : _30.objects) === null || _31 === void 0 ? void 0 : _31.product) === null || _32 === void 0 ? void 0 : _32.call(_31, props === null || props === void 0 ? void 0 : props.product);
294
- const cart = (_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.cart) === null || _36 === void 0 ? void 0 : _36.call(_35, {
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, {
295
322
  cart: props === null || props === void 0 ? void 0 : props.cart,
296
323
  });
297
- const quantity = ((_37 = props === null || props === void 0 ? void 0 : props.product) === null || _37 === void 0 ? void 0 : _37.quantity) || 1;
298
- const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_38 = props === null || props === void 0 ? void 0 : props.listId) === null || _38 === void 0 ? void 0 : _38.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
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 })] });
299
326
  if (typeof formatter === 'function') {
300
327
  const formattedPayload = formatter(props, payload);
301
328
  return this.track('Product Clicked', formattedPayload, options);
@@ -303,13 +330,13 @@ export class ChordAnalytics {
303
330
  return this.track('Product Clicked', payload, options);
304
331
  });
305
332
  this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
306
- var _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50;
307
- const formatter = (_41 = (_40 = (_39 = this.options) === null || _39 === void 0 ? void 0 : _39.formatters) === null || _40 === void 0 ? void 0 : _40.events) === null || _41 === void 0 ? void 0 : _41.variantClicked;
308
- const product = (_45 = (_44 = (_43 = (_42 = this.options) === null || _42 === void 0 ? void 0 : _42.formatters) === null || _43 === void 0 ? void 0 : _43.objects) === null || _44 === void 0 ? void 0 : _44.product) === null || _45 === void 0 ? void 0 : _45.call(_44, props === null || props === void 0 ? void 0 : props.product);
309
- const cart = (_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.cart) === null || _49 === void 0 ? void 0 : _49.call(_48, {
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, {
310
337
  cart: props === null || props === void 0 ? void 0 : props.cart,
311
338
  });
312
- const quantity = ((_50 = props === null || props === void 0 ? void 0 : props.product) === null || _50 === void 0 ? void 0 : _50.quantity) || 1;
339
+ const quantity = ((_52 = props === null || props === void 0 ? void 0 : props.product) === null || _52 === void 0 ? void 0 : _52.quantity) || 1;
313
340
  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 });
314
341
  if (typeof formatter === 'function') {
315
342
  const formattedPayload = formatter(props, payload);
@@ -318,13 +345,13 @@ export class ChordAnalytics {
318
345
  return this.track('Variant Clicked', payload, options);
319
346
  });
320
347
  this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
321
- var _51, _52, _53, _54, _55;
322
- const formatter = (_53 = (_52 = (_51 = this.options) === null || _51 === void 0 ? void 0 : _51.formatters) === null || _52 === void 0 ? void 0 : _52.events) === null || _53 === void 0 ? void 0 : _53.productListFiltered;
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;
323
350
  const payload = {
324
351
  category: props === null || props === void 0 ? void 0 : props.category,
325
352
  filters: props === null || props === void 0 ? void 0 : props.filters,
326
- list_id: (_54 = props === null || props === void 0 ? void 0 : props.listId) === null || _54 === void 0 ? void 0 : _54.toString(),
327
- item_list_id: (_55 = props === null || props === void 0 ? void 0 : props.listId) === null || _55 === void 0 ? void 0 : _55.toString(),
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(),
328
355
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
329
356
  sorts: props === null || props === void 0 ? void 0 : props.sorts,
330
357
  };
@@ -335,14 +362,14 @@ export class ChordAnalytics {
335
362
  return this.track('Product List Filtered', payload, options);
336
363
  });
337
364
  this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
338
- var _56, _57, _58, _59, _60, _61;
339
- const formatter = (_58 = (_57 = (_56 = this.options) === null || _56 === void 0 ? void 0 : _56.formatters) === null || _57 === void 0 ? void 0 : _57.events) === null || _58 === void 0 ? void 0 : _58.productListViewed;
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;
340
367
  const payload = {
341
368
  category: props === null || props === void 0 ? void 0 : props.category,
342
- list_id: (_59 = props === null || props === void 0 ? void 0 : props.listId) === null || _59 === void 0 ? void 0 : _59.toString(),
343
- item_list_id: (_60 = props === null || props === void 0 ? void 0 : props.listId) === null || _60 === void 0 ? void 0 : _60.toString(),
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(),
344
371
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
345
- products: (_61 = props === null || props === void 0 ? void 0 : props.products) === null || _61 === void 0 ? void 0 : _61.map((p, i) => {
372
+ products: (_63 = props === null || props === void 0 ? void 0 : props.products) === null || _63 === void 0 ? void 0 : _63.map((p, i) => {
346
373
  var _a, _b, _c, _d;
347
374
  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 }));
348
375
  }),
@@ -355,8 +382,8 @@ export class ChordAnalytics {
355
382
  return this.track('Product List Viewed', payload, options);
356
383
  });
357
384
  this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
358
- var _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76;
359
- 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.productRemoved;
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;
360
387
  /*
361
388
  const product = this.options?.formatters?.objects?.product?.({
362
389
  position: props?.position,
@@ -365,13 +392,13 @@ export class ChordAnalytics {
365
392
  variantId: props?.variantId,
366
393
  })
367
394
  */
368
- const lineItem = (_68 = (_67 = (_66 = (_65 = this.options) === null || _65 === void 0 ? void 0 : _65.formatters) === null || _66 === void 0 ? void 0 : _66.objects) === null || _67 === void 0 ? void 0 : _67.lineItem) === null || _68 === void 0 ? void 0 : _68.call(_67, {
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, {
369
396
  lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
370
397
  });
371
- const cart = (_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.cart) === null || _72 === void 0 ? void 0 : _72.call(_71, {
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, {
372
399
  cart: props === null || props === void 0 ? void 0 : props.cart,
373
400
  });
374
- const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_73 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _73 !== void 0 ? _73 : 0) * ((_74 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _74 !== void 0 ? _74 : 1), value: ((_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) });
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) });
375
402
  if (typeof formatter === 'function') {
376
403
  const formattedPayload = formatter(props, payload);
377
404
  return this.track('Product Removed', formattedPayload, options);
@@ -379,14 +406,14 @@ export class ChordAnalytics {
379
406
  return this.track('Product Removed', payload, options);
380
407
  });
381
408
  this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
382
- var _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89;
383
- const formatter = (_79 = (_78 = (_77 = this.options) === null || _77 === void 0 ? void 0 : _77.formatters) === null || _78 === void 0 ? void 0 : _78.events) === null || _79 === void 0 ? void 0 : _79.productViewed;
384
- const product = (_83 = (_82 = (_81 = (_80 = this.options) === null || _80 === void 0 ? void 0 : _80.formatters) === null || _81 === void 0 ? void 0 : _81.objects) === null || _82 === void 0 ? void 0 : _82.product) === null || _83 === void 0 ? void 0 : _83.call(_82, props === null || props === void 0 ? void 0 : props.product);
385
- const cart = (_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.cart) === null || _87 === void 0 ? void 0 : _87.call(_86, {
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, {
386
413
  cart: props === null || props === void 0 ? void 0 : props.cart,
387
414
  });
388
- const quantity = ((_88 = props === null || props === void 0 ? void 0 : props.product) === null || _88 === void 0 ? void 0 : _88.quantity) || 1;
389
- 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 * (((_89 = props === null || props === void 0 ? void 0 : props.product) === null || _89 === void 0 ? void 0 : _89.quantity) || 1) });
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) });
390
417
  if (typeof formatter === 'function') {
391
418
  const formattedPayload = formatter(props, payload);
392
419
  return this.track('Product Viewed', formattedPayload, options);
@@ -394,12 +421,12 @@ export class ChordAnalytics {
394
421
  return this.track('Product Viewed', payload, options);
395
422
  });
396
423
  this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
397
- var _90, _91, _92, _93;
398
- const formatter = (_92 = (_91 = (_90 = this.options) === null || _90 === void 0 ? void 0 : _90.formatters) === null || _91 === void 0 ? void 0 : _91.events) === null || _92 === void 0 ? void 0 : _92.productsSearched;
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;
399
426
  const payload = {
400
427
  currency: props === null || props === void 0 ? void 0 : props.currency,
401
428
  price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
402
- product_id: (_93 = props === null || props === void 0 ? void 0 : props.productId) === null || _93 === void 0 ? void 0 : _93.toString(),
429
+ product_id: (_95 = props === null || props === void 0 ? void 0 : props.productId) === null || _95 === void 0 ? void 0 : _95.toString(),
403
430
  quantity: props === null || props === void 0 ? void 0 : props.quantity,
404
431
  query: props === null || props === void 0 ? void 0 : props.query,
405
432
  };
@@ -410,8 +437,8 @@ export class ChordAnalytics {
410
437
  return this.track('Products Searched', payload, options);
411
438
  });
412
439
  this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
413
- var _94, _95, _96;
414
- 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.signedIn;
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;
415
442
  const payload = {
416
443
  email: props === null || props === void 0 ? void 0 : props.email,
417
444
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -423,8 +450,8 @@ export class ChordAnalytics {
423
450
  return this.track('Signed In', payload, options);
424
451
  });
425
452
  this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
426
- var _97, _98, _99;
427
- 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.signedOut;
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;
428
455
  const payload = {
429
456
  email: props === null || props === void 0 ? void 0 : props.email,
430
457
  };
@@ -435,8 +462,8 @@ export class ChordAnalytics {
435
462
  return this.track('Signed Out', payload, options);
436
463
  });
437
464
  this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
438
- var _100, _101, _102;
439
- 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.signedUp;
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;
440
467
  const payload = {
441
468
  email: props === null || props === void 0 ? void 0 : props.email,
442
469
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -448,8 +475,8 @@ export class ChordAnalytics {
448
475
  return this.track('Signed Up', payload, options);
449
476
  });
450
477
  this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
451
- var _103, _104, _105;
452
- 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.loginStarted;
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;
453
480
  const payload = {
454
481
  email: props === null || props === void 0 ? void 0 : props.email,
455
482
  };
@@ -460,8 +487,8 @@ export class ChordAnalytics {
460
487
  return this.track('Login Started', payload, options);
461
488
  });
462
489
  this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
463
- var _106, _107, _108, _109;
464
- 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.subscriptionCancelled;
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;
465
492
  const payload = {
466
493
  actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
467
494
  address: props === null || props === void 0 ? void 0 : props.address,
@@ -470,7 +497,7 @@ export class ChordAnalytics {
470
497
  end_date: props === null || props === void 0 ? void 0 : props.endDate,
471
498
  interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
472
499
  interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
473
- products: (_109 = props === null || props === void 0 ? void 0 : props.products) === null || _109 === void 0 ? void 0 : _109.map((p, i) => {
500
+ products: (_111 = props === null || props === void 0 ? void 0 : props.products) === null || _111 === void 0 ? void 0 : _111.map((p, i) => {
474
501
  var _a, _b, _c, _d;
475
502
  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 }));
476
503
  }),
@@ -485,8 +512,8 @@ export class ChordAnalytics {
485
512
  return this.track('Subscription Cancelled', payload, options);
486
513
  });
487
514
  this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
488
- var _110, _111, _112;
489
- 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.navigationClicked;
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;
490
517
  const payload = {
491
518
  category: props === null || props === void 0 ? void 0 : props.category,
492
519
  label: props === null || props === void 0 ? void 0 : props.label,
@@ -501,15 +528,15 @@ export class ChordAnalytics {
501
528
  return this.track('Navigation Clicked', payload, options);
502
529
  });
503
530
  this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
504
- var _113, _114, _115, _116;
505
- 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.paymentInfoEntered;
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;
506
533
  const payload = {
507
534
  checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
508
535
  coupon: props === null || props === void 0 ? void 0 : props.coupon,
509
536
  currency: props === null || props === void 0 ? void 0 : props.currency,
510
537
  order_id: props === null || props === void 0 ? void 0 : props.orderId,
511
538
  payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
512
- products: (_116 = props === null || props === void 0 ? void 0 : props.products) === null || _116 === void 0 ? void 0 : _116.map((p, i) => {
539
+ products: (_118 = props === null || props === void 0 ? void 0 : props.products) === null || _118 === void 0 ? void 0 : _118.map((p, i) => {
513
540
  var _a, _b, _c, _d;
514
541
  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 }));
515
542
  }),
@@ -526,8 +553,13 @@ export class ChordAnalytics {
526
553
  const defaults = {
527
554
  debug: false,
528
555
  enableLogging: true,
556
+ namespace: 'chord',
529
557
  stripNull: true,
530
558
  };
531
559
  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) {
561
+ window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
562
+ addCdpSnippet(this.options);
563
+ }
532
564
  }
533
565
  }
@@ -11,7 +11,7 @@ export interface ObjectTypes {
11
11
  LineItem: any;
12
12
  Product: any;
13
13
  }
14
- export type AnyAnalytics = AnalyticsSnippet | Analytics | AnalyticsBrowser;
14
+ export type AnyAnalytics = AnalyticsSnippet | Analytics | AnalyticsBrowser | ChordAnalyticsQueue;
15
15
  export type AnyOptions = Options;
16
16
  export type AnyProduct = {
17
17
  [key: string]: unknown;
@@ -28,9 +28,12 @@ export type AnyLineItem = {
28
28
  };
29
29
  export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
30
30
  cdp?: AnyAnalytics | (() => AnyAnalytics);
31
+ cdpDomain?: string;
32
+ cdpWriteKey?: string;
31
33
  debug?: boolean;
32
34
  enableLogging?: boolean;
33
35
  formatters: ChordAnalyticsFormatters<T>;
36
+ namespace?: string;
34
37
  stripNull?: boolean;
35
38
  metadata: EventMetadata;
36
39
  }
@@ -62,3 +65,9 @@ export interface versionMetadata {
62
65
  export interface storeMetadata {
63
66
  domain: string;
64
67
  }
68
+ export type ChordAnalyticsQueue = {
69
+ track: (...args: any[]) => void;
70
+ identify: (...args: any[]) => void;
71
+ page: (...args: any[]) => void;
72
+ reset: (...args: any[]) => void;
73
+ };
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.8.0",
4
+ "version": "1.9.1",
5
5
  "author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",