@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.js CHANGED
@@ -1206,6 +1206,27 @@ function getOrCreateTrackingClient(config) {
1206
1206
  globalClientKey = key;
1207
1207
  return globalClient;
1208
1208
  }
1209
+ var clientCaptureRegistry = /* @__PURE__ */ new WeakMap();
1210
+ function attachClientCapturesOnce(client, build) {
1211
+ let entry = clientCaptureRegistry.get(client);
1212
+ if (entry === void 0) {
1213
+ entry = { detach: build(), refCount: 0 };
1214
+ clientCaptureRegistry.set(client, entry);
1215
+ }
1216
+ entry.refCount += 1;
1217
+ let released = false;
1218
+ return () => {
1219
+ if (released) return;
1220
+ released = true;
1221
+ const current = clientCaptureRegistry.get(client);
1222
+ if (current === void 0) return;
1223
+ current.refCount -= 1;
1224
+ if (current.refCount <= 0) {
1225
+ current.detach();
1226
+ clientCaptureRegistry.delete(client);
1227
+ }
1228
+ };
1229
+ }
1209
1230
  function createTrackingClient(config) {
1210
1231
  const flushIntervalMs = config.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
1211
1232
  const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
@@ -2872,7 +2893,7 @@ function GoogleAdsTracking(props) {
2872
2893
  var import_react6 = require("react");
2873
2894
 
2874
2895
  // package.json
2875
- var version = "0.17.1";
2896
+ var version = "0.17.2";
2876
2897
 
2877
2898
  // ../tracking-core/src/phone-react.tsx
2878
2899
  var import_react5 = require("react");
@@ -3035,7 +3056,6 @@ function createTracking(options) {
3035
3056
  }
3036
3057
  }, [metaPixelId, metaPixelIdsKey]);
3037
3058
  (0, import_react6.useEffect)(() => {
3038
- const detachers = [];
3039
3059
  const rawClient = getOrCreateTrackingClient({
3040
3060
  apiKey,
3041
3061
  endpoint,
@@ -3046,47 +3066,50 @@ function createTracking(options) {
3046
3066
  activeGtagIds: resolvedGtagIds,
3047
3067
  debug
3048
3068
  });
3049
- const conversionStore = conversionConfig ? resolveConversionConfig({
3050
- cdnUrl: conversionConfig.cdnUrl,
3051
- baked: conversionConfig.baked
3052
- }) : null;
3053
- const detectorClient = conversionStore ? withConversionAutoFire(rawClient, createConversionAutoFire(conversionStore)) : rawClient;
3054
- detachers.push(attachAutoPageView(detectorClient));
3055
- detachers.push(attachBfcacheRestore(detectorClient));
3056
- detachers.push(attachPageExit(detectorClient));
3057
- const timeOnSite = triggers.automatic.time_on_site;
3058
- if (timeOnSite) {
3059
- detachers.push(attachTimeOnSite(detectorClient, timeOnSite));
3060
- }
3061
- const specificPageVisit = triggers.automatic.specific_page_visit;
3062
- if (specificPageVisit) {
3063
- detachers.push(attachSpecificPageVisit(detectorClient, specificPageVisit));
3064
- }
3065
- const scrollDepth = triggers.automatic.scroll_depth;
3066
- if (scrollDepth) {
3067
- detachers.push(attachScrollDepth(detectorClient, scrollDepth));
3068
- }
3069
- const multiPageSession = triggers.automatic.multi_page_session;
3070
- if (multiPageSession) {
3071
- detachers.push(attachMultiPageSession(detectorClient, multiPageSession));
3072
- }
3073
- const formStart = triggers.automatic.form_start;
3074
- if (formStart) {
3075
- detachers.push(attachFormStart(detectorClient, formStart));
3076
- }
3077
- const ctaClick = triggers.manual?.cta_click;
3078
- if (ctaClick) {
3079
- detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
3080
- }
3081
- const phoneClick = triggers.manual?.phone_click;
3082
- if (phoneClick) {
3083
- detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
3084
- }
3085
- return () => {
3086
- for (let i = detachers.length - 1; i >= 0; i--) {
3087
- detachers[i]();
3069
+ return attachClientCapturesOnce(rawClient, () => {
3070
+ const detachers = [];
3071
+ const conversionStore = conversionConfig ? resolveConversionConfig({
3072
+ cdnUrl: conversionConfig.cdnUrl,
3073
+ baked: conversionConfig.baked
3074
+ }) : null;
3075
+ const detectorClient = conversionStore ? withConversionAutoFire(rawClient, createConversionAutoFire(conversionStore)) : rawClient;
3076
+ detachers.push(attachAutoPageView(detectorClient));
3077
+ detachers.push(attachBfcacheRestore(detectorClient));
3078
+ detachers.push(attachPageExit(detectorClient));
3079
+ const timeOnSite = triggers.automatic.time_on_site;
3080
+ if (timeOnSite) {
3081
+ detachers.push(attachTimeOnSite(detectorClient, timeOnSite));
3082
+ }
3083
+ const specificPageVisit = triggers.automatic.specific_page_visit;
3084
+ if (specificPageVisit) {
3085
+ detachers.push(attachSpecificPageVisit(detectorClient, specificPageVisit));
3086
+ }
3087
+ const scrollDepth = triggers.automatic.scroll_depth;
3088
+ if (scrollDepth) {
3089
+ detachers.push(attachScrollDepth(detectorClient, scrollDepth));
3090
+ }
3091
+ const multiPageSession = triggers.automatic.multi_page_session;
3092
+ if (multiPageSession) {
3093
+ detachers.push(attachMultiPageSession(detectorClient, multiPageSession));
3094
+ }
3095
+ const formStart = triggers.automatic.form_start;
3096
+ if (formStart) {
3097
+ detachers.push(attachFormStart(detectorClient, formStart));
3088
3098
  }
3089
- };
3099
+ const ctaClick = triggers.manual?.cta_click;
3100
+ if (ctaClick) {
3101
+ detachers.push(attachCtaClickCapture(detectorClient, ctaClick));
3102
+ }
3103
+ const phoneClick = triggers.manual?.phone_click;
3104
+ if (phoneClick) {
3105
+ detachers.push(attachPhoneClickCapture(detectorClient, phoneClick));
3106
+ }
3107
+ return () => {
3108
+ for (let i = detachers.length - 1; i >= 0; i--) {
3109
+ detachers[i]();
3110
+ }
3111
+ };
3112
+ });
3090
3113
  }, []);
3091
3114
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
3092
3115
  }