@chordcommerce/analytics 1.7.0 → 1.9.0

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
+ };
@@ -1,4 +1,4 @@
1
- import type { AnyAnalytics, EventProperties, Options, ValidateResult, ChordAnalyticsOptions, AnyOptions, CartViewedInput, IdentifyTraits, CheckoutStartedInput, EmailCapturedInput, ProductListViewedInput, ProductListFilteredInput, ProductAddedInput, ProductClickedInput, ProductRemovedInput, ProductViewedInput, ProductsSearchedInput, CouponAppliedInput, CouponDeniedInput, CouponEnteredInput, CouponRemovedInput, SignedInInput, SignedOutInput, SignedUpInput, ObjectTypes } from '../types/index.js';
1
+ import type { AnyAnalytics, EventProperties, Options, ValidateResult, ChordAnalyticsOptions, AnyOptions, CartViewedInput, IdentifyTraits, CheckoutStartedInput, CheckoutStepCompletedInput, CheckoutStepViewedInput, EmailCapturedInput, ProductListViewedInput, ProductListFilteredInput, ProductAddedInput, ProductClickedInput, VariantClickedInput, ProductRemovedInput, ProductViewedInput, ProductsSearchedInput, CouponAppliedInput, CouponDeniedInput, CouponEnteredInput, CouponRemovedInput, SignedInInput, SignedOutInput, SignedUpInput, LoginStartedInput, ObjectTypes, SubscriptionCancelledInput, NavigationClickedInput, PaymentInfoEnteredInput } from '../types/index.js';
2
2
  export interface ChordAnalyticsSnippet {
3
3
  _loadOptions: ChordAnalyticsOptions<ObjectTypes>;
4
4
  invoked: boolean;
@@ -66,6 +66,8 @@ export declare class ChordAnalytics<T extends ObjectTypes = ObjectTypes> {
66
66
  reset: () => void;
67
67
  trackCartViewed: (props: CartViewedInput<T>, options?: AnyOptions) => Promise<void>;
68
68
  trackCheckoutStarted: (props: CheckoutStartedInput<T>, options?: AnyOptions) => Promise<void>;
69
+ trackCheckoutStepCompleted: (props: CheckoutStepCompletedInput, options?: AnyOptions) => Promise<void>;
70
+ trackCheckoutStepViewed: (props: CheckoutStepViewedInput, options?: AnyOptions) => Promise<void>;
69
71
  trackCouponApplied: (props: CouponAppliedInput, options?: AnyOptions) => Promise<void>;
70
72
  trackCouponDenied: (props: CouponDeniedInput, options?: AnyOptions) => Promise<void>;
71
73
  trackCouponEntered: (props: CouponEnteredInput, options?: AnyOptions) => Promise<void>;
@@ -73,6 +75,7 @@ export declare class ChordAnalytics<T extends ObjectTypes = ObjectTypes> {
73
75
  trackEmailCaptured: (props: EmailCapturedInput, options?: AnyOptions) => Promise<void>;
74
76
  trackProductAdded: (props: ProductAddedInput<T>, options?: AnyOptions) => Promise<void>;
75
77
  trackProductClicked: (props: ProductClickedInput<T>, options?: AnyOptions) => Promise<void>;
78
+ trackVariantClicked: (props: VariantClickedInput<T>, options?: AnyOptions) => Promise<void>;
76
79
  trackProductListFiltered: (props: ProductListFilteredInput, options?: AnyOptions) => Promise<void>;
77
80
  trackProductListViewed: (props: ProductListViewedInput<T>, options?: AnyOptions) => Promise<void>;
78
81
  trackProductRemoved: (props: ProductRemovedInput<T>, options?: AnyOptions) => Promise<void>;
@@ -81,4 +84,8 @@ export declare class ChordAnalytics<T extends ObjectTypes = ObjectTypes> {
81
84
  trackSignedIn: (props: SignedInInput, options?: AnyOptions) => Promise<void>;
82
85
  trackSignedOut: (props?: SignedOutInput, options?: AnyOptions) => Promise<void>;
83
86
  trackSignedUp: (props?: SignedUpInput, options?: AnyOptions) => Promise<void>;
87
+ trackLoginStarted: (props: LoginStartedInput, options?: AnyOptions) => Promise<void>;
88
+ trackSubscriptionCancelled: (props: SubscriptionCancelledInput, options?: AnyOptions) => Promise<void>;
89
+ trackNavigationClicked: (props: NavigationClickedInput, options?: AnyOptions) => Promise<void>;
90
+ trackPaymentInfoEntered: (props: PaymentInfoEnteredInput, options?: AnyOptions) => Promise<void>;
84
91
  }
@@ -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
  */
@@ -20,11 +22,11 @@ export class ChordAnalytics {
20
22
  */
21
23
  this.invoked = true;
22
24
  /*
23
- * Return the CDP instance provided in `options.cdp`.
25
+ * Return the CDP instance or the queue.
24
26
  */
25
27
  this.cdp = () => {
26
- var _a;
27
- const a = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cdp;
28
+ const { cdp, namespace } = this.options;
29
+ const a = cdp || (window === null || window === void 0 ? void 0 : window[`_${namespace}`]) || cdpQueue(namespace);
28
30
  if (typeof a === 'function')
29
31
  return a();
30
32
  return a;
@@ -135,8 +137,8 @@ export class ChordAnalytics {
135
137
  };
136
138
  // TODO: Add support for props.products
137
139
  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, {
140
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
141
+ 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
142
  cart: props === null || props === void 0 ? void 0 : props.cart,
141
143
  });
142
144
  const payload = {
@@ -145,17 +147,17 @@ export class ChordAnalytics {
145
147
  products: cart === null || cart === void 0 ? void 0 : cart.products,
146
148
  value: cart === null || cart === void 0 ? void 0 : cart.value,
147
149
  };
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);
150
+ 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) {
151
+ 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
152
  return this.track('Cart Viewed', formattedPayload, options);
151
153
  }
152
154
  return this.track('Cart Viewed', payload, options);
153
155
  });
154
156
  // TODO: Add support for props.products
155
157
  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, {
158
+ var _o, _p, _q, _r, _s, _t, _u;
159
+ 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;
160
+ 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
161
  checkout: props === null || props === void 0 ? void 0 : props.checkout,
160
162
  });
161
163
  const payload = checkout;
@@ -165,9 +167,39 @@ export class ChordAnalytics {
165
167
  }
166
168
  return this.track('Checkout Started', payload, options);
167
169
  });
170
+ this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
171
+ var _v, _w, _x;
172
+ 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;
173
+ const payload = {
174
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
175
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
176
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
177
+ step: props === null || props === void 0 ? void 0 : props.step,
178
+ };
179
+ if (typeof formatter === 'function') {
180
+ const formattedPayload = formatter(props, payload);
181
+ return this.track('Checkout Step Completed', formattedPayload, options);
182
+ }
183
+ return this.track('Checkout Step Completed', payload, options);
184
+ });
185
+ this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
186
+ var _y, _z, _0;
187
+ 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;
188
+ const payload = {
189
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
190
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
191
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
192
+ step: props === null || props === void 0 ? void 0 : props.step,
193
+ };
194
+ if (typeof formatter === 'function') {
195
+ const formattedPayload = formatter(props, payload);
196
+ return this.track('Checkout Step Viewed', formattedPayload, options);
197
+ }
198
+ return this.track('Checkout Step Viewed', payload, options);
199
+ });
168
200
  this.trackCouponApplied = (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.couponApplied;
201
+ var _1, _2, _3;
202
+ 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;
171
203
  const payload = {
172
204
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
173
205
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -182,8 +214,8 @@ export class ChordAnalytics {
182
214
  return this.track('Coupon Applied', payload, options);
183
215
  });
184
216
  this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
185
- var _w, _x, _y;
186
- 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.couponDenied;
217
+ var _4, _5, _6;
218
+ 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;
187
219
  const payload = {
188
220
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
189
221
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -198,8 +230,8 @@ export class ChordAnalytics {
198
230
  return this.track('Coupon Denied', payload, options);
199
231
  });
200
232
  this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
201
- var _z, _0, _1;
202
- 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.couponEntered;
233
+ var _7, _8, _9;
234
+ 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;
203
235
  const payload = {
204
236
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
205
237
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -213,8 +245,8 @@ export class ChordAnalytics {
213
245
  return this.track('Coupon Entered', payload, options);
214
246
  });
215
247
  this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
216
- var _2, _3, _4;
217
- 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.couponRemoved;
248
+ var _10, _11, _12;
249
+ 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;
218
250
  const payload = {
219
251
  cart_id: props === null || props === void 0 ? void 0 : props.cartId,
220
252
  coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
@@ -229,8 +261,8 @@ export class ChordAnalytics {
229
261
  return this.track('Coupon Removed', payload, options);
230
262
  });
231
263
  this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
232
- var _5, _6, _7;
233
- 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.emailCaptured;
264
+ var _13, _14, _15;
265
+ 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;
234
266
  const payload = {
235
267
  email: props === null || props === void 0 ? void 0 : props.email,
236
268
  placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
@@ -243,13 +275,13 @@ export class ChordAnalytics {
243
275
  return this.track('Email Captured', payload, options);
244
276
  });
245
277
  this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
246
- var _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
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.productAdded;
248
- const product = (_14 = (_13 = (_12 = (_11 = this.options) === null || _11 === void 0 ? void 0 : _11.formatters) === null || _12 === void 0 ? void 0 : _12.objects) === null || _13 === void 0 ? void 0 : _13.product) === null || _14 === void 0 ? void 0 : _14.call(_13, props === null || props === void 0 ? void 0 : props.product);
249
- const cart = (_18 = (_17 = (_16 = (_15 = this.options) === null || _15 === void 0 ? void 0 : _15.formatters) === null || _16 === void 0 ? void 0 : _16.objects) === null || _17 === void 0 ? void 0 : _17.cart) === null || _18 === void 0 ? void 0 : _18.call(_17, {
278
+ var _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
279
+ 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;
280
+ 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);
281
+ 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, {
250
282
  cart: props === null || props === void 0 ? void 0 : props.cart,
251
283
  });
252
- const quantity = ((_19 = props === null || props === void 0 ? void 0 : props.product) === null || _19 === void 0 ? void 0 : _19.quantity) || 1;
284
+ const quantity = ((_27 = props === null || props === void 0 ? void 0 : props.product) === null || _27 === void 0 ? void 0 : _27.quantity) || 1;
253
285
  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) });
254
286
  if (typeof formatter === 'function') {
255
287
  const formattedPayload = formatter(props, payload);
@@ -258,28 +290,43 @@ export class ChordAnalytics {
258
290
  return this.track('Product Added', payload, options);
259
291
  });
260
292
  this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
261
- var _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32;
262
- const formatter = (_22 = (_21 = (_20 = this.options) === null || _20 === void 0 ? void 0 : _20.formatters) === null || _21 === void 0 ? void 0 : _21.events) === null || _22 === void 0 ? void 0 : _22.productClicked;
263
- const product = (_26 = (_25 = (_24 = (_23 = this.options) === null || _23 === void 0 ? void 0 : _23.formatters) === null || _24 === void 0 ? void 0 : _24.objects) === null || _25 === void 0 ? void 0 : _25.product) === null || _26 === void 0 ? void 0 : _26.call(_25, props === null || props === void 0 ? void 0 : props.product);
264
- const cart = (_30 = (_29 = (_28 = (_27 = this.options) === null || _27 === void 0 ? void 0 : _27.formatters) === null || _28 === void 0 ? void 0 : _28.objects) === null || _29 === void 0 ? void 0 : _29.cart) === null || _30 === void 0 ? void 0 : _30.call(_29, {
293
+ var _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40;
294
+ 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;
295
+ 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);
296
+ 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, {
265
297
  cart: props === null || props === void 0 ? void 0 : props.cart,
266
298
  });
267
- const quantity = ((_31 = props === null || props === void 0 ? void 0 : props.product) === null || _31 === void 0 ? void 0 : _31.quantity) || 1;
268
- const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_32 = props === null || props === void 0 ? void 0 : props.listId) === null || _32 === void 0 ? void 0 : _32.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
299
+ const quantity = ((_39 = props === null || props === void 0 ? void 0 : props.product) === null || _39 === void 0 ? void 0 : _39.quantity) || 1;
300
+ 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 })] });
269
301
  if (typeof formatter === 'function') {
270
302
  const formattedPayload = formatter(props, payload);
271
303
  return this.track('Product Clicked', formattedPayload, options);
272
304
  }
273
305
  return this.track('Product Clicked', payload, options);
274
306
  });
307
+ this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
308
+ var _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52;
309
+ 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;
310
+ 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);
311
+ 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, {
312
+ cart: props === null || props === void 0 ? void 0 : props.cart,
313
+ });
314
+ const quantity = ((_52 = props === null || props === void 0 ? void 0 : props.product) === null || _52 === void 0 ? void 0 : _52.quantity) || 1;
315
+ 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 });
316
+ if (typeof formatter === 'function') {
317
+ const formattedPayload = formatter(props, payload);
318
+ return this.track('Variant Clicked', formattedPayload, options);
319
+ }
320
+ return this.track('Variant Clicked', payload, options);
321
+ });
275
322
  this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
276
- var _33, _34, _35, _36, _37;
277
- const formatter = (_35 = (_34 = (_33 = this.options) === null || _33 === void 0 ? void 0 : _33.formatters) === null || _34 === void 0 ? void 0 : _34.events) === null || _35 === void 0 ? void 0 : _35.productListFiltered;
323
+ var _53, _54, _55, _56, _57;
324
+ 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;
278
325
  const payload = {
279
326
  category: props === null || props === void 0 ? void 0 : props.category,
280
327
  filters: props === null || props === void 0 ? void 0 : props.filters,
281
- list_id: (_36 = props === null || props === void 0 ? void 0 : props.listId) === null || _36 === void 0 ? void 0 : _36.toString(),
282
- item_list_id: (_37 = props === null || props === void 0 ? void 0 : props.listId) === null || _37 === void 0 ? void 0 : _37.toString(),
328
+ list_id: (_56 = props === null || props === void 0 ? void 0 : props.listId) === null || _56 === void 0 ? void 0 : _56.toString(),
329
+ item_list_id: (_57 = props === null || props === void 0 ? void 0 : props.listId) === null || _57 === void 0 ? void 0 : _57.toString(),
283
330
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
284
331
  sorts: props === null || props === void 0 ? void 0 : props.sorts,
285
332
  };
@@ -290,14 +337,14 @@ export class ChordAnalytics {
290
337
  return this.track('Product List Filtered', payload, options);
291
338
  });
292
339
  this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
293
- var _38, _39, _40, _41, _42, _43;
294
- const formatter = (_40 = (_39 = (_38 = this.options) === null || _38 === void 0 ? void 0 : _38.formatters) === null || _39 === void 0 ? void 0 : _39.events) === null || _40 === void 0 ? void 0 : _40.productListViewed;
340
+ var _58, _59, _60, _61, _62, _63;
341
+ 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;
295
342
  const payload = {
296
343
  category: props === null || props === void 0 ? void 0 : props.category,
297
- list_id: (_41 = props === null || props === void 0 ? void 0 : props.listId) === null || _41 === void 0 ? void 0 : _41.toString(),
298
- item_list_id: (_42 = props === null || props === void 0 ? void 0 : props.listId) === null || _42 === void 0 ? void 0 : _42.toString(),
344
+ list_id: (_61 = props === null || props === void 0 ? void 0 : props.listId) === null || _61 === void 0 ? void 0 : _61.toString(),
345
+ item_list_id: (_62 = props === null || props === void 0 ? void 0 : props.listId) === null || _62 === void 0 ? void 0 : _62.toString(),
299
346
  item_list_name: props === null || props === void 0 ? void 0 : props.listName,
300
- products: (_43 = props === null || props === void 0 ? void 0 : props.products) === null || _43 === void 0 ? void 0 : _43.map((p, i) => {
347
+ products: (_63 = props === null || props === void 0 ? void 0 : props.products) === null || _63 === void 0 ? void 0 : _63.map((p, i) => {
301
348
  var _a, _b, _c, _d;
302
349
  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 }));
303
350
  }),
@@ -310,8 +357,8 @@ export class ChordAnalytics {
310
357
  return this.track('Product List Viewed', payload, options);
311
358
  });
312
359
  this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
313
- var _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58;
314
- const formatter = (_46 = (_45 = (_44 = this.options) === null || _44 === void 0 ? void 0 : _44.formatters) === null || _45 === void 0 ? void 0 : _45.events) === null || _46 === void 0 ? void 0 : _46.productRemoved;
360
+ var _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78;
361
+ 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;
315
362
  /*
316
363
  const product = this.options?.formatters?.objects?.product?.({
317
364
  position: props?.position,
@@ -320,13 +367,13 @@ export class ChordAnalytics {
320
367
  variantId: props?.variantId,
321
368
  })
322
369
  */
323
- const lineItem = (_50 = (_49 = (_48 = (_47 = this.options) === null || _47 === void 0 ? void 0 : _47.formatters) === null || _48 === void 0 ? void 0 : _48.objects) === null || _49 === void 0 ? void 0 : _49.lineItem) === null || _50 === void 0 ? void 0 : _50.call(_49, {
370
+ 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, {
324
371
  lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
325
372
  });
326
- const cart = (_54 = (_53 = (_52 = (_51 = this.options) === null || _51 === void 0 ? void 0 : _51.formatters) === null || _52 === void 0 ? void 0 : _52.objects) === null || _53 === void 0 ? void 0 : _53.cart) === null || _54 === void 0 ? void 0 : _54.call(_53, {
373
+ 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, {
327
374
  cart: props === null || props === void 0 ? void 0 : props.cart,
328
375
  });
329
- const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_55 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _55 !== void 0 ? _55 : 0) * ((_56 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _56 !== void 0 ? _56 : 1), value: ((_57 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _57 !== void 0 ? _57 : 0) * ((_58 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _58 !== void 0 ? _58 : 1) });
376
+ 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) });
330
377
  if (typeof formatter === 'function') {
331
378
  const formattedPayload = formatter(props, payload);
332
379
  return this.track('Product Removed', formattedPayload, options);
@@ -334,14 +381,14 @@ export class ChordAnalytics {
334
381
  return this.track('Product Removed', payload, options);
335
382
  });
336
383
  this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
337
- var _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71;
338
- 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.productViewed;
339
- const product = (_65 = (_64 = (_63 = (_62 = this.options) === null || _62 === void 0 ? void 0 : _62.formatters) === null || _63 === void 0 ? void 0 : _63.objects) === null || _64 === void 0 ? void 0 : _64.product) === null || _65 === void 0 ? void 0 : _65.call(_64, props === null || props === void 0 ? void 0 : props.product);
340
- const cart = (_69 = (_68 = (_67 = (_66 = this.options) === null || _66 === void 0 ? void 0 : _66.formatters) === null || _67 === void 0 ? void 0 : _67.objects) === null || _68 === void 0 ? void 0 : _68.cart) === null || _69 === void 0 ? void 0 : _69.call(_68, {
384
+ var _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91;
385
+ 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;
386
+ 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);
387
+ 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, {
341
388
  cart: props === null || props === void 0 ? void 0 : props.cart,
342
389
  });
343
- const quantity = ((_70 = props === null || props === void 0 ? void 0 : props.product) === null || _70 === void 0 ? void 0 : _70.quantity) || 1;
344
- 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 * (((_71 = props === null || props === void 0 ? void 0 : props.product) === null || _71 === void 0 ? void 0 : _71.quantity) || 1) });
390
+ const quantity = ((_90 = props === null || props === void 0 ? void 0 : props.product) === null || _90 === void 0 ? void 0 : _90.quantity) || 1;
391
+ 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) });
345
392
  if (typeof formatter === 'function') {
346
393
  const formattedPayload = formatter(props, payload);
347
394
  return this.track('Product Viewed', formattedPayload, options);
@@ -349,12 +396,12 @@ export class ChordAnalytics {
349
396
  return this.track('Product Viewed', payload, options);
350
397
  });
351
398
  this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
352
- var _72, _73, _74, _75;
353
- const formatter = (_74 = (_73 = (_72 = this.options) === null || _72 === void 0 ? void 0 : _72.formatters) === null || _73 === void 0 ? void 0 : _73.events) === null || _74 === void 0 ? void 0 : _74.productsSearched;
399
+ var _92, _93, _94, _95;
400
+ 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;
354
401
  const payload = {
355
402
  currency: props === null || props === void 0 ? void 0 : props.currency,
356
403
  price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
357
- product_id: (_75 = props === null || props === void 0 ? void 0 : props.productId) === null || _75 === void 0 ? void 0 : _75.toString(),
404
+ product_id: (_95 = props === null || props === void 0 ? void 0 : props.productId) === null || _95 === void 0 ? void 0 : _95.toString(),
358
405
  quantity: props === null || props === void 0 ? void 0 : props.quantity,
359
406
  query: props === null || props === void 0 ? void 0 : props.query,
360
407
  };
@@ -365,8 +412,8 @@ export class ChordAnalytics {
365
412
  return this.track('Products Searched', payload, options);
366
413
  });
367
414
  this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
368
- var _76, _77, _78;
369
- const formatter = (_78 = (_77 = (_76 = this.options) === null || _76 === void 0 ? void 0 : _76.formatters) === null || _77 === void 0 ? void 0 : _77.events) === null || _78 === void 0 ? void 0 : _78.signedIn;
415
+ var _96, _97, _98;
416
+ 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;
370
417
  const payload = {
371
418
  email: props === null || props === void 0 ? void 0 : props.email,
372
419
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -378,8 +425,8 @@ export class ChordAnalytics {
378
425
  return this.track('Signed In', payload, options);
379
426
  });
380
427
  this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
381
- var _79, _80, _81;
382
- 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.signedOut;
428
+ var _99, _100, _101;
429
+ 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;
383
430
  const payload = {
384
431
  email: props === null || props === void 0 ? void 0 : props.email,
385
432
  };
@@ -390,8 +437,8 @@ export class ChordAnalytics {
390
437
  return this.track('Signed Out', payload, options);
391
438
  });
392
439
  this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
393
- var _82, _83, _84;
394
- const formatter = (_84 = (_83 = (_82 = this.options) === null || _82 === void 0 ? void 0 : _82.formatters) === null || _83 === void 0 ? void 0 : _83.events) === null || _84 === void 0 ? void 0 : _84.signedUp;
440
+ var _102, _103, _104;
441
+ 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;
395
442
  const payload = {
396
443
  email: props === null || props === void 0 ? void 0 : props.email,
397
444
  method: props === null || props === void 0 ? void 0 : props.method,
@@ -402,11 +449,92 @@ export class ChordAnalytics {
402
449
  }
403
450
  return this.track('Signed Up', payload, options);
404
451
  });
452
+ this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
453
+ var _105, _106, _107;
454
+ 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;
455
+ const payload = {
456
+ email: props === null || props === void 0 ? void 0 : props.email,
457
+ };
458
+ if (typeof formatter === 'function') {
459
+ const formattedPayload = formatter(props, payload);
460
+ return this.track('Login Started', formattedPayload, options);
461
+ }
462
+ return this.track('Login Started', payload, options);
463
+ });
464
+ this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
465
+ var _108, _109, _110, _111;
466
+ 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;
467
+ const payload = {
468
+ actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
469
+ address: props === null || props === void 0 ? void 0 : props.address,
470
+ brand: props === null || props === void 0 ? void 0 : props.brand,
471
+ email: props === null || props === void 0 ? void 0 : props.email,
472
+ end_date: props === null || props === void 0 ? void 0 : props.endDate,
473
+ interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
474
+ interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
475
+ products: (_111 = props === null || props === void 0 ? void 0 : props.products) === null || _111 === void 0 ? void 0 : _111.map((p, i) => {
476
+ var _a, _b, _c, _d;
477
+ 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 }));
478
+ }),
479
+ state: props === null || props === void 0 ? void 0 : props.state,
480
+ subscription_id: props === null || props === void 0 ? void 0 : props.subscriptionId,
481
+ currency: props === null || props === void 0 ? void 0 : props.currency,
482
+ };
483
+ if (typeof formatter === 'function') {
484
+ const formattedPayload = formatter(props || {}, payload);
485
+ return this.track('Subscription Cancelled', formattedPayload, options);
486
+ }
487
+ return this.track('Subscription Cancelled', payload, options);
488
+ });
489
+ this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
490
+ var _112, _113, _114;
491
+ 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;
492
+ const payload = {
493
+ category: props === null || props === void 0 ? void 0 : props.category,
494
+ label: props === null || props === void 0 ? void 0 : props.label,
495
+ navigation_placement: props === null || props === void 0 ? void 0 : props.navigationPlacement,
496
+ navigation_title: props === null || props === void 0 ? void 0 : props.navigationTitle,
497
+ navigation_url: props === null || props === void 0 ? void 0 : props.navigationUrl,
498
+ };
499
+ if (typeof formatter === 'function') {
500
+ const formattedPayload = formatter(props, payload);
501
+ return this.track('Navigation Clicked', formattedPayload, options);
502
+ }
503
+ return this.track('Navigation Clicked', payload, options);
504
+ });
505
+ this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
506
+ var _115, _116, _117, _118;
507
+ 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;
508
+ const payload = {
509
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
510
+ coupon: props === null || props === void 0 ? void 0 : props.coupon,
511
+ currency: props === null || props === void 0 ? void 0 : props.currency,
512
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
513
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
514
+ products: (_118 = props === null || props === void 0 ? void 0 : props.products) === null || _118 === void 0 ? void 0 : _118.map((p, i) => {
515
+ var _a, _b, _c, _d;
516
+ 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 }));
517
+ }),
518
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
519
+ step: props === null || props === void 0 ? void 0 : props.step,
520
+ value: props === null || props === void 0 ? void 0 : props.value,
521
+ };
522
+ if (typeof formatter === 'function') {
523
+ const formattedPayload = formatter(props, payload);
524
+ return this.track('Payment Info Entered', formattedPayload, options);
525
+ }
526
+ return this.track('Payment Info Entered', payload, options);
527
+ });
405
528
  const defaults = {
406
529
  debug: false,
407
530
  enableLogging: true,
531
+ namespace: 'chord',
408
532
  stripNull: true,
409
533
  };
410
534
  this.options = Object.assign(Object.assign({}, defaults), options);
535
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.cdpDomain) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.cdpWriteKey) && window) {
536
+ window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
537
+ addCdpSnippet(this.options);
538
+ }
411
539
  }
412
540
  }