shopkit-analytics 1.0.17 → 1.0.18

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.
@@ -1,5 +1,5 @@
1
- export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-FYQJe6gw.mjs';
1
+ export { B as BaseAdapter, f as GoogleAdapter, G as GoogleAdapterConfig, k as KwikCheckoutAdapter, c as KwikCheckoutConfig, j as KwikPassAdapter, K as KwikPassConfig, g as MoengageAdapter, a as MoengageAdapterConfig, e as MultiPixelAdapter, M as MultiPixelAdapterConfig, d as PixelAdapter, P as PixelAdapterConfig, h as PostHogAdapter, b as PostHogAdapterConfig, i as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-Dr8EruTV.mjs';
2
2
  import '../types.mjs';
3
- import '../subscriber-BoyOlh9t.mjs';
3
+ import '../subscriber-90r_t90W.mjs';
4
4
  import '../types-BBZbvq9-.mjs';
5
5
  import '@shopify/hydrogen-react';
@@ -1,5 +1,5 @@
1
- export { B as BaseAdapter, d as GoogleAdapter, G as GoogleAdapterConfig, i as KwikCheckoutAdapter, b as KwikCheckoutConfig, h as KwikPassAdapter, K as KwikPassConfig, e as MoengageAdapter, M as MoengageAdapterConfig, c as PixelAdapter, P as PixelAdapterConfig, f as PostHogAdapter, a as PostHogAdapterConfig, g as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-D5kCwJ9W.js';
1
+ export { B as BaseAdapter, f as GoogleAdapter, G as GoogleAdapterConfig, k as KwikCheckoutAdapter, c as KwikCheckoutConfig, j as KwikPassAdapter, K as KwikPassConfig, g as MoengageAdapter, a as MoengageAdapterConfig, e as MultiPixelAdapter, M as MultiPixelAdapterConfig, d as PixelAdapter, P as PixelAdapterConfig, h as PostHogAdapter, b as PostHogAdapterConfig, i as ShopifyAdapter, S as ShopifyAdapterConfig } from '../index-Iq86iul2.js';
2
2
  import '../types.js';
3
- import '../subscriber-BDAm_BAi.js';
3
+ import '../subscriber-AtiHiP3i.js';
4
4
  import '../types-BBZbvq9-.js';
5
5
  import '@shopify/hydrogen-react';
@@ -36,6 +36,7 @@ __export(adapters_exports, {
36
36
  KwikCheckoutAdapter: () => KwikCheckoutAdapter,
37
37
  KwikPassAdapter: () => KwikPassAdapter,
38
38
  MoengageAdapter: () => MoengageAdapter,
39
+ MultiPixelAdapter: () => MultiPixelAdapter,
39
40
  PixelAdapter: () => PixelAdapter,
40
41
  PostHogAdapter: () => PostHogAdapter,
41
42
  ShopifyAdapter: () => ShopifyAdapter
@@ -599,6 +600,249 @@ var PixelAdapter = class extends BaseAdapter {
599
600
  }
600
601
  };
601
602
 
603
+ // src/adapters/multi-pixel-adapter.ts
604
+ var MultiPixelAdapter = class extends BaseAdapter {
605
+ constructor(config) {
606
+ super(config);
607
+ this.name = "MultiPixelFacebook";
608
+ this.pixels = [];
609
+ if (!config.pixels || config.pixels.length === 0) {
610
+ throw new Error(
611
+ "MultiPixelAdapter requires at least one pixel configuration"
612
+ );
613
+ }
614
+ this.pixels = config.pixels.map((pixelConfig) => ({
615
+ config: {
616
+ enableCAPI: config.enableCAPI ?? true,
617
+ ...pixelConfig
618
+ },
619
+ initialized: false
620
+ }));
621
+ this.initializeLogger();
622
+ }
623
+ /**
624
+ * Initialize all Facebook Pixels
625
+ */
626
+ async initialize() {
627
+ if (this.initialized) {
628
+ this.logger.debug("Already initialized");
629
+ return;
630
+ }
631
+ if (typeof window === "undefined") {
632
+ this.logger.debug("Skipping initialization on server");
633
+ return;
634
+ }
635
+ if (!window.fbq) {
636
+ this.logger.warn(
637
+ "Facebook Pixel fbq not found. Make sure the script is loaded."
638
+ );
639
+ return;
640
+ }
641
+ for (const pixel of this.pixels) {
642
+ const { pixelId, name } = pixel.config;
643
+ const pixelLabel = name || pixelId;
644
+ try {
645
+ window.fbq("init", pixelId);
646
+ this.logger.info(`Initialized pixel: ${pixelLabel}`, { pixelId: "***" });
647
+ pixel.initialized = true;
648
+ } catch (error) {
649
+ this.logger.error(`Failed to initialize pixel: ${pixelLabel}`, error instanceof Error ? error : new Error(String(error)));
650
+ }
651
+ }
652
+ this.initialized = true;
653
+ this.logger.info(`Successfully initialized ${this.pixels.length} pixels`);
654
+ }
655
+ /**
656
+ * Track an event across all configured pixels
657
+ */
658
+ async trackEvent(event, adapterParams) {
659
+ if (!event.eventId) {
660
+ event.eventId = generateEventId(event.type);
661
+ }
662
+ if (!event.timestamp) {
663
+ event.timestamp = Date.now();
664
+ }
665
+ this.logger.debug("Tracking event across multiple pixels", {
666
+ eventType: event.type,
667
+ eventId: event.eventId,
668
+ pixelCount: this.pixels.length
669
+ });
670
+ await this.trackClientSide(event, adapterParams);
671
+ if (this.pixels.some((pixel) => pixel.config.enableCAPI)) {
672
+ await this.trackServerSide(event, adapterParams);
673
+ }
674
+ }
675
+ /**
676
+ * Track event on client-side once (Facebook automatically sends to all initialized pixels)
677
+ */
678
+ async trackClientSide(event, adapterParams) {
679
+ if (typeof window === "undefined" || !window.fbq) {
680
+ this.logger.warn(
681
+ "Cannot track client-side event, fbq not available",
682
+ {
683
+ eventType: event.type,
684
+ hasWindow: typeof window !== "undefined",
685
+ hasFbq: !!window?.fbq
686
+ }
687
+ );
688
+ return;
689
+ }
690
+ const hasInitializedPixel = this.pixels.some((pixel) => pixel.initialized);
691
+ if (!hasInitializedPixel) {
692
+ this.logger.warn("No pixels initialized for client-side tracking");
693
+ return;
694
+ }
695
+ const { eventName, enhancedParams } = this.formatEventPayload(
696
+ event,
697
+ adapterParams
698
+ );
699
+ if (event.eventId) {
700
+ window.fbq?.("track", eventName, enhancedParams, {
701
+ eventID: event.eventId
702
+ });
703
+ } else {
704
+ window.fbq?.("track", eventName, enhancedParams);
705
+ }
706
+ this.logger.debug(`${eventName} event tracked on client-side for all pixels`, {
707
+ eventName,
708
+ eventId: event.eventId,
709
+ pixelCount: this.pixels.length
710
+ });
711
+ }
712
+ /**
713
+ * Track event on server-side for all enabled pixels
714
+ */
715
+ async trackServerSide(event, adapterParams) {
716
+ try {
717
+ const { eventName, enhancedParams } = this.formatEventPayload(
718
+ event,
719
+ adapterParams
720
+ );
721
+ const browserInfo = getBrowserInfo();
722
+ const payload = {
723
+ eventName,
724
+ eventId: event.eventId,
725
+ timestamp: event.timestamp,
726
+ enhancedParams,
727
+ userInfo: browserInfo,
728
+ // Send all pixel info to the multi-pixel endpoint
729
+ pixels: this.pixels.filter((pixel) => pixel.config.enableCAPI).map((pixel) => ({
730
+ pixelId: pixel.config.pixelId,
731
+ name: pixel.config.name
732
+ }))
733
+ };
734
+ const endpoint = this.getConfig("capiEndpoint", "/api/events/multi");
735
+ const response = await fetch(endpoint, {
736
+ method: "POST",
737
+ headers: {
738
+ "Content-Type": "application/json"
739
+ },
740
+ body: JSON.stringify(payload)
741
+ });
742
+ if (!response.ok) {
743
+ throw new Error(`Server-side tracking failed: ${response.status}`);
744
+ }
745
+ this.logger.debug(`${eventName} event sent to server-side for all pixels`, {
746
+ eventId: event.eventId,
747
+ pixelCount: this.pixels.filter((pixel) => pixel.config.enableCAPI).length
748
+ });
749
+ } catch (error) {
750
+ this.logger.error(
751
+ `Server-side tracking failed: ${error instanceof Error ? error.message : String(error)}`
752
+ );
753
+ }
754
+ }
755
+ /**
756
+ * Format event payload with pixel-specific customizations
757
+ */
758
+ formatEventPayload(event, adapterParams) {
759
+ let baseParams = {};
760
+ let eventName = "";
761
+ switch (event.type) {
762
+ case "page_view" /* PAGE_VIEW */:
763
+ const pageViewEvent = event;
764
+ eventName = this.getEventName(adapterParams, "PageView");
765
+ baseParams = {
766
+ content_name: pageViewEvent.page_title || pageViewEvent.title,
767
+ content_category: pageViewEvent.event_category,
768
+ page_location: pageViewEvent.page_location || pageViewEvent.path,
769
+ page_title: pageViewEvent.page_title || pageViewEvent.title,
770
+ page_referrer: pageViewEvent.page_referrer || pageViewEvent.referrer,
771
+ page_path: pageViewEvent.page_path || pageViewEvent.path
772
+ };
773
+ break;
774
+ case "view_content" /* VIEW_CONTENT */:
775
+ const viewContentEvent = event;
776
+ eventName = this.getEventName(adapterParams, "ViewContent");
777
+ baseParams = {
778
+ content_type: viewContentEvent.content_type || "product",
779
+ content_ids: viewContentEvent.content_ids || [],
780
+ content_name: viewContentEvent.content_name || "",
781
+ content_category: viewContentEvent.content_category || "",
782
+ value: viewContentEvent.value || 0,
783
+ currency: viewContentEvent.currency || "INR"
784
+ };
785
+ break;
786
+ case "product_view" /* PRODUCT_VIEW */:
787
+ const productEvent = event;
788
+ eventName = this.getEventName(adapterParams, "ViewContent");
789
+ baseParams = {
790
+ content_type: "product_group",
791
+ content_ids: [productEvent.productId],
792
+ content_name: productEvent.productName,
793
+ content_category: productEvent.category,
794
+ value: productEvent.price,
795
+ currency: productEvent.currency || "INR"
796
+ };
797
+ break;
798
+ case "add_to_cart" /* ADD_TO_CART */:
799
+ const cartEvent = event;
800
+ eventName = this.getEventName(adapterParams, "AddToCart");
801
+ baseParams = {
802
+ content_type: "product_group",
803
+ content_ids: [cartEvent.productId],
804
+ content_name: cartEvent.productName,
805
+ value: cartEvent.price,
806
+ currency: cartEvent.currency || "INR"
807
+ };
808
+ break;
809
+ case "search" /* SEARCH */:
810
+ const searchEvent = event;
811
+ eventName = this.getEventName(adapterParams, "Search");
812
+ baseParams = {
813
+ search_string: searchEvent.searchTerm,
814
+ content_category: "product",
815
+ content_ids: searchEvent.content_ids || []
816
+ };
817
+ break;
818
+ default:
819
+ eventName = this.getEventName(adapterParams, "CustomEvent");
820
+ baseParams = {};
821
+ break;
822
+ }
823
+ const affiliateParams = this.enhanceWithAffiliateParams(baseParams);
824
+ const experimentParams = this.enhanceWithExperimentParams(affiliateParams);
825
+ const enhancedParams = this.mergeEventData(experimentParams, adapterParams);
826
+ return { eventName, enhancedParams };
827
+ }
828
+ /**
829
+ * Get configuration for all pixels
830
+ */
831
+ getPixelConfigs() {
832
+ return this.pixels.map((pixel) => pixel.config);
833
+ }
834
+ /**
835
+ * Get initialization status for all pixels
836
+ */
837
+ getPixelStatus() {
838
+ return this.pixels.map((pixel) => ({
839
+ pixelId: pixel.config.pixelId,
840
+ name: pixel.config.name,
841
+ initialized: pixel.initialized
842
+ }));
843
+ }
844
+ };
845
+
602
846
  // src/adapters/google-adapter.ts
603
847
  var GoogleAdapter = class extends BaseAdapter {
604
848
  constructor(config) {
@@ -2842,6 +3086,7 @@ var KwikCheckoutAdapter = class extends BaseAdapter {
2842
3086
  KwikCheckoutAdapter,
2843
3087
  KwikPassAdapter,
2844
3088
  MoengageAdapter,
3089
+ MultiPixelAdapter,
2845
3090
  PixelAdapter,
2846
3091
  PostHogAdapter,
2847
3092
  ShopifyAdapter