@chordcommerce/analytics 1.22.0-beta.2 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/cdp.js +15 -9
- package/dist/cjs/client/index.d.ts +0 -13
- package/dist/cjs/client/index.js +28 -41
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/types/client.d.ts +0 -13
- package/dist/client/cdp.js +15 -8
- package/dist/client/index.d.ts +0 -13
- package/dist/client/index.js +102 -114
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/types/client.d.ts +0 -13
- package/package.json +1 -1
- package/dist/cjs/client/identifiers.d.ts +0 -55
- package/dist/cjs/client/identifiers.js +0 -197
- package/dist/client/identifiers.d.ts +0 -55
- package/dist/client/identifiers.js +0 -135
package/dist/client/index.js
CHANGED
|
@@ -11,7 +11,6 @@ import { addCdpSnippet, cdpQueue } from './cdp.js';
|
|
|
11
11
|
import { addCdpConsent } from './consent/index.js';
|
|
12
12
|
import { eventSchemas } from '../validators/index.js';
|
|
13
13
|
import { pruneNullValues } from '../utils.js';
|
|
14
|
-
import { syncIdentifiersToCart as syncIdentifiers, } from './identifiers.js';
|
|
15
14
|
const DEBUG_MODE_STORAGE_KEY = 'chordcommerce/analytics/debug';
|
|
16
15
|
const CONSENT_QUEUE_STORAGE_KEY = 'chordcommerce/analytics/consent-queue';
|
|
17
16
|
const CONSENT_QUEUE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
@@ -19,7 +18,7 @@ const CONSENT_QUEUE_MAX_SIZE_BYTES = 100 * 1024; // 100KB max queue size
|
|
|
19
18
|
const CONSENT_QUEUE_MAX_EVENTS = 50; // Max number of events to queue
|
|
20
19
|
export class ChordAnalytics {
|
|
21
20
|
constructor(options) {
|
|
22
|
-
var _a, _b, _c, _d
|
|
21
|
+
var _a, _b, _c, _d;
|
|
23
22
|
/**
|
|
24
23
|
* Allows snippet.js to detect whether this library has been initialized yet.
|
|
25
24
|
*/
|
|
@@ -586,7 +585,7 @@ export class ChordAnalytics {
|
|
|
586
585
|
});
|
|
587
586
|
});
|
|
588
587
|
this.reset = () => __awaiter(this, void 0, void 0, function* () {
|
|
589
|
-
var
|
|
588
|
+
var _e;
|
|
590
589
|
try {
|
|
591
590
|
this.resetInProgress = true;
|
|
592
591
|
const a = this.ccdp();
|
|
@@ -603,12 +602,12 @@ export class ChordAnalytics {
|
|
|
603
602
|
// eslint-disable-next-line
|
|
604
603
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
605
604
|
try {
|
|
606
|
-
const userState = ((
|
|
605
|
+
const userState = ((_e = a === null || a === void 0 ? void 0 : a.user) === null || _e === void 0 ? void 0 : _e.call(a)) || {};
|
|
607
606
|
if (userState.userId === null || userState.userId === undefined) {
|
|
608
607
|
break;
|
|
609
608
|
}
|
|
610
609
|
}
|
|
611
|
-
catch (
|
|
610
|
+
catch (_f) {
|
|
612
611
|
break;
|
|
613
612
|
}
|
|
614
613
|
attempts++;
|
|
@@ -654,6 +653,17 @@ export class ChordAnalytics {
|
|
|
654
653
|
return;
|
|
655
654
|
if (event.data.source !== 'chord-web-pixel')
|
|
656
655
|
return;
|
|
656
|
+
// Validate origin — only accept messages from the same hostname
|
|
657
|
+
try {
|
|
658
|
+
if (event.origin) {
|
|
659
|
+
const eventHostname = new URL(event.origin).hostname;
|
|
660
|
+
if (eventHostname !== window.location.hostname)
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
catch (_a) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
657
667
|
const message = event.data;
|
|
658
668
|
if (this.options.enableLogging && this.options.debug) {
|
|
659
669
|
// eslint-disable-next-line no-console
|
|
@@ -664,18 +674,18 @@ export class ChordAnalytics {
|
|
|
664
674
|
case 'track': {
|
|
665
675
|
const [eventName, properties] = message.payload;
|
|
666
676
|
if (eventName) {
|
|
667
|
-
this.track(eventName, properties);
|
|
677
|
+
Promise.resolve(this.track(eventName, properties)).catch((err) => this.logger('[Chord Analytics]: Error in web pixel track:', err));
|
|
668
678
|
}
|
|
669
679
|
break;
|
|
670
680
|
}
|
|
671
681
|
case 'identify': {
|
|
672
682
|
const [userId, traits] = message.payload;
|
|
673
|
-
this.identify(userId, traits);
|
|
683
|
+
Promise.resolve(this.identify(userId, traits)).catch((err) => this.logger('[Chord Analytics]: Error in web pixel identify:', err));
|
|
674
684
|
break;
|
|
675
685
|
}
|
|
676
686
|
case 'page': {
|
|
677
687
|
const [properties] = message.payload;
|
|
678
|
-
this.page(properties);
|
|
688
|
+
Promise.resolve(this.page(undefined, properties)).catch((err) => this.logger('[Chord Analytics]: Error in web pixel page:', err));
|
|
679
689
|
break;
|
|
680
690
|
}
|
|
681
691
|
default:
|
|
@@ -697,28 +707,10 @@ export class ChordAnalytics {
|
|
|
697
707
|
}
|
|
698
708
|
};
|
|
699
709
|
};
|
|
700
|
-
/**
|
|
701
|
-
* Sync CDP anonymous ID and Google Client ID to Shopify cart attributes.
|
|
702
|
-
* This enables server-side events (webhooks) to correlate with client-side tracking.
|
|
703
|
-
*
|
|
704
|
-
* By default, syncs:
|
|
705
|
-
* - `_cdpAnonymousId`: from the `__eventn_id` cookie (Chord/Jitsu CDP)
|
|
706
|
-
* - `_googleClientId`: from the `_ga` cookie (Google Analytics)
|
|
707
|
-
*
|
|
708
|
-
* @param options - Optional configuration for the sync
|
|
709
|
-
* @returns The updated cart, or undefined if no update was needed or an error occurred
|
|
710
|
-
*/
|
|
711
|
-
this.syncIdentifiersToCart = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
712
|
-
const result = yield syncIdentifiers(options);
|
|
713
|
-
if (result) {
|
|
714
|
-
this.logger('[Chord Analytics]: Identifiers synced to cart');
|
|
715
|
-
}
|
|
716
|
-
return result;
|
|
717
|
-
});
|
|
718
710
|
// TODO: Add support for props.products
|
|
719
711
|
this.trackCartViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
720
|
-
var
|
|
721
|
-
const cart = (
|
|
712
|
+
var _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
713
|
+
const cart = (_k = (_j = (_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.formatters) === null || _h === void 0 ? void 0 : _h.objects) === null || _j === void 0 ? void 0 : _j.cart) === null || _k === void 0 ? void 0 : _k.call(_j, {
|
|
722
714
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
723
715
|
});
|
|
724
716
|
const payload = {
|
|
@@ -727,17 +719,17 @@ export class ChordAnalytics {
|
|
|
727
719
|
products: cart === null || cart === void 0 ? void 0 : cart.products,
|
|
728
720
|
value: cart === null || cart === void 0 ? void 0 : cart.value,
|
|
729
721
|
};
|
|
730
|
-
if ((
|
|
731
|
-
const formattedPayload = (
|
|
722
|
+
if ((_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) {
|
|
723
|
+
const formattedPayload = (_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(props, payload);
|
|
732
724
|
return this.track('Cart Viewed', formattedPayload, options);
|
|
733
725
|
}
|
|
734
726
|
return this.track('Cart Viewed', payload, options);
|
|
735
727
|
});
|
|
736
728
|
// TODO: Add support for props.products
|
|
737
729
|
this.trackCheckoutStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
738
|
-
var
|
|
739
|
-
const formatter = (
|
|
740
|
-
const checkout = (
|
|
730
|
+
var _s, _t, _u, _v, _w, _x, _y;
|
|
731
|
+
const formatter = (_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.checkoutStarted;
|
|
732
|
+
const checkout = (_y = (_x = (_w = (_v = this.options) === null || _v === void 0 ? void 0 : _v.formatters) === null || _w === void 0 ? void 0 : _w.objects) === null || _x === void 0 ? void 0 : _x.checkout) === null || _y === void 0 ? void 0 : _y.call(_x, {
|
|
741
733
|
checkout: props === null || props === void 0 ? void 0 : props.checkout,
|
|
742
734
|
});
|
|
743
735
|
const payload = checkout;
|
|
@@ -748,8 +740,8 @@ export class ChordAnalytics {
|
|
|
748
740
|
return this.track('Checkout Started', payload, options);
|
|
749
741
|
});
|
|
750
742
|
this.trackCheckoutStepCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
751
|
-
var
|
|
752
|
-
const formatter = (
|
|
743
|
+
var _z, _0, _1;
|
|
744
|
+
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.checkoutStepCompleted;
|
|
753
745
|
const payload = {
|
|
754
746
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
755
747
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -763,8 +755,8 @@ export class ChordAnalytics {
|
|
|
763
755
|
return this.track('Checkout Step Completed', payload, options);
|
|
764
756
|
});
|
|
765
757
|
this.trackCheckoutStepViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
766
|
-
var
|
|
767
|
-
const formatter = (
|
|
758
|
+
var _2, _3, _4;
|
|
759
|
+
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.checkoutStepViewed;
|
|
768
760
|
const payload = {
|
|
769
761
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
770
762
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
@@ -778,8 +770,8 @@ export class ChordAnalytics {
|
|
|
778
770
|
return this.track('Checkout Step Viewed', payload, options);
|
|
779
771
|
});
|
|
780
772
|
this.trackCouponApplied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
781
|
-
var
|
|
782
|
-
const formatter = (
|
|
773
|
+
var _5, _6, _7;
|
|
774
|
+
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.couponApplied;
|
|
783
775
|
const payload = {
|
|
784
776
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
785
777
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -794,8 +786,8 @@ export class ChordAnalytics {
|
|
|
794
786
|
return this.track('Coupon Applied', payload, options);
|
|
795
787
|
});
|
|
796
788
|
this.trackCouponDenied = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
var
|
|
798
|
-
const formatter = (
|
|
789
|
+
var _8, _9, _10;
|
|
790
|
+
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.couponDenied;
|
|
799
791
|
const payload = {
|
|
800
792
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
801
793
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -810,8 +802,8 @@ export class ChordAnalytics {
|
|
|
810
802
|
return this.track('Coupon Denied', payload, options);
|
|
811
803
|
});
|
|
812
804
|
this.trackCouponEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
813
|
-
var
|
|
814
|
-
const formatter = (
|
|
805
|
+
var _11, _12, _13;
|
|
806
|
+
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.couponEntered;
|
|
815
807
|
const payload = {
|
|
816
808
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
817
809
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -825,8 +817,8 @@ export class ChordAnalytics {
|
|
|
825
817
|
return this.track('Coupon Entered', payload, options);
|
|
826
818
|
});
|
|
827
819
|
this.trackCouponRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
828
|
-
var
|
|
829
|
-
const formatter = (
|
|
820
|
+
var _14, _15, _16;
|
|
821
|
+
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.couponRemoved;
|
|
830
822
|
const payload = {
|
|
831
823
|
cart_id: props === null || props === void 0 ? void 0 : props.cartId,
|
|
832
824
|
coupon_id: props === null || props === void 0 ? void 0 : props.couponId,
|
|
@@ -841,8 +833,8 @@ export class ChordAnalytics {
|
|
|
841
833
|
return this.track('Coupon Removed', payload, options);
|
|
842
834
|
});
|
|
843
835
|
this.trackEmailCaptured = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
844
|
-
var
|
|
845
|
-
const formatter = (
|
|
836
|
+
var _17, _18, _19;
|
|
837
|
+
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.emailCaptured;
|
|
846
838
|
const payload = {
|
|
847
839
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
848
840
|
placement_component: props === null || props === void 0 ? void 0 : props.placementComponent,
|
|
@@ -855,13 +847,13 @@ export class ChordAnalytics {
|
|
|
855
847
|
return this.track('Email Captured', payload, options);
|
|
856
848
|
});
|
|
857
849
|
this.trackProductAdded = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
858
|
-
var
|
|
859
|
-
const formatter = (
|
|
860
|
-
const product = (
|
|
861
|
-
const cart = (
|
|
850
|
+
var _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
|
|
851
|
+
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.productAdded;
|
|
852
|
+
const product = (_26 = (_25 = (_24 = (_23 = this.options) === null || _23 === void 0 ? void 0 : _23.formatters) === null || _24 === void 0 ? void 0 : _24.objects) === null || _25 === void 0 ? void 0 : _25.product) === null || _26 === void 0 ? void 0 : _26.call(_25, props === null || props === void 0 ? void 0 : props.product);
|
|
853
|
+
const cart = (_30 = (_29 = (_28 = (_27 = this.options) === null || _27 === void 0 ? void 0 : _27.formatters) === null || _28 === void 0 ? void 0 : _28.objects) === null || _29 === void 0 ? void 0 : _29.cart) === null || _30 === void 0 ? void 0 : _30.call(_29, {
|
|
862
854
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
863
855
|
});
|
|
864
|
-
const quantity = ((
|
|
856
|
+
const quantity = ((_31 = props === null || props === void 0 ? void 0 : props.product) === null || _31 === void 0 ? void 0 : _31.quantity) || 1;
|
|
865
857
|
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
858
|
if (typeof formatter === 'function') {
|
|
867
859
|
const formattedPayload = formatter(props, payload);
|
|
@@ -870,14 +862,14 @@ export class ChordAnalytics {
|
|
|
870
862
|
return this.track('Product Added', payload, options);
|
|
871
863
|
});
|
|
872
864
|
this.trackProductClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
873
|
-
var
|
|
874
|
-
const formatter = (
|
|
875
|
-
const product = (
|
|
876
|
-
const cart = (
|
|
865
|
+
var _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44;
|
|
866
|
+
const formatter = (_34 = (_33 = (_32 = this.options) === null || _32 === void 0 ? void 0 : _32.formatters) === null || _33 === void 0 ? void 0 : _33.events) === null || _34 === void 0 ? void 0 : _34.productClicked;
|
|
867
|
+
const product = (_38 = (_37 = (_36 = (_35 = this.options) === null || _35 === void 0 ? void 0 : _35.formatters) === null || _36 === void 0 ? void 0 : _36.objects) === null || _37 === void 0 ? void 0 : _37.product) === null || _38 === void 0 ? void 0 : _38.call(_37, props === null || props === void 0 ? void 0 : props.product);
|
|
868
|
+
const cart = (_42 = (_41 = (_40 = (_39 = this.options) === null || _39 === void 0 ? void 0 : _39.formatters) === null || _40 === void 0 ? void 0 : _40.objects) === null || _41 === void 0 ? void 0 : _41.cart) === null || _42 === void 0 ? void 0 : _42.call(_41, {
|
|
877
869
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
878
870
|
});
|
|
879
|
-
const quantity = ((
|
|
880
|
-
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (
|
|
871
|
+
const quantity = ((_43 = props === null || props === void 0 ? void 0 : props.product) === null || _43 === void 0 ? void 0 : _43.quantity) || 1;
|
|
872
|
+
const payload = Object.assign(Object.assign({}, product), { cart_id: cart.cart_id, currency: cart.currency, item_list_id: (_44 = props === null || props === void 0 ? void 0 : props.listId) === null || _44 === void 0 ? void 0 : _44.toString(), item_list_name: props === null || props === void 0 ? void 0 : props.listName, products: [Object.assign(Object.assign({}, product), { quantity })] });
|
|
881
873
|
if (typeof formatter === 'function') {
|
|
882
874
|
const formattedPayload = formatter(props, payload);
|
|
883
875
|
return this.track('Product Clicked', formattedPayload, options);
|
|
@@ -885,13 +877,13 @@ export class ChordAnalytics {
|
|
|
885
877
|
return this.track('Product Clicked', payload, options);
|
|
886
878
|
});
|
|
887
879
|
this.trackVariantClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
888
|
-
var
|
|
889
|
-
const formatter = (
|
|
890
|
-
const product = (
|
|
891
|
-
const cart = (
|
|
880
|
+
var _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56;
|
|
881
|
+
const formatter = (_47 = (_46 = (_45 = this.options) === null || _45 === void 0 ? void 0 : _45.formatters) === null || _46 === void 0 ? void 0 : _46.events) === null || _47 === void 0 ? void 0 : _47.variantClicked;
|
|
882
|
+
const product = (_51 = (_50 = (_49 = (_48 = this.options) === null || _48 === void 0 ? void 0 : _48.formatters) === null || _49 === void 0 ? void 0 : _49.objects) === null || _50 === void 0 ? void 0 : _50.product) === null || _51 === void 0 ? void 0 : _51.call(_50, props === null || props === void 0 ? void 0 : props.product);
|
|
883
|
+
const cart = (_55 = (_54 = (_53 = (_52 = this.options) === null || _52 === void 0 ? void 0 : _52.formatters) === null || _53 === void 0 ? void 0 : _53.objects) === null || _54 === void 0 ? void 0 : _54.cart) === null || _55 === void 0 ? void 0 : _55.call(_54, {
|
|
892
884
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
893
885
|
});
|
|
894
|
-
const quantity = ((
|
|
886
|
+
const quantity = ((_56 = props === null || props === void 0 ? void 0 : props.product) === null || _56 === void 0 ? void 0 : _56.quantity) || 1;
|
|
895
887
|
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
888
|
if (typeof formatter === 'function') {
|
|
897
889
|
const formattedPayload = formatter(props, payload);
|
|
@@ -900,13 +892,13 @@ export class ChordAnalytics {
|
|
|
900
892
|
return this.track('Variant Clicked', payload, options);
|
|
901
893
|
});
|
|
902
894
|
this.trackProductListFiltered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
903
|
-
var
|
|
904
|
-
const formatter = (
|
|
895
|
+
var _57, _58, _59, _60, _61;
|
|
896
|
+
const formatter = (_59 = (_58 = (_57 = this.options) === null || _57 === void 0 ? void 0 : _57.formatters) === null || _58 === void 0 ? void 0 : _58.events) === null || _59 === void 0 ? void 0 : _59.productListFiltered;
|
|
905
897
|
const payload = {
|
|
906
898
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
907
899
|
filters: props === null || props === void 0 ? void 0 : props.filters,
|
|
908
|
-
list_id: (
|
|
909
|
-
item_list_id: (
|
|
900
|
+
list_id: (_60 = props === null || props === void 0 ? void 0 : props.listId) === null || _60 === void 0 ? void 0 : _60.toString(),
|
|
901
|
+
item_list_id: (_61 = props === null || props === void 0 ? void 0 : props.listId) === null || _61 === void 0 ? void 0 : _61.toString(),
|
|
910
902
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
911
903
|
sorts: props === null || props === void 0 ? void 0 : props.sorts,
|
|
912
904
|
};
|
|
@@ -917,14 +909,14 @@ export class ChordAnalytics {
|
|
|
917
909
|
return this.track('Product List Filtered', payload, options);
|
|
918
910
|
});
|
|
919
911
|
this.trackProductListViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
920
|
-
var
|
|
921
|
-
const formatter = (
|
|
912
|
+
var _62, _63, _64, _65, _66, _67;
|
|
913
|
+
const formatter = (_64 = (_63 = (_62 = this.options) === null || _62 === void 0 ? void 0 : _62.formatters) === null || _63 === void 0 ? void 0 : _63.events) === null || _64 === void 0 ? void 0 : _64.productListViewed;
|
|
922
914
|
const payload = {
|
|
923
915
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
924
|
-
list_id: (
|
|
925
|
-
item_list_id: (
|
|
916
|
+
list_id: (_65 = props === null || props === void 0 ? void 0 : props.listId) === null || _65 === void 0 ? void 0 : _65.toString(),
|
|
917
|
+
item_list_id: (_66 = props === null || props === void 0 ? void 0 : props.listId) === null || _66 === void 0 ? void 0 : _66.toString(),
|
|
926
918
|
item_list_name: props === null || props === void 0 ? void 0 : props.listName,
|
|
927
|
-
products: (
|
|
919
|
+
products: (_67 = props === null || props === void 0 ? void 0 : props.products) === null || _67 === void 0 ? void 0 : _67.map((p, i) => {
|
|
928
920
|
var _a, _b, _c, _d;
|
|
929
921
|
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
922
|
}),
|
|
@@ -937,8 +929,8 @@ export class ChordAnalytics {
|
|
|
937
929
|
return this.track('Product List Viewed', payload, options);
|
|
938
930
|
});
|
|
939
931
|
this.trackProductRemoved = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
940
|
-
var _73, _74, _75, _76, _77, _78, _79, _80, _81, _82
|
|
941
|
-
const formatter = (
|
|
932
|
+
var _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82;
|
|
933
|
+
const formatter = (_70 = (_69 = (_68 = this.options) === null || _68 === void 0 ? void 0 : _68.formatters) === null || _69 === void 0 ? void 0 : _69.events) === null || _70 === void 0 ? void 0 : _70.productRemoved;
|
|
942
934
|
/*
|
|
943
935
|
const product = this.options?.formatters?.objects?.product?.({
|
|
944
936
|
position: props?.position,
|
|
@@ -947,13 +939,13 @@ export class ChordAnalytics {
|
|
|
947
939
|
variantId: props?.variantId,
|
|
948
940
|
})
|
|
949
941
|
*/
|
|
950
|
-
const lineItem = (
|
|
942
|
+
const lineItem = (_74 = (_73 = (_72 = (_71 = this.options) === null || _71 === void 0 ? void 0 : _71.formatters) === null || _72 === void 0 ? void 0 : _72.objects) === null || _73 === void 0 ? void 0 : _73.lineItem) === null || _74 === void 0 ? void 0 : _74.call(_73, {
|
|
951
943
|
lineItem: props === null || props === void 0 ? void 0 : props.lineItem,
|
|
952
944
|
});
|
|
953
|
-
const cart = (
|
|
945
|
+
const cart = (_78 = (_77 = (_76 = (_75 = this.options) === null || _75 === void 0 ? void 0 : _75.formatters) === null || _76 === void 0 ? void 0 : _76.objects) === null || _77 === void 0 ? void 0 : _77.cart) === null || _78 === void 0 ? void 0 : _78.call(_77, {
|
|
954
946
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
955
947
|
});
|
|
956
|
-
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((
|
|
948
|
+
const payload = Object.assign(Object.assign({}, lineItem), { cart_id: cart.cart_id, currency: cart.currency, products: [lineItem], total: ((_79 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _79 !== void 0 ? _79 : 0) * ((_80 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _80 !== void 0 ? _80 : 1), value: ((_81 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.price) !== null && _81 !== void 0 ? _81 : 0) * ((_82 = lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) !== null && _82 !== void 0 ? _82 : 1) });
|
|
957
949
|
if (typeof formatter === 'function') {
|
|
958
950
|
const formattedPayload = formatter(props, payload);
|
|
959
951
|
return this.track('Product Removed', formattedPayload, options);
|
|
@@ -961,14 +953,14 @@ export class ChordAnalytics {
|
|
|
961
953
|
return this.track('Product Removed', payload, options);
|
|
962
954
|
});
|
|
963
955
|
this.trackProductViewed = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
964
|
-
var
|
|
965
|
-
const formatter = (
|
|
966
|
-
const product = (
|
|
967
|
-
const cart = (
|
|
956
|
+
var _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95;
|
|
957
|
+
const formatter = (_85 = (_84 = (_83 = this.options) === null || _83 === void 0 ? void 0 : _83.formatters) === null || _84 === void 0 ? void 0 : _84.events) === null || _85 === void 0 ? void 0 : _85.productViewed;
|
|
958
|
+
const product = (_89 = (_88 = (_87 = (_86 = this.options) === null || _86 === void 0 ? void 0 : _86.formatters) === null || _87 === void 0 ? void 0 : _87.objects) === null || _88 === void 0 ? void 0 : _88.product) === null || _89 === void 0 ? void 0 : _89.call(_88, props === null || props === void 0 ? void 0 : props.product);
|
|
959
|
+
const cart = (_93 = (_92 = (_91 = (_90 = this.options) === null || _90 === void 0 ? void 0 : _90.formatters) === null || _91 === void 0 ? void 0 : _91.objects) === null || _92 === void 0 ? void 0 : _92.cart) === null || _93 === void 0 ? void 0 : _93.call(_92, {
|
|
968
960
|
cart: props === null || props === void 0 ? void 0 : props.cart,
|
|
969
961
|
});
|
|
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 * (((
|
|
962
|
+
const quantity = ((_94 = props === null || props === void 0 ? void 0 : props.product) === null || _94 === void 0 ? void 0 : _94.quantity) || 1;
|
|
963
|
+
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 * (((_95 = props === null || props === void 0 ? void 0 : props.product) === null || _95 === void 0 ? void 0 : _95.quantity) || 1) });
|
|
972
964
|
if (typeof formatter === 'function') {
|
|
973
965
|
const formattedPayload = formatter(props, payload);
|
|
974
966
|
return this.track('Product Viewed', formattedPayload, options);
|
|
@@ -976,12 +968,12 @@ export class ChordAnalytics {
|
|
|
976
968
|
return this.track('Product Viewed', payload, options);
|
|
977
969
|
});
|
|
978
970
|
this.trackProductsSearched = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
979
|
-
var
|
|
980
|
-
const formatter = (
|
|
971
|
+
var _96, _97, _98, _99;
|
|
972
|
+
const formatter = (_98 = (_97 = (_96 = this.options) === null || _96 === void 0 ? void 0 : _96.formatters) === null || _97 === void 0 ? void 0 : _97.events) === null || _98 === void 0 ? void 0 : _98.productsSearched;
|
|
981
973
|
const payload = {
|
|
982
974
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
983
975
|
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: (
|
|
976
|
+
product_id: (_99 = props === null || props === void 0 ? void 0 : props.productId) === null || _99 === void 0 ? void 0 : _99.toString(),
|
|
985
977
|
quantity: props === null || props === void 0 ? void 0 : props.quantity,
|
|
986
978
|
query: props === null || props === void 0 ? void 0 : props.query,
|
|
987
979
|
};
|
|
@@ -992,8 +984,8 @@ export class ChordAnalytics {
|
|
|
992
984
|
return this.track('Products Searched', payload, options);
|
|
993
985
|
});
|
|
994
986
|
this.trackSignedIn = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
995
|
-
var
|
|
996
|
-
const formatter = (
|
|
987
|
+
var _100, _101, _102;
|
|
988
|
+
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.signedIn;
|
|
997
989
|
const payload = {
|
|
998
990
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
999
991
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1005,8 +997,8 @@ export class ChordAnalytics {
|
|
|
1005
997
|
return this.track('Signed In', payload, options);
|
|
1006
998
|
});
|
|
1007
999
|
this.trackSignedOut = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1008
|
-
var
|
|
1009
|
-
const formatter = (
|
|
1000
|
+
var _103, _104, _105;
|
|
1001
|
+
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.signedOut;
|
|
1010
1002
|
const payload = {
|
|
1011
1003
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1012
1004
|
};
|
|
@@ -1017,8 +1009,8 @@ export class ChordAnalytics {
|
|
|
1017
1009
|
return this.track('Signed Out', payload, options);
|
|
1018
1010
|
});
|
|
1019
1011
|
this.trackSignedUp = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1020
|
-
var
|
|
1021
|
-
const formatter = (
|
|
1012
|
+
var _106, _107, _108;
|
|
1013
|
+
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.signedUp;
|
|
1022
1014
|
const payload = {
|
|
1023
1015
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1024
1016
|
method: props === null || props === void 0 ? void 0 : props.method,
|
|
@@ -1030,8 +1022,8 @@ export class ChordAnalytics {
|
|
|
1030
1022
|
return this.track('Signed Up', payload, options);
|
|
1031
1023
|
});
|
|
1032
1024
|
this.trackLoginStarted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
-
var
|
|
1034
|
-
const formatter = (
|
|
1025
|
+
var _109, _110, _111;
|
|
1026
|
+
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.loginStarted;
|
|
1035
1027
|
const payload = {
|
|
1036
1028
|
email: props === null || props === void 0 ? void 0 : props.email,
|
|
1037
1029
|
};
|
|
@@ -1042,8 +1034,8 @@ export class ChordAnalytics {
|
|
|
1042
1034
|
return this.track('Login Started', payload, options);
|
|
1043
1035
|
});
|
|
1044
1036
|
this.trackSubscriptionCancelled = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1045
|
-
var
|
|
1046
|
-
const formatter = (
|
|
1037
|
+
var _112, _113, _114, _115;
|
|
1038
|
+
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.subscriptionCancelled;
|
|
1047
1039
|
const payload = {
|
|
1048
1040
|
actionable_date: props === null || props === void 0 ? void 0 : props.actionableDate,
|
|
1049
1041
|
address: props === null || props === void 0 ? void 0 : props.address,
|
|
@@ -1052,7 +1044,7 @@ export class ChordAnalytics {
|
|
|
1052
1044
|
end_date: props === null || props === void 0 ? void 0 : props.endDate,
|
|
1053
1045
|
interval_length: props === null || props === void 0 ? void 0 : props.intervalLength,
|
|
1054
1046
|
interval_units: props === null || props === void 0 ? void 0 : props.intervalUnits,
|
|
1055
|
-
products: (
|
|
1047
|
+
products: (_115 = props === null || props === void 0 ? void 0 : props.products) === null || _115 === void 0 ? void 0 : _115.map((p, i) => {
|
|
1056
1048
|
var _a, _b, _c, _d;
|
|
1057
1049
|
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
1050
|
}),
|
|
@@ -1067,8 +1059,8 @@ export class ChordAnalytics {
|
|
|
1067
1059
|
return this.track('Subscription Cancelled', payload, options);
|
|
1068
1060
|
});
|
|
1069
1061
|
this.trackNavigationClicked = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1070
|
-
var
|
|
1071
|
-
const formatter = (
|
|
1062
|
+
var _116, _117, _118;
|
|
1063
|
+
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.navigationClicked;
|
|
1072
1064
|
const payload = {
|
|
1073
1065
|
category: props === null || props === void 0 ? void 0 : props.category,
|
|
1074
1066
|
label: props === null || props === void 0 ? void 0 : props.label,
|
|
@@ -1083,15 +1075,15 @@ export class ChordAnalytics {
|
|
|
1083
1075
|
return this.track('Navigation Clicked', payload, options);
|
|
1084
1076
|
});
|
|
1085
1077
|
this.trackPaymentInfoEntered = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1086
|
-
var
|
|
1087
|
-
const formatter = (
|
|
1078
|
+
var _119, _120, _121, _122;
|
|
1079
|
+
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.paymentInfoEntered;
|
|
1088
1080
|
const payload = {
|
|
1089
1081
|
checkout_id: props === null || props === void 0 ? void 0 : props.checkoutId,
|
|
1090
1082
|
coupon: props === null || props === void 0 ? void 0 : props.coupon,
|
|
1091
1083
|
currency: props === null || props === void 0 ? void 0 : props.currency,
|
|
1092
1084
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1093
1085
|
payment_method: props === null || props === void 0 ? void 0 : props.paymentMethod,
|
|
1094
|
-
products: (
|
|
1086
|
+
products: (_122 = props === null || props === void 0 ? void 0 : props.products) === null || _122 === void 0 ? void 0 : _122.map((p, i) => {
|
|
1095
1087
|
var _a, _b, _c, _d;
|
|
1096
1088
|
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
1089
|
}),
|
|
@@ -1106,8 +1098,8 @@ export class ChordAnalytics {
|
|
|
1106
1098
|
return this.track('Payment Info Entered', payload, options);
|
|
1107
1099
|
});
|
|
1108
1100
|
this.trackOrderCompleted = (props, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1109
|
-
var
|
|
1110
|
-
const formatter = (
|
|
1101
|
+
var _123, _124, _125, _126;
|
|
1102
|
+
const formatter = (_125 = (_124 = (_123 = this.options) === null || _123 === void 0 ? void 0 : _123.formatters) === null || _124 === void 0 ? void 0 : _124.events) === null || _125 === void 0 ? void 0 : _125.orderCompleted;
|
|
1111
1103
|
const payload = {
|
|
1112
1104
|
affiliation: props === null || props === void 0 ? void 0 : props.affiliation,
|
|
1113
1105
|
campaign_id: props === null || props === void 0 ? void 0 : props.campaignId,
|
|
@@ -1127,7 +1119,7 @@ export class ChordAnalytics {
|
|
|
1127
1119
|
order_date: props === null || props === void 0 ? void 0 : props.orderDate,
|
|
1128
1120
|
order_id: props === null || props === void 0 ? void 0 : props.orderId,
|
|
1129
1121
|
phone: props === null || props === void 0 ? void 0 : props.phone,
|
|
1130
|
-
products: (
|
|
1122
|
+
products: (_126 = props === null || props === void 0 ? void 0 : props.products) === null || _126 === void 0 ? void 0 : _126.map((p, i) => {
|
|
1131
1123
|
var _a;
|
|
1132
1124
|
return ({
|
|
1133
1125
|
affiliation: p === null || p === void 0 ? void 0 : p.affiliation,
|
|
@@ -1199,18 +1191,14 @@ export class ChordAnalytics {
|
|
|
1199
1191
|
window[this.options.namespace] = (window === null || window === void 0 ? void 0 : window[this.options.namespace]) || this;
|
|
1200
1192
|
this.initializeCdp();
|
|
1201
1193
|
}
|
|
1202
|
-
// Set up web pixel listener:
|
|
1203
|
-
//
|
|
1204
|
-
|
|
1194
|
+
// Set up web pixel listener: always enabled unless explicitly disabled.
|
|
1195
|
+
// The listener only processes messages with source === 'chord-web-pixel',
|
|
1196
|
+
// so it's safe to enable on non-Shopify sites (no matching messages).
|
|
1197
|
+
const shouldEnableWebPixel = ((_d = this.options) === null || _d === void 0 ? void 0 : _d.enableWebPixelListener) !== false &&
|
|
1198
|
+
typeof window !== 'undefined';
|
|
1205
1199
|
if (shouldEnableWebPixel) {
|
|
1206
1200
|
this.setupWebPixelListener();
|
|
1207
1201
|
}
|
|
1208
|
-
// Sync identifiers to cart: explicit true/false takes precedence,
|
|
1209
|
-
// otherwise auto-detect by checking for window.Shopify.shop (Liquid storefront)
|
|
1210
|
-
const shouldEnableIdentifierSync = (_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.enableIdentifierSync) !== null && _h !== void 0 ? _h : (typeof window !== 'undefined' && !!((_j = window.Shopify) === null || _j === void 0 ? void 0 : _j.shop));
|
|
1211
|
-
if (shouldEnableIdentifierSync) {
|
|
1212
|
-
this.syncIdentifiersToCart();
|
|
1213
|
-
}
|
|
1214
1202
|
}
|
|
1215
1203
|
/**
|
|
1216
1204
|
* Initialize CDP snippet and wait for it to be ready.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/client.d.ts
CHANGED
|
@@ -34,20 +34,7 @@ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
|
|
|
34
34
|
awaitConsent?: boolean;
|
|
35
35
|
debug?: boolean;
|
|
36
36
|
enableLogging?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Controls the postMessage listener for events from the Shopify Custom Web
|
|
39
|
-
* Pixel sandbox. When true, always enables the listener. When false, always
|
|
40
|
-
* disables it. When undefined (default), auto-detects by checking for
|
|
41
|
-
* window.Shopify.shop which is present on Shopify Liquid storefronts.
|
|
42
|
-
*/
|
|
43
37
|
enableWebPixelListener?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Controls syncing CDP anonymous ID and Google Client ID to Shopify cart
|
|
46
|
-
* attributes. When true, always enables sync. When false, always disables it.
|
|
47
|
-
* When undefined (default), auto-detects by checking for window.Shopify.shop
|
|
48
|
-
* which is present on Shopify Liquid storefronts.
|
|
49
|
-
*/
|
|
50
|
-
enableIdentifierSync?: boolean;
|
|
51
38
|
formatters: ChordAnalyticsFormatters<T>;
|
|
52
39
|
namespace?: string;
|
|
53
40
|
stripNull?: boolean;
|
package/package.json
CHANGED