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