@aranova/tracking-react 0.17.1 → 0.17.2

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/index.mjs CHANGED
@@ -1134,6 +1134,27 @@ function getOrCreateTrackingClient(config) {
1134
1134
  globalClientKey = key;
1135
1135
  return globalClient;
1136
1136
  }
1137
+ var clientCaptureRegistry = /* @__PURE__ */ new WeakMap();
1138
+ function attachClientCapturesOnce(client, build) {
1139
+ let entry = clientCaptureRegistry.get(client);
1140
+ if (entry === void 0) {
1141
+ entry = { detach: build(), refCount: 0 };
1142
+ clientCaptureRegistry.set(client, entry);
1143
+ }
1144
+ entry.refCount += 1;
1145
+ let released = false;
1146
+ return () => {
1147
+ if (released) return;
1148
+ released = true;
1149
+ const current = clientCaptureRegistry.get(client);
1150
+ if (current === void 0) return;
1151
+ current.refCount -= 1;
1152
+ if (current.refCount <= 0) {
1153
+ current.detach();
1154
+ clientCaptureRegistry.delete(client);
1155
+ }
1156
+ };
1157
+ }
1137
1158
  function createTrackingClient(config) {
1138
1159
  const flushIntervalMs = config.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
1139
1160
  const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
@@ -2800,7 +2821,7 @@ function GoogleAdsTracking(props) {
2800
2821
  import { createContext as createContext2, useContext as useContext2, useEffect as useEffect5, useMemo as useMemo4 } from "react";
2801
2822
 
2802
2823
  // package.json
2803
- var version = "0.17.1";
2824
+ var version = "0.17.2";
2804
2825
 
2805
2826
  // ../tracking-core/src/phone-react.tsx
2806
2827
  import {
@@ -2970,7 +2991,6 @@ function createTracking(options) {
2970
2991
  }
2971
2992
  }, [metaPixelId, metaPixelIdsKey]);
2972
2993
  useEffect5(() => {
2973
- const detachers = [];
2974
2994
  const rawClient = getOrCreateTrackingClient({
2975
2995
  apiKey,
2976
2996
  endpoint,
@@ -2981,47 +3001,50 @@ function createTracking(options) {
2981
3001
  activeGtagIds: resolvedGtagIds,
2982
3002
  debug
2983
3003
  });
2984
- const conversionStore = conversionConfig ? resolveConversionConfig({
2985
- cdnUrl: conversionConfig.cdnUrl,
2986
- baked: conversionConfig.baked
2987
- }) : null;
2988
- const detectorClient = conversionStore ? withConversionAutoFire(rawClient, createConversionAutoFire(conversionStore)) : rawClient;
2989
- detachers.push(attachAutoPageView(detectorClient));
2990
- detachers.push(attachBfcacheRestore(detectorClient));
2991
- detachers.push(attachPageExit(detectorClient));
2992
- const timeOnSite = triggers.automatic.time_on_site;
2993
- if (timeOnSite) {
2994
- detachers.push(attachTimeOnSite(detectorClient, timeOnSite));
2995
- }
2996
- const specificPageVisit = triggers.automatic.specific_page_visit;
2997
- if (specificPageVisit) {
2998
- detachers.push(attachSpecificPageVisit(detectorClient, specificPageVisit));
2999
- }
3000
- const scrollDepth = triggers.automatic.scroll_depth;
3001
- if (scrollDepth) {
3002
- detachers.push(attachScrollDepth(detectorClient, scrollDepth));
3003
- }
3004
- const multiPageSession = triggers.automatic.multi_page_session;
3005
- if (multiPageSession) {
3006
- detachers.push(attachMultiPageSession(detectorClient, multiPageSession));
3007
- }
3008
- const formStart = triggers.automatic.form_start;
3009
- if (formStart) {
3010
- detachers.push(attachFormStart(detectorClient, formStart));
3011
- }
3012
- const ctaClick = triggers.manual?.cta_click;
3013
- if (ctaClick) {
3014
- detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
3015
- }
3016
- const phoneClick = triggers.manual?.phone_click;
3017
- if (phoneClick) {
3018
- detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
3019
- }
3020
- return () => {
3021
- for (let i = detachers.length - 1; i >= 0; i--) {
3022
- detachers[i]();
3004
+ return attachClientCapturesOnce(rawClient, () => {
3005
+ const detachers = [];
3006
+ const conversionStore = conversionConfig ? resolveConversionConfig({
3007
+ cdnUrl: conversionConfig.cdnUrl,
3008
+ baked: conversionConfig.baked
3009
+ }) : null;
3010
+ const detectorClient = conversionStore ? withConversionAutoFire(rawClient, createConversionAutoFire(conversionStore)) : rawClient;
3011
+ detachers.push(attachAutoPageView(detectorClient));
3012
+ detachers.push(attachBfcacheRestore(detectorClient));
3013
+ detachers.push(attachPageExit(detectorClient));
3014
+ const timeOnSite = triggers.automatic.time_on_site;
3015
+ if (timeOnSite) {
3016
+ detachers.push(attachTimeOnSite(detectorClient, timeOnSite));
3017
+ }
3018
+ const specificPageVisit = triggers.automatic.specific_page_visit;
3019
+ if (specificPageVisit) {
3020
+ detachers.push(attachSpecificPageVisit(detectorClient, specificPageVisit));
3021
+ }
3022
+ const scrollDepth = triggers.automatic.scroll_depth;
3023
+ if (scrollDepth) {
3024
+ detachers.push(attachScrollDepth(detectorClient, scrollDepth));
3025
+ }
3026
+ const multiPageSession = triggers.automatic.multi_page_session;
3027
+ if (multiPageSession) {
3028
+ detachers.push(attachMultiPageSession(detectorClient, multiPageSession));
3029
+ }
3030
+ const formStart = triggers.automatic.form_start;
3031
+ if (formStart) {
3032
+ detachers.push(attachFormStart(detectorClient, formStart));
3023
3033
  }
3024
- };
3034
+ const ctaClick = triggers.manual?.cta_click;
3035
+ if (ctaClick) {
3036
+ detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
3037
+ }
3038
+ const phoneClick = triggers.manual?.phone_click;
3039
+ if (phoneClick) {
3040
+ detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
3041
+ }
3042
+ return () => {
3043
+ for (let i = detachers.length - 1; i >= 0; i--) {
3044
+ detachers[i]();
3045
+ }
3046
+ };
3047
+ });
3025
3048
  }, []);
3026
3049
  return /* @__PURE__ */ jsx3(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ jsx3(PhoneConfigProvider, { value: phone ?? null, children }) });
3027
3050
  }