@chordcommerce/analytics 1.22.0-beta.2 → 1.22.0-beta.3
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/cjs/client/index.js +7 -5
- package/dist/cjs/types/client.d.ts +3 -3
- package/dist/client/index.js +89 -87
- package/dist/types/client.d.ts +3 -3
- package/package.json +1 -1
package/dist/cjs/client/index.js
CHANGED
|
@@ -70,7 +70,7 @@ var CONSENT_QUEUE_MAX_EVENTS = 50; // Max number of events to queue
|
|
|
70
70
|
var ChordAnalytics = /** @class */ (function () {
|
|
71
71
|
function ChordAnalytics(options) {
|
|
72
72
|
var _this = this;
|
|
73
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
73
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
74
74
|
/**
|
|
75
75
|
* Allows snippet.js to detect whether this library has been initialized yet.
|
|
76
76
|
*/
|
|
@@ -1447,15 +1447,17 @@ var ChordAnalytics = /** @class */ (function () {
|
|
|
1447
1447
|
window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
|
|
1448
1448
|
this.initializeCdp();
|
|
1449
1449
|
}
|
|
1450
|
-
// Set up web pixel listener:
|
|
1451
|
-
//
|
|
1452
|
-
|
|
1450
|
+
// Set up web pixel listener: always enabled unless explicitly disabled.
|
|
1451
|
+
// The listener only processes messages with source === 'chord-web-pixel',
|
|
1452
|
+
// so it's safe to enable on non-Shopify sites (no matching messages).
|
|
1453
|
+
var shouldEnableWebPixel = ((_d = this.options) === null || _d === void 0 ? void 0 : _d.enableWebPixelListener) !== false &&
|
|
1454
|
+
typeof window !== 'undefined';
|
|
1453
1455
|
if (shouldEnableWebPixel) {
|
|
1454
1456
|
this.setupWebPixelListener();
|
|
1455
1457
|
}
|
|
1456
1458
|
// Sync identifiers to cart: explicit true/false takes precedence,
|
|
1457
1459
|
// otherwise auto-detect by checking for window.Shopify.shop (Liquid storefront)
|
|
1458
|
-
var shouldEnableIdentifierSync = (
|
|
1460
|
+
var shouldEnableIdentifierSync = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.enableIdentifierSync) !== null && _f !== void 0 ? _f : (typeof window !== 'undefined' && !!((_g = window.Shopify) === null || _g === void 0 ? void 0 : _g.shop));
|
|
1459
1461
|
if (shouldEnableIdentifierSync) {
|
|
1460
1462
|
this.syncIdentifiersToCart();
|
|
1461
1463
|
}
|
|
@@ -36,9 +36,9 @@ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
|
|
|
36
36
|
enableLogging?: boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Controls the postMessage listener for events from the Shopify Custom Web
|
|
39
|
-
* Pixel sandbox.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Pixel sandbox. Enabled by default in browser environments. The listener
|
|
40
|
+
* only processes messages with source === 'chord-web-pixel', so it is safe
|
|
41
|
+
* to leave enabled on non-Shopify sites. Set to false to explicitly disable.
|
|
42
42
|
*/
|
|
43
43
|
enableWebPixelListener?: boolean;
|
|
44
44
|
/**
|
package/dist/client/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const CONSENT_QUEUE_MAX_SIZE_BYTES = 100 * 1024; // 100KB max queue size
|
|
|
19
19
|
const CONSENT_QUEUE_MAX_EVENTS = 50; // Max number of events to queue
|
|
20
20
|
export class ChordAnalytics {
|
|
21
21
|
constructor(options) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
23
|
/**
|
|
24
24
|
* Allows snippet.js to detect whether this library has been initialized yet.
|
|
25
25
|
*/
|
|
@@ -586,7 +586,7 @@ export class ChordAnalytics {
|
|
|
586
586
|
});
|
|
587
587
|
});
|
|
588
588
|
this.reset = () => __awaiter(this, void 0, void 0, function* () {
|
|
589
|
-
var
|
|
589
|
+
var _h;
|
|
590
590
|
try {
|
|
591
591
|
this.resetInProgress = true;
|
|
592
592
|
const a = this.ccdp();
|
|
@@ -603,12 +603,12 @@ export class ChordAnalytics {
|
|
|
603
603
|
// eslint-disable-next-line
|
|
604
604
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
605
605
|
try {
|
|
606
|
-
const userState = ((
|
|
606
|
+
const userState = ((_h = a === null || a === void 0 ? void 0 : a.user) === null || _h === void 0 ? void 0 : _h.call(a)) || {};
|
|
607
607
|
if (userState.userId === null || userState.userId === undefined) {
|
|
608
608
|
break;
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
|
-
catch (
|
|
611
|
+
catch (_j) {
|
|
612
612
|
break;
|
|
613
613
|
}
|
|
614
614
|
attempts++;
|
|
@@ -717,8 +717,8 @@ export class ChordAnalytics {
|
|
|
717
717
|
});
|
|
718
718
|
// TODO: Add support for props.products
|
|
719
719
|
this.trackCartViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
720
|
-
var _m, _o, _p, _q, _r, _s, _t, _u
|
|
721
|
-
const cart = (
|
|
720
|
+
var _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
721
|
+
const cart = (_o = (_m = (_l = (_k = this.options) === null || _k === void 0 ? void 0 : _k.formatters) === null || _l === void 0 ? void 0 : _l.objects) === null || _m === void 0 ? void 0 : _m.cart) === null || _o === void 0 ? void 0 : _o.call(_m, {
|
|
722
722
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
723
723
|
});
|
|
724
724
|
const payload = {
|
|
@@ -727,17 +727,17 @@ export class ChordAnalytics {
|
|
|
727
727
|
products: cart === null || cart === void 0 ? void 0 : cart.products,
|
|
728
728
|
value: cart === null || cart === void 0 ? void 0 : cart.value,
|
|
729
729
|
};
|
|
730
|
-
if ((
|
|
731
|
-
const formattedPayload = (
|
|
730
|
+
if ((_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.cartViewed) {
|
|
731
|
+
const formattedPayload = (_u = (_t = (_s = this.options) === null || _s === void 0 ? void 0 : _s.formatters) === null || _t === void 0 ? void 0 : _t.events) === null || _u === void 0 ? void 0 : _u.cartViewed(props, payload);
|
|
732
732
|
return this.track('Cart Viewed', formattedPayload, options);
|
|
733
733
|
}
|
|
734
734
|
return this.track('Cart Viewed', payload, options);
|
|
735
735
|
});
|
|
736
736
|
// TODO: Add support for props.products
|
|
737
737
|
this.trackCheckoutStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
738
|
-
var _x, _y, _z, _0, _1
|
|
739
|
-
const formatter = (
|
|
740
|
-
const checkout = (
|
|
738
|
+
var _v, _w, _x, _y, _z, _0, _1;
|
|
739
|
+
const formatter = (_x = (_w = (_v = this.options) === null || _v === void 0 ? void 0 : _v.formatters) === null || _w === void 0 ? void 0 : _w.events) === null || _x === void 0 ? void 0 : _x.checkoutStarted;
|
|
740
|
+
const checkout = (_1 = (_0 = (_z = (_y = this.options) === null || _y === void 0 ? void 0 : _y.formatters) === null || _z === void 0 ? void 0 : _z.objects) === null || _0 === void 0 ? void 0 : _0.checkout) === null || _1 === void 0 ? void 0 : _1.call(_0, {
|
|
741
741
|
checkout: props === null || props === void 0 ? void 0 : props.checkout,
|
|
742
742
|
});
|
|
743
743
|
const payload = checkout;
|
|
@@ -748,8 +748,8 @@ export class ChordAnalytics {
|
|
|
748
748
|
return this.track('Checkout Started', payload, options);
|
|
749
749
|
});
|
|
750
750
|
this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
751
|
-
var
|
|
752
|
-
const formatter = (
|
|
751
|
+
var _2, _3, _4;
|
|
752
|
+
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.checkoutStepCompleted;
|
|
753
753
|
const payload = {
|
|
754
754
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
755
755
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -763,8 +763,8 @@ export class ChordAnalytics {
|
|
|
763
763
|
return this.track('Checkout Step Completed', payload, options);
|
|
764
764
|
});
|
|
765
765
|
this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
766
|
-
var
|
|
767
|
-
const formatter = (
|
|
766
|
+
var _5, _6, _7;
|
|
767
|
+
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.checkoutStepViewed;
|
|
768
768
|
const payload = {
|
|
769
769
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
770
770
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -778,8 +778,8 @@ export class ChordAnalytics {
|
|
|
778
778
|
return this.track('Checkout Step Viewed', payload, options);
|
|
779
779
|
});
|
|
780
780
|
this.trackCouponApplied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
781
|
-
var
|
|
782
|
-
const formatter = (
|
|
781
|
+
var _8, _9, _10;
|
|
782
|
+
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.couponApplied;
|
|
783
783
|
const payload = {
|
|
784
784
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
785
785
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -794,8 +794,8 @@ export class ChordAnalytics {
|
|
|
794
794
|
return this.track('Coupon Applied', payload, options);
|
|
795
795
|
});
|
|
796
796
|
this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
var
|
|
798
|
-
const formatter = (
|
|
797
|
+
var _11, _12, _13;
|
|
798
|
+
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.couponDenied;
|
|
799
799
|
const payload = {
|
|
800
800
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
801
801
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -810,8 +810,8 @@ export class ChordAnalytics {
|
|
|
810
810
|
return this.track('Coupon Denied', payload, options);
|
|
811
811
|
});
|
|
812
812
|
this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
813
|
-
var
|
|
814
|
-
const formatter = (
|
|
813
|
+
var _14, _15, _16;
|
|
814
|
+
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.couponEntered;
|
|
815
815
|
const payload = {
|
|
816
816
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
817
817
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -825,8 +825,8 @@ export class ChordAnalytics {
|
|
|
825
825
|
return this.track('Coupon Entered', payload, options);
|
|
826
826
|
});
|
|
827
827
|
this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
828
|
-
var
|
|
829
|
-
const formatter = (
|
|
828
|
+
var _17, _18, _19;
|
|
829
|
+
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.couponRemoved;
|
|
830
830
|
const payload = {
|
|
831
831
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
832
832
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -841,8 +841,8 @@ export class ChordAnalytics {
|
|
|
841
841
|
return this.track('Coupon Removed', payload, options);
|
|
842
842
|
});
|
|
843
843
|
this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
844
|
-
var
|
|
845
|
-
const formatter = (
|
|
844
|
+
var _20, _21, _22;
|
|
845
|
+
const formatter = (_22 = (_21 = (_20 = this.options) === null || _20 === void 0 ? void 0 : _20.formatters) === null || _21 === void 0 ? void 0 : _21.events) === null || _22 === void 0 ? void 0 : _22.emailCaptured;
|
|
846
846
|
const payload = {
|
|
847
847
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
848
848
|
placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
|
|
@@ -855,13 +855,13 @@ export class ChordAnalytics {
|
|
|
855
855
|
return this.track('Email Captured', payload, options);
|
|
856
856
|
});
|
|
857
857
|
this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
858
|
-
var _25, _26, _27, _28, _29, _30, _31, _32, _33, _34
|
|
859
|
-
const formatter = (
|
|
860
|
-
const product = (
|
|
861
|
-
const cart = (
|
|
858
|
+
var _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34;
|
|
859
|
+
const formatter = (_25 = (_24 = (_23 = this.options) === null || _23 === void 0 ? void 0 : _23.formatters) === null || _24 === void 0 ? void 0 : _24.events) === null || _25 === void 0 ? void 0 : _25.productAdded;
|
|
860
|
+
const product = (_29 = (_28 = (_27 = (_26 = this.options) === null || _26 === void 0 ? void 0 : _26.formatters) === null || _27 === void 0 ? void 0 : _27.objects) === null || _28 === void 0 ? void 0 : _28.product) === null || _29 === void 0 ? void 0 : _29.call(_28, props === null || props === void 0 ? void 0 : props.product);
|
|
861
|
+
const cart = (_33 = (_32 = (_31 = (_30 = this.options) === null || _30 === void 0 ? void 0 : _30.formatters) === null || _31 === void 0 ? void 0 : _31.objects) === null || _32 === void 0 ? void 0 : _32.cart) === null || _33 === void 0 ? void 0 : _33.call(_32, {
|
|
862
862
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
863
863
|
});
|
|
864
|
-
const quantity = ((
|
|
864
|
+
const quantity = ((_34 = props === null || props === void 0 ? void 0 : props.product) === null || _34 === void 0 ? void 0 : _34.quantity) || 1;
|
|
865
865
|
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) });
|
|
866
866
|
if (typeof formatter === 'function') {
|
|
867
867
|
const formattedPayload = formatter(props, payload);
|
|
@@ -870,14 +870,14 @@ export class ChordAnalytics {
|
|
|
870
870
|
return this.track('Product Added', payload, options);
|
|
871
871
|
});
|
|
872
872
|
this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
873
|
-
var _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47
|
|
874
|
-
const formatter = (
|
|
875
|
-
const product = (
|
|
876
|
-
const cart = (
|
|
873
|
+
var _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47;
|
|
874
|
+
const formatter = (_37 = (_36 = (_35 = this.options) === null || _35 === void 0 ? void 0 : _35.formatters) === null || _36 === void 0 ? void 0 : _36.events) === null || _37 === void 0 ? void 0 : _37.productClicked;
|
|
875
|
+
const product = (_41 = (_40 = (_39 = (_38 = this.options) === null || _38 === void 0 ? void 0 : _38.formatters) === null || _39 === void 0 ? void 0 : _39.objects) === null || _40 === void 0 ? void 0 : _40.product) === null || _41 === void 0 ? void 0 : _41.call(_40, props === null || props === void 0 ? void 0 : props.product);
|
|
876
|
+
const cart = (_45 = (_44 = (_43 = (_42 = this.options) === null || _42 === void 0 ? void 0 : _42.formatters) === null || _43 === void 0 ? void 0 : _43.objects) === null || _44 === void 0 ? void 0 : _44.cart) === null || _45 === void 0 ? void 0 : _45.call(_44, {
|
|
877
877
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
878
878
|
});
|
|
879
|
-
const quantity = ((
|
|
880
|
-
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (
|
|
879
|
+
const quantity = ((_46 = props === null || props === void 0 ? void 0 : props.product) === null || _46 === void 0 ? void 0 : _46.quantity) || 1;
|
|
880
|
+
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_47 = props === null || props === void 0 ? void 0 : props.listId) === null || _47 === void 0 ? void 0 : _47.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
|
|
881
881
|
if (typeof formatter === 'function') {
|
|
882
882
|
const formattedPayload = formatter(props, payload);
|
|
883
883
|
return this.track('Product Clicked', formattedPayload, options);
|
|
@@ -885,13 +885,13 @@ export class ChordAnalytics {
|
|
|
885
885
|
return this.track('Product Clicked', payload, options);
|
|
886
886
|
});
|
|
887
887
|
this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
888
|
-
var _50, _51, _52, _53, _54, _55, _56, _57, _58, _59
|
|
889
|
-
const formatter = (
|
|
890
|
-
const product = (
|
|
891
|
-
const cart = (
|
|
888
|
+
var _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59;
|
|
889
|
+
const formatter = (_50 = (_49 = (_48 = this.options) === null || _48 === void 0 ? void 0 : _48.formatters) === null || _49 === void 0 ? void 0 : _49.events) === null || _50 === void 0 ? void 0 : _50.variantClicked;
|
|
890
|
+
const product = (_54 = (_53 = (_52 = (_51 = this.options) === null || _51 === void 0 ? void 0 : _51.formatters) === null || _52 === void 0 ? void 0 : _52.objects) === null || _53 === void 0 ? void 0 : _53.product) === null || _54 === void 0 ? void 0 : _54.call(_53, props === null || props === void 0 ? void 0 : props.product);
|
|
891
|
+
const cart = (_58 = (_57 = (_56 = (_55 = this.options) === null || _55 === void 0 ? void 0 : _55.formatters) === null || _56 === void 0 ? void 0 : _56.objects) === null || _57 === void 0 ? void 0 : _57.cart) === null || _58 === void 0 ? void 0 : _58.call(_57, {
|
|
892
892
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
893
893
|
});
|
|
894
|
-
const quantity = ((
|
|
894
|
+
const quantity = ((_59 = props === null || props === void 0 ? void 0 : props.product) === null || _59 === void 0 ? void 0 : _59.quantity) || 1;
|
|
895
895
|
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 });
|
|
896
896
|
if (typeof formatter === 'function') {
|
|
897
897
|
const formattedPayload = formatter(props, payload);
|
|
@@ -900,13 +900,13 @@ export class ChordAnalytics {
|
|
|
900
900
|
return this.track('Variant Clicked', payload, options);
|
|
901
901
|
});
|
|
902
902
|
this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
903
|
-
var
|
|
904
|
-
const formatter = (
|
|
903
|
+
var _60, _61, _62, _63, _64;
|
|
904
|
+
const formatter = (_62 = (_61 = (_60 = this.options) === null || _60 === void 0 ? void 0 : _60.formatters) === null || _61 === void 0 ? void 0 : _61.events) === null || _62 === void 0 ? void 0 : _62.productListFiltered;
|
|
905
905
|
const payload = {
|
|
906
906
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
907
907
|
filters: props === null || props === void 0 ? void 0 : props.filters,
|
|
908
|
-
list_id: (
|
|
909
|
-
item_list_id: (
|
|
908
|
+
list_id: (_63 = props === null || props === void 0 ? void 0 : props.listId) === null || _63 === void 0 ? void 0 : _63.toString(),
|
|
909
|
+
item_list_id: (_64 = props === null || props === void 0 ? void 0 : props.listId) === null || _64 === void 0 ? void 0 : _64.toString(),
|
|
910
910
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
911
911
|
sorts: props === null || props === void 0 ? void 0 : props.sorts,
|
|
912
912
|
};
|
|
@@ -917,14 +917,14 @@ export class ChordAnalytics {
|
|
|
917
917
|
return this.track('Product List Filtered', payload, options);
|
|
918
918
|
});
|
|
919
919
|
this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
920
|
-
var _67, _68, _69, _70
|
|
921
|
-
const formatter = (
|
|
920
|
+
var _65, _66, _67, _68, _69, _70;
|
|
921
|
+
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.productListViewed;
|
|
922
922
|
const payload = {
|
|
923
923
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
924
|
-
list_id: (
|
|
925
|
-
item_list_id: (
|
|
924
|
+
list_id: (_68 = props === null || props === void 0 ? void 0 : props.listId) === null || _68 === void 0 ? void 0 : _68.toString(),
|
|
925
|
+
item_list_id: (_69 = props === null || props === void 0 ? void 0 : props.listId) === null || _69 === void 0 ? void 0 : _69.toString(),
|
|
926
926
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
927
|
-
products: (
|
|
927
|
+
products: (_70 = props === null || props === void 0 ? void 0 : props.products) === null || _70 === void 0 ? void 0 : _70.map((p, i) => {
|
|
928
928
|
var _a, _b, _c, _d;
|
|
929
929
|
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 }));
|
|
930
930
|
}),
|
|
@@ -937,8 +937,8 @@ export class ChordAnalytics {
|
|
|
937
937
|
return this.track('Product List Viewed', payload, options);
|
|
938
938
|
});
|
|
939
939
|
this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
940
|
-
var _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85
|
|
941
|
-
const formatter = (
|
|
940
|
+
var _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85;
|
|
941
|
+
const formatter = (_73 = (_72 = (_71 = this.options) === null || _71 === void 0 ? void 0 : _71.formatters) === null || _72 === void 0 ? void 0 : _72.events) === null || _73 === void 0 ? void 0 : _73.productRemoved;
|
|
942
942
|
/*
|
|
943
943
|
const product = this.options?.formatters?.objects?.product?.({
|
|
944
944
|
position: props?.position,
|
|
@@ -947,13 +947,13 @@ export class ChordAnalytics {
|
|
|
947
947
|
variantId: props?.variantId,
|
|
948
948
|
})
|
|
949
949
|
*/
|
|
950
|
-
const lineItem = (
|
|
950
|
+
const lineItem = (_77 = (_76 = (_75 = (_74 = this.options) === null || _74 === void 0 ? void 0 : _74.formatters) === null || _75 === void 0 ? void 0 : _75.objects) === null || _76 === void 0 ? void 0 : _76.lineItem) === null || _77 === void 0 ? void 0 : _77.call(_76, {
|
|
951
951
|
lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
|
|
952
952
|
});
|
|
953
|
-
const cart = (
|
|
953
|
+
const cart = (_81 = (_80 = (_79 = (_78 = this.options) === null || _78 === void 0 ? void 0 : _78.formatters) === null || _79 === void 0 ? void 0 : _79.objects) === null || _80 === void 0 ? void 0 : _80.cart) === null || _81 === void 0 ? void 0 : _81.call(_80, {
|
|
954
954
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
955
955
|
});
|
|
956
|
-
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((
|
|
956
|
+
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_82 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _82 !== void 0 ? _82 : 0) * ((_83 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _83 !== void 0 ? _83 : 1), value: ((_84 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _84 !== void 0 ? _84 : 0) * ((_85 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _85 !== void 0 ? _85 : 1) });
|
|
957
957
|
if (typeof formatter === 'function') {
|
|
958
958
|
const formattedPayload = formatter(props, payload);
|
|
959
959
|
return this.track('Product Removed', formattedPayload, options);
|
|
@@ -961,14 +961,14 @@ export class ChordAnalytics {
|
|
|
961
961
|
return this.track('Product Removed', payload, options);
|
|
962
962
|
});
|
|
963
963
|
this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
964
|
-
var _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98
|
|
965
|
-
const formatter = (
|
|
966
|
-
const product = (
|
|
967
|
-
const cart = (
|
|
964
|
+
var _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98;
|
|
965
|
+
const formatter = (_88 = (_87 = (_86 = this.options) === null || _86 === void 0 ? void 0 : _86.formatters) === null || _87 === void 0 ? void 0 : _87.events) === null || _88 === void 0 ? void 0 : _88.productViewed;
|
|
966
|
+
const product = (_92 = (_91 = (_90 = (_89 = this.options) === null || _89 === void 0 ? void 0 : _89.formatters) === null || _90 === void 0 ? void 0 : _90.objects) === null || _91 === void 0 ? void 0 : _91.product) === null || _92 === void 0 ? void 0 : _92.call(_91, props === null || props === void 0 ? void 0 : props.product);
|
|
967
|
+
const cart = (_96 = (_95 = (_94 = (_93 = this.options) === null || _93 === void 0 ? void 0 : _93.formatters) === null || _94 === void 0 ? void 0 : _94.objects) === null || _95 === void 0 ? void 0 : _95.cart) === null || _96 === void 0 ? void 0 : _96.call(_95, {
|
|
968
968
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
969
969
|
});
|
|
970
|
-
const quantity = ((
|
|
971
|
-
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 * (((
|
|
970
|
+
const quantity = ((_97 = props === null || props === void 0 ? void 0 : props.product) === null || _97 === void 0 ? void 0 : _97.quantity) || 1;
|
|
971
|
+
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 * (((_98 = props === null || props === void 0 ? void 0 : props.product) === null || _98 === void 0 ? void 0 : _98.quantity) || 1) });
|
|
972
972
|
if (typeof formatter === 'function') {
|
|
973
973
|
const formattedPayload = formatter(props, payload);
|
|
974
974
|
return this.track('Product Viewed', formattedPayload, options);
|
|
@@ -976,12 +976,12 @@ export class ChordAnalytics {
|
|
|
976
976
|
return this.track('Product Viewed', payload, options);
|
|
977
977
|
});
|
|
978
978
|
this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
979
|
-
var
|
|
980
|
-
const formatter = (
|
|
979
|
+
var _99, _100, _101, _102;
|
|
980
|
+
const formatter = (_101 = (_100 = (_99 = this.options) === null || _99 === void 0 ? void 0 : _99.formatters) === null || _100 === void 0 ? void 0 : _100.events) === null || _101 === void 0 ? void 0 : _101.productsSearched;
|
|
981
981
|
const payload = {
|
|
982
982
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
983
983
|
price: typeof (props === null || props === void 0 ? void 0 : props.price) !== 'undefined' ? Number(props === null || props === void 0 ? void 0 : props.price) : undefined,
|
|
984
|
-
product_id: (
|
|
984
|
+
product_id: (_102 = props === null || props === void 0 ? void 0 : props.productId) === null || _102 === void 0 ? void 0 : _102.toString(),
|
|
985
985
|
quantity: props === null || props === void 0 ? void 0 : props.quantity,
|
|
986
986
|
query: props === null || props === void 0 ? void 0 : props.query,
|
|
987
987
|
};
|
|
@@ -992,8 +992,8 @@ export class ChordAnalytics {
|
|
|
992
992
|
return this.track('Products Searched', payload, options);
|
|
993
993
|
});
|
|
994
994
|
this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
995
|
-
var
|
|
996
|
-
const formatter = (
|
|
995
|
+
var _103, _104, _105;
|
|
996
|
+
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.signedIn;
|
|
997
997
|
const payload = {
|
|
998
998
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
999
999
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1005,8 +1005,8 @@ export class ChordAnalytics {
|
|
|
1005
1005
|
return this.track('Signed In', payload, options);
|
|
1006
1006
|
});
|
|
1007
1007
|
this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1008
|
-
var
|
|
1009
|
-
const formatter = (
|
|
1008
|
+
var _106, _107, _108;
|
|
1009
|
+
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.signedOut;
|
|
1010
1010
|
const payload = {
|
|
1011
1011
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1012
1012
|
};
|
|
@@ -1017,8 +1017,8 @@ export class ChordAnalytics {
|
|
|
1017
1017
|
return this.track('Signed Out', payload, options);
|
|
1018
1018
|
});
|
|
1019
1019
|
this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1020
|
-
var
|
|
1021
|
-
const formatter = (
|
|
1020
|
+
var _109, _110, _111;
|
|
1021
|
+
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.signedUp;
|
|
1022
1022
|
const payload = {
|
|
1023
1023
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1024
1024
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1030,8 +1030,8 @@ export class ChordAnalytics {
|
|
|
1030
1030
|
return this.track('Signed Up', payload, options);
|
|
1031
1031
|
});
|
|
1032
1032
|
this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
-
var
|
|
1034
|
-
const formatter = (
|
|
1033
|
+
var _112, _113, _114;
|
|
1034
|
+
const formatter = (_114 = (_113 = (_112 = this.options) === null || _112 === void 0 ? void 0 : _112.formatters) === null || _113 === void 0 ? void 0 : _113.events) === null || _114 === void 0 ? void 0 : _114.loginStarted;
|
|
1035
1035
|
const payload = {
|
|
1036
1036
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1037
1037
|
};
|
|
@@ -1042,8 +1042,8 @@ export class ChordAnalytics {
|
|
|
1042
1042
|
return this.track('Login Started', payload, options);
|
|
1043
1043
|
});
|
|
1044
1044
|
this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1045
|
-
var
|
|
1046
|
-
const formatter = (
|
|
1045
|
+
var _115, _116, _117, _118;
|
|
1046
|
+
const formatter = (_117 = (_116 = (_115 = this.options) === null || _115 === void 0 ? void 0 : _115.formatters) === null || _116 === void 0 ? void 0 : _116.events) === null || _117 === void 0 ? void 0 : _117.subscriptionCancelled;
|
|
1047
1047
|
const payload = {
|
|
1048
1048
|
actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
|
|
1049
1049
|
address: props === null || props === void 0 ? void 0 : props.address,
|
|
@@ -1052,7 +1052,7 @@ export class ChordAnalytics {
|
|
|
1052
1052
|
end_date: props === null || props === void 0 ? void 0 : props.endDate,
|
|
1053
1053
|
interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
|
|
1054
1054
|
interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
|
|
1055
|
-
products: (
|
|
1055
|
+
products: (_118 = props === null || props === void 0 ? void 0 : props.products) === null || _118 === void 0 ? void 0 : _118.map((p, i) => {
|
|
1056
1056
|
var _a, _b, _c, _d;
|
|
1057
1057
|
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 }));
|
|
1058
1058
|
}),
|
|
@@ -1067,8 +1067,8 @@ export class ChordAnalytics {
|
|
|
1067
1067
|
return this.track('Subscription Cancelled', payload, options);
|
|
1068
1068
|
});
|
|
1069
1069
|
this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1070
|
-
var
|
|
1071
|
-
const formatter = (
|
|
1070
|
+
var _119, _120, _121;
|
|
1071
|
+
const formatter = (_121 = (_120 = (_119 = this.options) === null || _119 === void 0 ? void 0 : _119.formatters) === null || _120 === void 0 ? void 0 : _120.events) === null || _121 === void 0 ? void 0 : _121.navigationClicked;
|
|
1072
1072
|
const payload = {
|
|
1073
1073
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
1074
1074
|
label: props === null || props === void 0 ? void 0 : props.label,
|
|
@@ -1083,15 +1083,15 @@ export class ChordAnalytics {
|
|
|
1083
1083
|
return this.track('Navigation Clicked', payload, options);
|
|
1084
1084
|
});
|
|
1085
1085
|
this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1086
|
-
var
|
|
1087
|
-
const formatter = (
|
|
1086
|
+
var _122, _123, _124, _125;
|
|
1087
|
+
const formatter = (_124 = (_123 = (_122 = this.options) === null || _122 === void 0 ? void 0 : _122.formatters) === null || _123 === void 0 ? void 0 : _123.events) === null || _124 === void 0 ? void 0 : _124.paymentInfoEntered;
|
|
1088
1088
|
const payload = {
|
|
1089
1089
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
1090
1090
|
coupon: props === null || props === void 0 ? void 0 : props.coupon,
|
|
1091
1091
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
1092
1092
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1093
1093
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
1094
|
-
products: (
|
|
1094
|
+
products: (_125 = props === null || props === void 0 ? void 0 : props.products) === null || _125 === void 0 ? void 0 : _125.map((p, i) => {
|
|
1095
1095
|
var _a, _b, _c, _d;
|
|
1096
1096
|
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 }));
|
|
1097
1097
|
}),
|
|
@@ -1106,8 +1106,8 @@ export class ChordAnalytics {
|
|
|
1106
1106
|
return this.track('Payment Info Entered', payload, options);
|
|
1107
1107
|
});
|
|
1108
1108
|
this.trackOrderCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1109
|
-
var
|
|
1110
|
-
const formatter = (
|
|
1109
|
+
var _126, _127, _128, _129;
|
|
1110
|
+
const formatter = (_128 = (_127 = (_126 = this.options) === null || _126 === void 0 ? void 0 : _126.formatters) === null || _127 === void 0 ? void 0 : _127.events) === null || _128 === void 0 ? void 0 : _128.orderCompleted;
|
|
1111
1111
|
const payload = {
|
|
1112
1112
|
affiliation: props === null || props === void 0 ? void 0 : props.affiliation,
|
|
1113
1113
|
campaign_id: props === null || props === void 0 ? void 0 : props.campaignId,
|
|
@@ -1127,7 +1127,7 @@ export class ChordAnalytics {
|
|
|
1127
1127
|
order_date: props === null || props === void 0 ? void 0 : props.orderDate,
|
|
1128
1128
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1129
1129
|
phone: props === null || props === void 0 ? void 0 : props.phone,
|
|
1130
|
-
products: (
|
|
1130
|
+
products: (_129 = props === null || props === void 0 ? void 0 : props.products) === null || _129 === void 0 ? void 0 : _129.map((p, i) => {
|
|
1131
1131
|
var _a;
|
|
1132
1132
|
return ({
|
|
1133
1133
|
affiliation: p === null || p === void 0 ? void 0 : p.affiliation,
|
|
@@ -1199,15 +1199,17 @@ export class ChordAnalytics {
|
|
|
1199
1199
|
window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
|
|
1200
1200
|
this.initializeCdp();
|
|
1201
1201
|
}
|
|
1202
|
-
// Set up web pixel listener:
|
|
1203
|
-
//
|
|
1204
|
-
|
|
1202
|
+
// Set up web pixel listener: always enabled unless explicitly disabled.
|
|
1203
|
+
// The listener only processes messages with source === 'chord-web-pixel',
|
|
1204
|
+
// so it's safe to enable on non-Shopify sites (no matching messages).
|
|
1205
|
+
const shouldEnableWebPixel = ((_d = this.options) === null || _d === void 0 ? void 0 : _d.enableWebPixelListener) !== false &&
|
|
1206
|
+
typeof window !== 'undefined';
|
|
1205
1207
|
if (shouldEnableWebPixel) {
|
|
1206
1208
|
this.setupWebPixelListener();
|
|
1207
1209
|
}
|
|
1208
1210
|
// Sync identifiers to cart: explicit true/false takes precedence,
|
|
1209
1211
|
// otherwise auto-detect by checking for window.Shopify.shop (Liquid storefront)
|
|
1210
|
-
const shouldEnableIdentifierSync = (
|
|
1212
|
+
const shouldEnableIdentifierSync = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.enableIdentifierSync) !== null && _f !== void 0 ? _f : (typeof window !== 'undefined' && !!((_g = window.Shopify) === null || _g === void 0 ? void 0 : _g.shop));
|
|
1211
1213
|
if (shouldEnableIdentifierSync) {
|
|
1212
1214
|
this.syncIdentifiersToCart();
|
|
1213
1215
|
}
|
package/dist/types/client.d.ts
CHANGED
|
@@ -36,9 +36,9 @@ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
|
|
|
36
36
|
enableLogging?: boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Controls the postMessage listener for events from the Shopify Custom Web
|
|
39
|
-
* Pixel sandbox.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Pixel sandbox. Enabled by default in browser environments. The listener
|
|
40
|
+
* only processes messages with source === 'chord-web-pixel', so it is safe
|
|
41
|
+
* to leave enabled on non-Shopify sites. Set to false to explicitly disable.
|
|
42
42
|
*/
|
|
43
43
|
enableWebPixelListener?: boolean;
|
|
44
44
|
/**
|
package/package.json
CHANGED