@chordcommerce/analytics 1.17.1 → 1.18.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.
Files changed (48) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/client/cdp.d.ts +3 -0
  3. package/dist/cjs/client/cdp.js +123 -0
  4. package/dist/cjs/client/consent/index.d.ts +11 -0
  5. package/dist/cjs/client/consent/index.js +241 -0
  6. package/dist/cjs/client/consent/ketch.d.ts +16 -0
  7. package/dist/cjs/client/consent/ketch.js +53 -0
  8. package/dist/cjs/client/consent/onetrust.d.ts +22 -0
  9. package/dist/cjs/client/consent/onetrust.js +61 -0
  10. package/dist/cjs/client/consent/segment.d.ts +17 -0
  11. package/dist/cjs/client/consent/segment.js +155 -0
  12. package/dist/cjs/client/consent/shopify.d.ts +21 -0
  13. package/dist/cjs/client/consent/shopify.js +51 -0
  14. package/dist/cjs/client/index.d.ts +111 -0
  15. package/dist/cjs/client/index.js +861 -0
  16. package/dist/cjs/client/utils.d.ts +1 -0
  17. package/dist/cjs/client/utils.js +12 -0
  18. package/dist/cjs/index.d.ts +2 -0
  19. package/dist/cjs/index.js +18 -0
  20. package/dist/cjs/setupTests.d.ts +1 -0
  21. package/dist/cjs/setupTests.js +6 -0
  22. package/dist/cjs/types/client.d.ts +96 -0
  23. package/dist/cjs/types/client.js +2 -0
  24. package/dist/cjs/types/consent.d.ts +11 -0
  25. package/dist/cjs/types/consent.js +2 -0
  26. package/dist/cjs/types/formatters.d.ts +114 -0
  27. package/dist/cjs/types/formatters.js +2 -0
  28. package/dist/cjs/types/index.d.ts +7 -0
  29. package/dist/cjs/types/index.js +22 -0
  30. package/dist/cjs/types/input.d.ts +396 -0
  31. package/dist/cjs/types/input.js +2 -0
  32. package/dist/cjs/types/objects.d.ts +379 -0
  33. package/dist/cjs/types/objects.js +2 -0
  34. package/dist/cjs/types/typewriter.d.ts +6502 -0
  35. package/dist/cjs/types/typewriter.js +5 -0
  36. package/dist/cjs/utils.d.ts +2 -0
  37. package/dist/cjs/utils.js +25 -0
  38. package/dist/cjs/validators/custom.d.ts +43 -0
  39. package/dist/cjs/validators/custom.js +18 -0
  40. package/dist/cjs/validators/index.d.ts +4 -0
  41. package/dist/cjs/validators/index.js +20 -0
  42. package/dist/cjs/validators/objects.d.ts +696 -0
  43. package/dist/cjs/validators/objects.js +128 -0
  44. package/dist/cjs/validators/tracking-plan-map.d.ts +6603 -0
  45. package/dist/cjs/validators/tracking-plan-map.js +72 -0
  46. package/dist/cjs/validators/tracking-plan.d.ts +9275 -0
  47. package/dist/cjs/validators/tracking-plan.js +1682 -0
  48. package/package.json +4 -2
@@ -0,0 +1,861 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.ChordAnalytics = void 0;
60
+ var cdp_js_1 = require("./cdp.js");
61
+ var index_js_1 = require("../validators/index.js");
62
+ var utils_js_1 = require("../utils.js");
63
+ var DEBUG_MODE_STORAGE_KEY = 'chordcommerce/analytics/debug';
64
+ var ChordAnalytics = /** @class */ (function () {
65
+ function ChordAnalytics(options) {
66
+ var _this = this;
67
+ var _a, _b, _c;
68
+ /**
69
+ * Allows snippet.js to detect whether this library has been initialized yet.
70
+ */
71
+ this.initialize = true;
72
+ /**
73
+ * Allows snippet.js to detect whether the snippet has started running yet.
74
+ */
75
+ this.invoked = true;
76
+ /**
77
+ * Middleware to be applied to the event properties
78
+ */
79
+ this.middleware = [];
80
+ /**
81
+ * Promise that resolves when CDP is ready
82
+ */
83
+ this.cdpReadyPromise = null;
84
+ /**
85
+ * Set debug mode for Chord Analytics
86
+ * @param enabled - Whether debug mode should be enabled
87
+ */
88
+ // eslint-disable-next-line class-methods-use-this
89
+ this.setDebugMode = function (enabled) {
90
+ if (window === null || window === void 0 ? void 0 : window.localStorage) {
91
+ window.localStorage.setItem(DEBUG_MODE_STORAGE_KEY, enabled.toString());
92
+ }
93
+ };
94
+ /*
95
+ * Return the CDP instance provided in `options.cdp`.
96
+ */
97
+ this.cdp = function () {
98
+ var _a;
99
+ var a = (_a = _this.options) === null || _a === void 0 ? void 0 : _a.cdp;
100
+ if (typeof a === 'function')
101
+ return a();
102
+ return a;
103
+ };
104
+ /*
105
+ * Return the Chord CDP instance or queue.
106
+ */
107
+ this.ccdp = function () {
108
+ var _a = _this.options, cdpDomain = _a.cdpDomain, cdpWriteKey = _a.cdpWriteKey, namespace = _a.namespace;
109
+ if (!cdpDomain || !cdpWriteKey)
110
+ return null;
111
+ return (window === null || window === void 0 ? void 0 : window["_".concat(namespace)]) || (0, cdp_js_1.cdpQueue)(namespace);
112
+ };
113
+ /*
114
+ * Log a message to the console if `options.enableLogging` is true.
115
+ */
116
+ this.logger = function (message) {
117
+ var optionalParams = [];
118
+ for (var _i = 1; _i < arguments.length; _i++) {
119
+ optionalParams[_i - 1] = arguments[_i];
120
+ }
121
+ if (!_this.options.enableLogging)
122
+ return;
123
+ // eslint-disable-next-line no-console
124
+ console.log.apply(console, __spreadArray([message], optionalParams, false));
125
+ };
126
+ /**
127
+ * Validate the body of a `track` event against the Chord tracking plan.
128
+ */
129
+ this.validate = function (event, props) {
130
+ if (!event) {
131
+ _this.logger('No event name provided');
132
+ return [{ success: false }];
133
+ }
134
+ var schema = event && index_js_1.eventSchemas[event];
135
+ if (!schema)
136
+ return [{ success: true, data: props }];
137
+ return schema.map(function (s) { return s.safeParse(props); });
138
+ };
139
+ /**
140
+ * Generate the event `meta` property.
141
+ */
142
+ this.meta = function () {
143
+ var _a, _b, _c, _d, _e, _f;
144
+ return __assign(__assign({}, _this.options.metadata), { ownership: {
145
+ oms_id: (_b = (_a = _this.options.metadata) === null || _a === void 0 ? void 0 : _a.ownership) === null || _b === void 0 ? void 0 : _b.omsId,
146
+ store_id: (_d = (_c = _this.options.metadata) === null || _c === void 0 ? void 0 : _c.ownership) === null || _d === void 0 ? void 0 : _d.storeId,
147
+ tenant_id: (_f = (_e = _this.options.metadata) === null || _e === void 0 ? void 0 : _e.ownership) === null || _f === void 0 ? void 0 : _f.tenantId,
148
+ }, version: {
149
+ // TODO: make this dynamic
150
+ major: 3,
151
+ minor: 0,
152
+ patch: 0,
153
+ } });
154
+ };
155
+ // eslint-disable-next-line class-methods-use-this
156
+ this.addSourceMiddleware = function (func) {
157
+ _this.middleware.push(func);
158
+ };
159
+ /**
160
+ * Send a `track` event to the CDP with any event name and properties.
161
+ */
162
+ this.track = function (event, props, options) { return __awaiter(_this, void 0, void 0, function () {
163
+ var formattedProps, middlewareProps, searchParams_1, urlSearchParams, searchData_1, finalEventProps;
164
+ var _this = this;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ if (!event)
169
+ this.logger('No event name provided');
170
+ if (!this.cdpReadyPromise) return [3 /*break*/, 2];
171
+ return [4 /*yield*/, this.cdpReadyPromise];
172
+ case 1:
173
+ _a.sent();
174
+ _a.label = 2;
175
+ case 2:
176
+ formattedProps = this.options.stripNull && props ? (0, utils_js_1.pruneNullValues)(props) : props;
177
+ middlewareProps = {};
178
+ if (this.middleware.length > 0) {
179
+ searchParams_1 = typeof window !== 'undefined' ? window.location.search : '';
180
+ urlSearchParams = new URLSearchParams(searchParams_1);
181
+ searchData_1 = Object.fromEntries(urlSearchParams.entries());
182
+ // process middleware synchronously
183
+ this.middleware.forEach(function (func) {
184
+ try {
185
+ var result = func({
186
+ payload: {
187
+ obj: {
188
+ properties: props,
189
+ event: event,
190
+ context: {
191
+ page: {
192
+ search: searchParams_1,
193
+ searchParams: searchData_1,
194
+ },
195
+ },
196
+ },
197
+ },
198
+ next: function (_) { return _; },
199
+ });
200
+ if (result && typeof result === 'object') {
201
+ middlewareProps = __assign(__assign({}, middlewareProps), result);
202
+ }
203
+ }
204
+ catch (error) {
205
+ console.warn('Middleware error:', error);
206
+ }
207
+ });
208
+ }
209
+ finalEventProps = __assign(__assign(__assign({}, formattedProps), middlewareProps), { meta: this.meta() });
210
+ if (this.options.debug) {
211
+ this.validate(event, finalEventProps).forEach(function (valid) {
212
+ if (!valid.success) {
213
+ _this.logger('Chord tracking plan violation', valid.error);
214
+ }
215
+ });
216
+ }
217
+ return [2 /*return*/, new Promise(function (resolve) {
218
+ var cdpPromises = [];
219
+ try {
220
+ var a_1 = _this.ccdp();
221
+ if (a_1 && typeof a_1.track === 'function') {
222
+ cdpPromises.push(new Promise(function (cdpResolve) {
223
+ a_1.track(event, finalEventProps, options, function () { return cdpResolve(); });
224
+ }));
225
+ }
226
+ var b_1 = _this.cdp();
227
+ if (b_1 && typeof b_1.track === 'function') {
228
+ cdpPromises.push(new Promise(function (cdpResolve) {
229
+ b_1.track(event, finalEventProps, options, function () { return cdpResolve(); });
230
+ }));
231
+ }
232
+ if (cdpPromises.length > 0) {
233
+ Promise.allSettled(cdpPromises)
234
+ .then(function () { return resolve(); })
235
+ .catch(function (error) {
236
+ _this.logger(error);
237
+ resolve();
238
+ });
239
+ }
240
+ else {
241
+ resolve();
242
+ }
243
+ }
244
+ catch (error) {
245
+ _this.logger(error);
246
+ resolve();
247
+ }
248
+ })];
249
+ }
250
+ });
251
+ }); };
252
+ /**
253
+ * Send an `identify` event to the CDP with user id and traits.
254
+ */
255
+ this.identify = function () {
256
+ var props = [];
257
+ for (var _i = 0; _i < arguments.length; _i++) {
258
+ props[_i] = arguments[_i];
259
+ }
260
+ return __awaiter(_this, void 0, void 0, function () {
261
+ var identifyPromises, a_2, b_2;
262
+ var _this = this;
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ if (!this.cdpReadyPromise) return [3 /*break*/, 2];
267
+ return [4 /*yield*/, this.cdpReadyPromise];
268
+ case 1:
269
+ _a.sent();
270
+ _a.label = 2;
271
+ case 2:
272
+ try {
273
+ identifyPromises = [];
274
+ a_2 = this.ccdp();
275
+ if (a_2 && typeof a_2.identify === 'function') {
276
+ identifyPromises.push(new Promise(function (resolve) {
277
+ a_2.identify.apply(a_2, __spreadArray(__spreadArray([], props, false), [function () { return resolve(); }], false));
278
+ }));
279
+ }
280
+ b_2 = this.cdp();
281
+ if (b_2 && typeof b_2.identify === 'function') {
282
+ identifyPromises.push(new Promise(function (resolve) {
283
+ b_2.identify.apply(b_2, __spreadArray(__spreadArray([], props, false), [function () { return resolve(); }], false));
284
+ }));
285
+ }
286
+ // We don't return the promise to maintain the void return type
287
+ Promise.allSettled(identifyPromises).then(function (results) {
288
+ _this.logger('identify event sent', results);
289
+ });
290
+ }
291
+ catch (error) {
292
+ this.logger(error);
293
+ }
294
+ return [2 /*return*/];
295
+ }
296
+ });
297
+ });
298
+ };
299
+ /**
300
+ * Send a `page` event to the CDP.
301
+ */
302
+ this.page = function (props) {
303
+ if (props === void 0) { props = {}; }
304
+ return __awaiter(_this, void 0, void 0, function () {
305
+ var pagePromises, a_3, b_3;
306
+ var _this = this;
307
+ return __generator(this, function (_a) {
308
+ switch (_a.label) {
309
+ case 0:
310
+ if (!this.cdpReadyPromise) return [3 /*break*/, 2];
311
+ return [4 /*yield*/, this.cdpReadyPromise];
312
+ case 1:
313
+ _a.sent();
314
+ _a.label = 2;
315
+ case 2:
316
+ try {
317
+ pagePromises = [];
318
+ a_3 = this.ccdp();
319
+ if (a_3 && typeof a_3.page === 'function') {
320
+ pagePromises.push(new Promise(function (resolve) {
321
+ a_3.page(__assign(__assign({}, props), { meta: _this.meta() }), function () { return resolve(); });
322
+ }));
323
+ }
324
+ b_3 = this.cdp();
325
+ if (b_3 && typeof b_3.page === 'function') {
326
+ pagePromises.push(new Promise(function (resolve) {
327
+ b_3.page(__assign(__assign({}, props), { meta: _this.meta() }), function () { return resolve(); });
328
+ }));
329
+ }
330
+ // We don't return the promise to maintain the void return type
331
+ Promise.allSettled(pagePromises).then(function (results) {
332
+ _this.logger('page event sent', results);
333
+ });
334
+ }
335
+ catch (error) {
336
+ this.logger(error);
337
+ }
338
+ return [2 /*return*/];
339
+ }
340
+ });
341
+ });
342
+ };
343
+ this.reset = function () {
344
+ try {
345
+ var resetPromises = [];
346
+ var a_4 = _this.ccdp();
347
+ if (a_4 && typeof a_4.reset === 'function') {
348
+ resetPromises.push(new Promise(function (resolve) {
349
+ a_4.reset(function () { return resolve(); });
350
+ }));
351
+ }
352
+ var b_4 = _this.cdp();
353
+ if (b_4 && typeof b_4.reset === 'function') {
354
+ resetPromises.push(new Promise(function (resolve) {
355
+ b_4.reset(function () { return resolve(); });
356
+ }));
357
+ }
358
+ // We don't return the promise to maintain the return type
359
+ Promise.allSettled(resetPromises).catch(_this.logger);
360
+ }
361
+ catch (error) {
362
+ _this.logger(error);
363
+ }
364
+ };
365
+ // TODO: Add support for props.products
366
+ this.trackCartViewed = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
367
+ var cart, payload, formattedPayload;
368
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
369
+ return __generator(this, function (_l) {
370
+ 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, {
371
+ cart: props === null || props === void 0 ? void 0 : props.cart,
372
+ });
373
+ payload = {
374
+ cart_id: cart === null || cart === void 0 ? void 0 : cart.cart_id,
375
+ currency: cart === null || cart === void 0 ? void 0 : cart.currency,
376
+ products: cart === null || cart === void 0 ? void 0 : cart.products,
377
+ value: cart === null || cart === void 0 ? void 0 : cart.value,
378
+ };
379
+ 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) {
380
+ 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);
381
+ return [2 /*return*/, this.track('Cart Viewed', formattedPayload, options)];
382
+ }
383
+ return [2 /*return*/, this.track('Cart Viewed', payload, options)];
384
+ });
385
+ }); };
386
+ // TODO: Add support for props.products
387
+ this.trackCheckoutStarted = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
388
+ var formatter, checkout, payload, formattedPayload;
389
+ var _a, _b, _c, _d, _e, _f, _g;
390
+ return __generator(this, function (_h) {
391
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.checkoutStarted;
392
+ checkout = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.checkout) === null || _g === void 0 ? void 0 : _g.call(_f, {
393
+ checkout: props === null || props === void 0 ? void 0 : props.checkout,
394
+ });
395
+ payload = checkout;
396
+ if (typeof formatter === 'function') {
397
+ formattedPayload = formatter(props, payload);
398
+ return [2 /*return*/, this.track('Checkout Started', formattedPayload, options)];
399
+ }
400
+ return [2 /*return*/, this.track('Checkout Started', payload, options)];
401
+ });
402
+ }); };
403
+ this.trackCheckoutStepCompleted = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
404
+ var formatter, payload, formattedPayload;
405
+ var _a, _b, _c;
406
+ return __generator(this, function (_d) {
407
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.checkoutStepCompleted;
408
+ payload = {
409
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
410
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
411
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
412
+ step: props === null || props === void 0 ? void 0 : props.step,
413
+ };
414
+ if (typeof formatter === 'function') {
415
+ formattedPayload = formatter(props, payload);
416
+ return [2 /*return*/, this.track('Checkout Step Completed', formattedPayload, options)];
417
+ }
418
+ return [2 /*return*/, this.track('Checkout Step Completed', payload, options)];
419
+ });
420
+ }); };
421
+ this.trackCheckoutStepViewed = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
422
+ var formatter, payload, formattedPayload;
423
+ var _a, _b, _c;
424
+ return __generator(this, function (_d) {
425
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.checkoutStepViewed;
426
+ payload = {
427
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
428
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
429
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
430
+ step: props === null || props === void 0 ? void 0 : props.step,
431
+ };
432
+ if (typeof formatter === 'function') {
433
+ formattedPayload = formatter(props, payload);
434
+ return [2 /*return*/, this.track('Checkout Step Viewed', formattedPayload, options)];
435
+ }
436
+ return [2 /*return*/, this.track('Checkout Step Viewed', payload, options)];
437
+ });
438
+ }); };
439
+ this.trackCouponApplied = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
440
+ var formatter, payload, formattedPayload;
441
+ var _a, _b, _c;
442
+ return __generator(this, function (_d) {
443
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.couponApplied;
444
+ payload = {
445
+ cart_id: props === null || props === void 0 ? void 0 : props.cartId,
446
+ coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
447
+ coupon_name: props === null || props === void 0 ? void 0 : props.couponName,
448
+ discount: props === null || props === void 0 ? void 0 : props.discount,
449
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
450
+ };
451
+ if (typeof formatter === 'function') {
452
+ formattedPayload = formatter(props, payload);
453
+ return [2 /*return*/, this.track('Coupon Applied', formattedPayload, options)];
454
+ }
455
+ return [2 /*return*/, this.track('Coupon Applied', payload, options)];
456
+ });
457
+ }); };
458
+ this.trackCouponDenied = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
459
+ var formatter, payload, formattedPayload;
460
+ var _a, _b, _c;
461
+ return __generator(this, function (_d) {
462
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.couponDenied;
463
+ payload = {
464
+ cart_id: props === null || props === void 0 ? void 0 : props.cartId,
465
+ coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
466
+ coupon_name: props === null || props === void 0 ? void 0 : props.couponName,
467
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
468
+ reason: props === null || props === void 0 ? void 0 : props.reason,
469
+ };
470
+ if (typeof formatter === 'function') {
471
+ formattedPayload = formatter(props, payload);
472
+ return [2 /*return*/, this.track('Coupon Denied', formattedPayload, options)];
473
+ }
474
+ return [2 /*return*/, this.track('Coupon Denied', payload, options)];
475
+ });
476
+ }); };
477
+ this.trackCouponEntered = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
478
+ var formatter, payload, formattedPayload;
479
+ var _a, _b, _c;
480
+ return __generator(this, function (_d) {
481
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.couponEntered;
482
+ payload = {
483
+ cart_id: props === null || props === void 0 ? void 0 : props.cartId,
484
+ coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
485
+ coupon_name: props === null || props === void 0 ? void 0 : props.couponName,
486
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
487
+ };
488
+ if (typeof formatter === 'function') {
489
+ formattedPayload = formatter(props, payload);
490
+ return [2 /*return*/, this.track('Coupon Entered', formattedPayload, options)];
491
+ }
492
+ return [2 /*return*/, this.track('Coupon Entered', payload, options)];
493
+ });
494
+ }); };
495
+ this.trackCouponRemoved = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
496
+ var formatter, payload, formattedPayload;
497
+ var _a, _b, _c;
498
+ return __generator(this, function (_d) {
499
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.couponRemoved;
500
+ payload = {
501
+ cart_id: props === null || props === void 0 ? void 0 : props.cartId,
502
+ coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
503
+ coupon_name: props === null || props === void 0 ? void 0 : props.couponName,
504
+ discount: props === null || props === void 0 ? void 0 : props.discount,
505
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
506
+ };
507
+ if (typeof formatter === 'function') {
508
+ formattedPayload = formatter(props, payload);
509
+ return [2 /*return*/, this.track('Coupon Removed', formattedPayload, options)];
510
+ }
511
+ return [2 /*return*/, this.track('Coupon Removed', payload, options)];
512
+ });
513
+ }); };
514
+ this.trackEmailCaptured = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
515
+ var formatter, payload, formattedPayload;
516
+ var _a, _b, _c;
517
+ return __generator(this, function (_d) {
518
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.emailCaptured;
519
+ payload = {
520
+ email: props === null || props === void 0 ? void 0 : props.email,
521
+ placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
522
+ placement_page: props === null || props === void 0 ? void 0 : props.placementPage,
523
+ };
524
+ if (typeof formatter === 'function') {
525
+ formattedPayload = formatter(props, payload);
526
+ return [2 /*return*/, this.track('Email Captured', formattedPayload, options)];
527
+ }
528
+ return [2 /*return*/, this.track('Email Captured', payload, options)];
529
+ });
530
+ }); };
531
+ this.trackProductAdded = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
532
+ var formatter, product, cart, quantity, payload, formattedPayload;
533
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
534
+ return __generator(this, function (_o) {
535
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productAdded;
536
+ product = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.product) === null || _g === void 0 ? void 0 : _g.call(_f, props === null || props === void 0 ? void 0 : props.product);
537
+ cart = (_l = (_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.cart) === null || _l === void 0 ? void 0 : _l.call(_k, {
538
+ cart: props === null || props === void 0 ? void 0 : props.cart,
539
+ });
540
+ quantity = ((_m = props === null || props === void 0 ? void 0 : props.product) === null || _m === void 0 ? void 0 : _m.quantity) || 1;
541
+ payload = __assign(__assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, products: [__assign(__assign({}, product), { quantity: quantity })], total: product.price * (quantity || 1), value: product.price * (quantity || 1) });
542
+ if (typeof formatter === 'function') {
543
+ formattedPayload = formatter(props, payload);
544
+ return [2 /*return*/, this.track('Product Added', formattedPayload, options)];
545
+ }
546
+ return [2 /*return*/, this.track('Product Added', payload, options)];
547
+ });
548
+ }); };
549
+ this.trackProductClicked = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
550
+ var formatter, product, cart, quantity, payload, formattedPayload;
551
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
552
+ return __generator(this, function (_p) {
553
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productClicked;
554
+ product = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.product) === null || _g === void 0 ? void 0 : _g.call(_f, props === null || props === void 0 ? void 0 : props.product);
555
+ cart = (_l = (_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.cart) === null || _l === void 0 ? void 0 : _l.call(_k, {
556
+ cart: props === null || props === void 0 ? void 0 : props.cart,
557
+ });
558
+ quantity = ((_m = props === null || props === void 0 ? void 0 : props.product) === null || _m === void 0 ? void 0 : _m.quantity) || 1;
559
+ payload = __assign(__assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_o = props === null || props === void 0 ? void 0 : props.listId) === null || _o === void 0 ? void 0 : _o.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [__assign(__assign({}, product), { quantity: quantity })] });
560
+ if (typeof formatter === 'function') {
561
+ formattedPayload = formatter(props, payload);
562
+ return [2 /*return*/, this.track('Product Clicked', formattedPayload, options)];
563
+ }
564
+ return [2 /*return*/, this.track('Product Clicked', payload, options)];
565
+ });
566
+ }); };
567
+ this.trackVariantClicked = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
568
+ var formatter, product, cart, quantity, payload, formattedPayload;
569
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
570
+ return __generator(this, function (_o) {
571
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.variantClicked;
572
+ product = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.product) === null || _g === void 0 ? void 0 : _g.call(_f, props === null || props === void 0 ? void 0 : props.product);
573
+ cart = (_l = (_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.cart) === null || _l === void 0 ? void 0 : _l.call(_k, {
574
+ cart: props === null || props === void 0 ? void 0 : props.cart,
575
+ });
576
+ quantity = ((_m = props === null || props === void 0 ? void 0 : props.product) === null || _m === void 0 ? void 0 : _m.quantity) || 1;
577
+ payload = __assign(__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 });
578
+ if (typeof formatter === 'function') {
579
+ formattedPayload = formatter(props, payload);
580
+ return [2 /*return*/, this.track('Variant Clicked', formattedPayload, options)];
581
+ }
582
+ return [2 /*return*/, this.track('Variant Clicked', payload, options)];
583
+ });
584
+ }); };
585
+ this.trackProductListFiltered = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
586
+ var formatter, payload, formattedPayload;
587
+ var _a, _b, _c, _d, _e;
588
+ return __generator(this, function (_f) {
589
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productListFiltered;
590
+ payload = {
591
+ category: props === null || props === void 0 ? void 0 : props.category,
592
+ filters: props === null || props === void 0 ? void 0 : props.filters,
593
+ list_id: (_d = props === null || props === void 0 ? void 0 : props.listId) === null || _d === void 0 ? void 0 : _d.toString(),
594
+ item_list_id: (_e = props === null || props === void 0 ? void 0 : props.listId) === null || _e === void 0 ? void 0 : _e.toString(),
595
+ item_list_name: props === null || props === void 0 ? void 0 : props.listName,
596
+ sorts: props === null || props === void 0 ? void 0 : props.sorts,
597
+ };
598
+ if (typeof formatter === 'function') {
599
+ formattedPayload = formatter(props, payload);
600
+ return [2 /*return*/, this.track('Product List Filtered', formattedPayload, options)];
601
+ }
602
+ return [2 /*return*/, this.track('Product List Filtered', payload, options)];
603
+ });
604
+ }); };
605
+ this.trackProductListViewed = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
606
+ var formatter, payload, formattedPayload;
607
+ var _this = this;
608
+ var _a, _b, _c, _d, _e, _f;
609
+ return __generator(this, function (_g) {
610
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productListViewed;
611
+ payload = {
612
+ category: props === null || props === void 0 ? void 0 : props.category,
613
+ list_id: (_d = props === null || props === void 0 ? void 0 : props.listId) === null || _d === void 0 ? void 0 : _d.toString(),
614
+ item_list_id: (_e = props === null || props === void 0 ? void 0 : props.listId) === null || _e === void 0 ? void 0 : _e.toString(),
615
+ item_list_name: props === null || props === void 0 ? void 0 : props.listName,
616
+ products: (_f = props === null || props === void 0 ? void 0 : props.products) === null || _f === void 0 ? void 0 : _f.map(function (p, i) {
617
+ var _a, _b, _c, _d;
618
+ 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, __assign(__assign({}, p), { position: i + 1 }));
619
+ }),
620
+ value: 0, // TODO: remove from tracking plan
621
+ };
622
+ if (typeof formatter === 'function') {
623
+ formattedPayload = formatter(props, payload);
624
+ return [2 /*return*/, this.track('Product List Viewed', formattedPayload, options)];
625
+ }
626
+ return [2 /*return*/, this.track('Product List Viewed', payload, options)];
627
+ });
628
+ }); };
629
+ this.trackProductRemoved = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
630
+ var formatter, lineItem, cart, payload, formattedPayload;
631
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
632
+ return __generator(this, function (_r) {
633
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productRemoved;
634
+ lineItem = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.lineItem) === null || _g === void 0 ? void 0 : _g.call(_f, {
635
+ lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
636
+ });
637
+ cart = (_l = (_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.cart) === null || _l === void 0 ? void 0 : _l.call(_k, {
638
+ cart: props === null || props === void 0 ? void 0 : props.cart,
639
+ });
640
+ payload = __assign(__assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_m = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _m !== void 0 ? _m : 0) * ((_o = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _o !== void 0 ? _o : 1), value: ((_p = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _p !== void 0 ? _p : 0) * ((_q = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _q !== void 0 ? _q : 1) });
641
+ if (typeof formatter === 'function') {
642
+ formattedPayload = formatter(props, payload);
643
+ return [2 /*return*/, this.track('Product Removed', formattedPayload, options)];
644
+ }
645
+ return [2 /*return*/, this.track('Product Removed', payload, options)];
646
+ });
647
+ }); };
648
+ this.trackProductViewed = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
649
+ var formatter, product, cart, quantity, payload, formattedPayload;
650
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
651
+ return __generator(this, function (_p) {
652
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productViewed;
653
+ product = (_g = (_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.formatters) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.product) === null || _g === void 0 ? void 0 : _g.call(_f, props === null || props === void 0 ? void 0 : props.product);
654
+ cart = (_l = (_k = (_j = (_h = this.options) === null || _h === void 0 ? void 0 : _h.formatters) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.cart) === null || _l === void 0 ? void 0 : _l.call(_k, {
655
+ cart: props === null || props === void 0 ? void 0 : props.cart,
656
+ });
657
+ quantity = ((_m = props === null || props === void 0 ? void 0 : props.product) === null || _m === void 0 ? void 0 : _m.quantity) || 1;
658
+ payload = __assign(__assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, products: [__assign(__assign({}, product), { quantity: quantity })], value: product.price * (((_o = props === null || props === void 0 ? void 0 : props.product) === null || _o === void 0 ? void 0 : _o.quantity) || 1) });
659
+ if (typeof formatter === 'function') {
660
+ formattedPayload = formatter(props, payload);
661
+ return [2 /*return*/, this.track('Product Viewed', formattedPayload, options)];
662
+ }
663
+ return [2 /*return*/, this.track('Product Viewed', payload, options)];
664
+ });
665
+ }); };
666
+ this.trackProductsSearched = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
667
+ var formatter, payload, formattedPayload;
668
+ var _a, _b, _c, _d;
669
+ return __generator(this, function (_e) {
670
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.productsSearched;
671
+ payload = {
672
+ currency: props === null || props === void 0 ? void 0 : props.currency,
673
+ price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
674
+ product_id: (_d = props === null || props === void 0 ? void 0 : props.productId) === null || _d === void 0 ? void 0 : _d.toString(),
675
+ quantity: props === null || props === void 0 ? void 0 : props.quantity,
676
+ query: props === null || props === void 0 ? void 0 : props.query,
677
+ };
678
+ if (typeof formatter === 'function') {
679
+ formattedPayload = formatter(props, payload);
680
+ return [2 /*return*/, this.track('Products Searched', formattedPayload, options)];
681
+ }
682
+ return [2 /*return*/, this.track('Products Searched', payload, options)];
683
+ });
684
+ }); };
685
+ this.trackSignedIn = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
686
+ var formatter, payload, formattedPayload;
687
+ var _a, _b, _c;
688
+ return __generator(this, function (_d) {
689
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.signedIn;
690
+ payload = {
691
+ email: props === null || props === void 0 ? void 0 : props.email,
692
+ method: props === null || props === void 0 ? void 0 : props.method,
693
+ };
694
+ if (typeof formatter === 'function') {
695
+ formattedPayload = formatter(props, payload);
696
+ return [2 /*return*/, this.track('Signed In', formattedPayload, options)];
697
+ }
698
+ return [2 /*return*/, this.track('Signed In', payload, options)];
699
+ });
700
+ }); };
701
+ this.trackSignedOut = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
702
+ var formatter, payload, formattedPayload;
703
+ var _a, _b, _c;
704
+ return __generator(this, function (_d) {
705
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.signedOut;
706
+ payload = {
707
+ email: props === null || props === void 0 ? void 0 : props.email,
708
+ };
709
+ if (typeof formatter === 'function') {
710
+ formattedPayload = formatter(props || {}, payload);
711
+ return [2 /*return*/, this.track('Signed Out', formattedPayload, options)];
712
+ }
713
+ return [2 /*return*/, this.track('Signed Out', payload, options)];
714
+ });
715
+ }); };
716
+ this.trackSignedUp = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
717
+ var formatter, payload, formattedPayload;
718
+ var _a, _b, _c;
719
+ return __generator(this, function (_d) {
720
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.signedUp;
721
+ payload = {
722
+ email: props === null || props === void 0 ? void 0 : props.email,
723
+ method: props === null || props === void 0 ? void 0 : props.method,
724
+ };
725
+ if (typeof formatter === 'function') {
726
+ formattedPayload = formatter(props || {}, payload);
727
+ return [2 /*return*/, this.track('Signed Up', formattedPayload, options)];
728
+ }
729
+ return [2 /*return*/, this.track('Signed Up', payload, options)];
730
+ });
731
+ }); };
732
+ this.trackLoginStarted = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
733
+ var formatter, payload, formattedPayload;
734
+ var _a, _b, _c;
735
+ return __generator(this, function (_d) {
736
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.loginStarted;
737
+ payload = {
738
+ email: props === null || props === void 0 ? void 0 : props.email,
739
+ };
740
+ if (typeof formatter === 'function') {
741
+ formattedPayload = formatter(props, payload);
742
+ return [2 /*return*/, this.track('Login Started', formattedPayload, options)];
743
+ }
744
+ return [2 /*return*/, this.track('Login Started', payload, options)];
745
+ });
746
+ }); };
747
+ this.trackSubscriptionCancelled = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
748
+ var formatter, payload, formattedPayload;
749
+ var _this = this;
750
+ var _a, _b, _c, _d;
751
+ return __generator(this, function (_e) {
752
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.subscriptionCancelled;
753
+ payload = {
754
+ actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
755
+ address: props === null || props === void 0 ? void 0 : props.address,
756
+ brand: props === null || props === void 0 ? void 0 : props.brand,
757
+ email: props === null || props === void 0 ? void 0 : props.email,
758
+ end_date: props === null || props === void 0 ? void 0 : props.endDate,
759
+ interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
760
+ interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
761
+ products: (_d = props === null || props === void 0 ? void 0 : props.products) === null || _d === void 0 ? void 0 : _d.map(function (p, i) {
762
+ var _a, _b, _c, _d;
763
+ 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, __assign(__assign({}, p), { position: i + 1 }));
764
+ }),
765
+ state: props === null || props === void 0 ? void 0 : props.state,
766
+ subscription_id: props === null || props === void 0 ? void 0 : props.subscriptionId,
767
+ currency: props === null || props === void 0 ? void 0 : props.currency,
768
+ };
769
+ if (typeof formatter === 'function') {
770
+ formattedPayload = formatter(props || {}, payload);
771
+ return [2 /*return*/, this.track('Subscription Cancelled', formattedPayload, options)];
772
+ }
773
+ return [2 /*return*/, this.track('Subscription Cancelled', payload, options)];
774
+ });
775
+ }); };
776
+ this.trackNavigationClicked = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
777
+ var formatter, payload, formattedPayload;
778
+ var _a, _b, _c;
779
+ return __generator(this, function (_d) {
780
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.navigationClicked;
781
+ payload = {
782
+ category: props === null || props === void 0 ? void 0 : props.category,
783
+ label: props === null || props === void 0 ? void 0 : props.label,
784
+ navigation_placement: props === null || props === void 0 ? void 0 : props.navigationPlacement,
785
+ navigation_title: props === null || props === void 0 ? void 0 : props.navigationTitle,
786
+ navigation_url: props === null || props === void 0 ? void 0 : props.navigationUrl,
787
+ };
788
+ if (typeof formatter === 'function') {
789
+ formattedPayload = formatter(props, payload);
790
+ return [2 /*return*/, this.track('Navigation Clicked', formattedPayload, options)];
791
+ }
792
+ return [2 /*return*/, this.track('Navigation Clicked', payload, options)];
793
+ });
794
+ }); };
795
+ this.trackPaymentInfoEntered = function (props, options) { return __awaiter(_this, void 0, void 0, function () {
796
+ var formatter, payload, formattedPayload;
797
+ var _this = this;
798
+ var _a, _b, _c, _d;
799
+ return __generator(this, function (_e) {
800
+ formatter = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.formatters) === null || _b === void 0 ? void 0 : _b.events) === null || _c === void 0 ? void 0 : _c.paymentInfoEntered;
801
+ payload = {
802
+ checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
803
+ coupon: props === null || props === void 0 ? void 0 : props.coupon,
804
+ currency: props === null || props === void 0 ? void 0 : props.currency,
805
+ order_id: props === null || props === void 0 ? void 0 : props.orderId,
806
+ payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
807
+ products: (_d = props === null || props === void 0 ? void 0 : props.products) === null || _d === void 0 ? void 0 : _d.map(function (p, i) {
808
+ var _a, _b, _c, _d;
809
+ 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, __assign(__assign({}, p), { position: i + 1 }));
810
+ }),
811
+ shipping_method: props === null || props === void 0 ? void 0 : props.shippingMethod,
812
+ step: props === null || props === void 0 ? void 0 : props.step,
813
+ value: props === null || props === void 0 ? void 0 : props.value,
814
+ };
815
+ if (typeof formatter === 'function') {
816
+ formattedPayload = formatter(props, payload);
817
+ return [2 /*return*/, this.track('Payment Info Entered', formattedPayload, options)];
818
+ }
819
+ return [2 /*return*/, this.track('Payment Info Entered', payload, options)];
820
+ });
821
+ }); };
822
+ var debug = ((_a = window === null || window === void 0 ? void 0 : window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(DEBUG_MODE_STORAGE_KEY)) === 'true';
823
+ var defaults = {
824
+ debug: debug,
825
+ enableLogging: debug,
826
+ namespace: 'chord',
827
+ stripNull: true,
828
+ };
829
+ this.options = __assign(__assign({}, defaults), options);
830
+ if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.cdpDomain) && ((_c = this.options) === null || _c === void 0 ? void 0 : _c.cdpWriteKey) && window) {
831
+ window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
832
+ this.initializeCdp();
833
+ }
834
+ }
835
+ /**
836
+ * Initialize CDP snippet and wait for it to be ready
837
+ */
838
+ ChordAnalytics.prototype.initializeCdp = function () {
839
+ return __awaiter(this, void 0, void 0, function () {
840
+ var error_1;
841
+ return __generator(this, function (_a) {
842
+ switch (_a.label) {
843
+ case 0:
844
+ _a.trys.push([0, 2, , 3]);
845
+ this.cdpReadyPromise = (0, cdp_js_1.addCdpSnippet)(this.options);
846
+ return [4 /*yield*/, this.cdpReadyPromise];
847
+ case 1:
848
+ _a.sent();
849
+ return [3 /*break*/, 3];
850
+ case 2:
851
+ error_1 = _a.sent();
852
+ console.error('CDP initialization failed:', error_1);
853
+ return [3 /*break*/, 3];
854
+ case 3: return [2 /*return*/];
855
+ }
856
+ });
857
+ });
858
+ };
859
+ return ChordAnalytics;
860
+ }());
861
+ exports.ChordAnalytics = ChordAnalytics;