@aranova/tracking-react 0.12.1 → 0.13.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/index.mjs CHANGED
@@ -17,21 +17,32 @@ function buildConsentPayload(state) {
17
17
  }
18
18
  function getConsentState() {
19
19
  if (typeof window === "undefined") return "pending";
20
- const storedState = window.localStorage.getItem(CONSENT_STATE_KEY);
21
- if (storedState === "granted" || storedState === "denied") return storedState;
20
+ try {
21
+ const storedState = window.localStorage.getItem(CONSENT_STATE_KEY);
22
+ if (storedState === "granted" || storedState === "denied") return storedState;
23
+ } catch {
24
+ }
22
25
  return "pending";
23
26
  }
24
27
  function setConsentState(state) {
25
28
  if (typeof window === "undefined") return;
26
- window.localStorage.setItem(CONSENT_STATE_KEY, state);
27
- window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
29
+ try {
30
+ window.localStorage.setItem(CONSENT_STATE_KEY, state);
31
+ window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
32
+ } catch {
33
+ }
28
34
  if (typeof window.gtag === "function")
29
35
  window.gtag("consent", "update", buildConsentPayload(state));
36
+ if (typeof window.fbq === "function")
37
+ window.fbq("consent", state === "granted" ? "grant" : "revoke");
30
38
  }
31
39
  function resetConsent() {
32
40
  if (typeof window === "undefined") return;
33
- window.localStorage.removeItem(CONSENT_STATE_KEY);
34
- window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
41
+ try {
42
+ window.localStorage.removeItem(CONSENT_STATE_KEY);
43
+ window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
44
+ } catch {
45
+ }
35
46
  }
36
47
  function restoreStoredConsent() {
37
48
  const consentState = getConsentState();
@@ -39,45 +50,106 @@ function restoreStoredConsent() {
39
50
  return consentState;
40
51
  }
41
52
 
42
- // ../tracking-core/src/payloads.ts
43
- function createTrackingClientContext(surface, input = {}) {
53
+ // ../tracking-core/src/tracking.ts
54
+ var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
55
+ var TRACKING_PARAM_KEYS = [
56
+ "gclid",
57
+ "fbclid",
58
+ "utm_source",
59
+ "utm_medium",
60
+ "utm_campaign",
61
+ "utm_term",
62
+ "utm_content"
63
+ ];
64
+ function createEmptyTrackingParams() {
44
65
  return {
45
- surface,
46
- sdk_version: input.sdkVersion ?? null,
47
- package_name: input.packageName ?? null,
48
- site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
49
- page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
50
- referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
51
- environment: input.environment ?? "production",
52
- active_gtag_ids: input.activeGtagIds ?? null
66
+ gclid: null,
67
+ fbclid: null,
68
+ utm_source: null,
69
+ utm_medium: null,
70
+ utm_campaign: null,
71
+ utm_term: null,
72
+ utm_content: null
53
73
  };
54
74
  }
55
- function createTrackingSessionUpsertPayload(trackingParams, input, context) {
56
- return {
57
- session_id: input.sessionId,
58
- visitor_id: input.visitorId ?? null,
59
- gclid: trackingParams.gclid,
60
- fbclid: trackingParams.fbclid,
61
- utm_source: trackingParams.utm_source,
62
- utm_medium: trackingParams.utm_medium,
63
- utm_campaign: trackingParams.utm_campaign,
64
- utm_term: trackingParams.utm_term,
65
- utm_content: trackingParams.utm_content,
66
- first_page: input.firstPage ?? null,
67
- consent_state: input.consentState ?? null,
68
- context
69
- };
75
+ function normalizeTrackingCookieValue(value) {
76
+ return typeof value === "string" && value.length > 0 ? value : null;
70
77
  }
71
- function createTrackingEventCreatePayload(trackingParams, input, context) {
72
- return {
73
- session_id: input.sessionId,
74
- event_type: input.eventType,
75
- gclid: trackingParams.gclid,
76
- fbclid: trackingParams.fbclid,
77
- page_url: input.pageUrl ?? (typeof window === "undefined" ? null : window.location.href),
78
- metadata: input.metadata ?? null,
79
- context
80
- };
78
+ function getTrackingParamsFromCookieReader(readCookie) {
79
+ return TRACKING_PARAM_KEYS.reduce((params, key) => {
80
+ params[key] = normalizeTrackingCookieValue(readCookie(key));
81
+ return params;
82
+ }, createEmptyTrackingParams());
83
+ }
84
+ function getTrackingQueryValues(searchParams) {
85
+ return TRACKING_PARAM_KEYS.reduce((params, key) => {
86
+ const value = searchParams.get(key);
87
+ if (typeof value === "string" && value.trim().length > 0) {
88
+ params[key] = value;
89
+ }
90
+ return params;
91
+ }, {});
92
+ }
93
+ var FALLBACK_STORAGE_PREFIX = "_aranova_track_";
94
+ function fallbackKey(name) {
95
+ return `${FALLBACK_STORAGE_PREFIX}${name}`;
96
+ }
97
+ function persistCookieValue(name, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
98
+ const encoded = encodeURIComponent(value);
99
+ if (typeof document !== "undefined") {
100
+ try {
101
+ document.cookie = `${name}=${encoded}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
102
+ } catch {
103
+ }
104
+ }
105
+ if (typeof window !== "undefined") {
106
+ try {
107
+ window.localStorage.setItem(fallbackKey(name), encoded);
108
+ } catch {
109
+ }
110
+ }
111
+ }
112
+ function readCookieValue(name) {
113
+ if (typeof document !== "undefined") {
114
+ const cookies = document.cookie ? document.cookie.split("; ") : [];
115
+ const match = cookies.find((cookie) => cookie.startsWith(`${name}=`));
116
+ if (match) {
117
+ const [, rawValue = ""] = match.split("=");
118
+ return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
119
+ }
120
+ }
121
+ if (typeof window !== "undefined") {
122
+ try {
123
+ const stored = window.localStorage.getItem(fallbackKey(name));
124
+ if (stored) return normalizeTrackingCookieValue(decodeURIComponent(stored));
125
+ } catch {
126
+ }
127
+ }
128
+ return null;
129
+ }
130
+ function getCookieValueFromDocument(key) {
131
+ return readCookieValue(key);
132
+ }
133
+ function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
134
+ persistCookieValue(key, value, maxAgeSeconds);
135
+ }
136
+ function mergeTrackingParams(primary, fallback) {
137
+ return TRACKING_PARAM_KEYS.reduce((merged, key) => {
138
+ merged[key] = primary[key] ?? fallback[key];
139
+ return merged;
140
+ }, createEmptyTrackingParams());
141
+ }
142
+ function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
143
+ const trackingValues = getTrackingQueryValues(searchParams);
144
+ Object.entries(trackingValues).forEach(([key, value]) => {
145
+ setTrackingCookie(key, value, maxAgeSeconds);
146
+ });
147
+ return trackingValues;
148
+ }
149
+ function captureTrackingParamsFromLocation(url = typeof window === "undefined" ? "" : window.location.href, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
150
+ const resolvedUrl = typeof window === "undefined" ? new URL(url || "https://example.invalid") : new URL(url, window.location.origin);
151
+ persistTrackingParamsFromSearchParams(resolvedUrl.searchParams, maxAgeSeconds);
152
+ return getTrackingParamsFromCookieReader(getCookieValueFromDocument);
81
153
  }
82
154
 
83
155
  // ../tracking-core/src/gtag.ts
@@ -136,7 +208,9 @@ function bootstrapGoogleAdsTracking(gtagId) {
136
208
  }
137
209
  function bootstrapMultipleGtags(gtagIds) {
138
210
  if (typeof window === "undefined" || typeof document === "undefined") return;
139
- const ids = Object.values(gtagIds).filter(isValidGtagId);
211
+ const ids = Object.values(gtagIds).filter(
212
+ (id) => typeof id === "string" && isValidGtagId(id)
213
+ );
140
214
  if (ids.length === 0) return;
141
215
  applyDefaultConsentState();
142
216
  loadGtagScript(ids[0]);
@@ -148,70 +222,158 @@ function bootstrapMultipleGtags(gtagIds) {
148
222
  restoreStoredConsent();
149
223
  }
150
224
 
151
- // ../tracking-core/src/tracking.ts
152
- var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
153
- var TRACKING_PARAM_KEYS = [
154
- "gclid",
155
- "fbclid",
156
- "utm_source",
157
- "utm_medium",
158
- "utm_campaign",
159
- "utm_term",
160
- "utm_content"
161
- ];
162
- function createEmptyTrackingParams() {
163
- return {
164
- gclid: null,
165
- fbclid: null,
166
- utm_source: null,
167
- utm_medium: null,
168
- utm_campaign: null,
169
- utm_term: null,
170
- utm_content: null
171
- };
225
+ // ../tracking-core/src/fbq.ts
226
+ var FB_EVENTS_SCRIPT_HOST = "https://connect.facebook.net/en_US/fbevents.js";
227
+ var FBC_COOKIE = "_fbc";
228
+ var FBP_COOKIE = "_fbp";
229
+ var META_PIXEL_ID_PATTERN = /^\d{15,16}$/;
230
+ function isValidMetaPixelId(id) {
231
+ return META_PIXEL_ID_PATTERN.test(id);
232
+ }
233
+ function computeFbSubdomainIndex(hostname) {
234
+ const labels = hostname.split(".").filter(Boolean);
235
+ return Math.max(0, labels.length - 1);
236
+ }
237
+ function buildFbc(fbclid, now, hostname) {
238
+ const host = hostname ?? (typeof window === "undefined" ? "" : window.location.hostname);
239
+ return `fb.${computeFbSubdomainIndex(host)}.${now}.${fbclid}`;
240
+ }
241
+ function getFbcCookie() {
242
+ return readCookieValue(FBC_COOKIE);
243
+ }
244
+ function getFbpCookie() {
245
+ return readCookieValue(FBP_COOKIE);
246
+ }
247
+ function readFbclidFromUrl() {
248
+ if (typeof window === "undefined") return null;
249
+ try {
250
+ const value = new URL(window.location.href).searchParams.get("fbclid");
251
+ return value && value.trim().length > 0 ? value : null;
252
+ } catch {
253
+ return null;
254
+ }
172
255
  }
173
- function normalizeTrackingCookieValue(value) {
174
- return typeof value === "string" && value.length > 0 ? value : null;
256
+ function captureFbc(now = typeof Date === "undefined" ? 0 : Date.now()) {
257
+ if (typeof window === "undefined") return;
258
+ if (getFbcCookie()) return;
259
+ const fbclid = readFbclidFromUrl() ?? readCookieValue("fbclid");
260
+ if (!fbclid) return;
261
+ persistCookieValue(FBC_COOKIE, buildFbc(fbclid, now), TRACKING_COOKIE_MAX_AGE_SECONDS);
175
262
  }
176
- function getTrackingParamsFromCookieReader(readCookie) {
177
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
178
- params[key] = normalizeTrackingCookieValue(readCookie(key));
179
- return params;
180
- }, createEmptyTrackingParams());
263
+ function getScriptMarker2(id) {
264
+ return `aranova-${id}`;
181
265
  }
182
- function getTrackingQueryValues(searchParams) {
183
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
184
- const value = searchParams.get(key);
185
- if (typeof value === "string" && value.trim().length > 0) {
186
- params[key] = value;
187
- }
188
- return params;
189
- }, {});
266
+ function ensureFbqFunction() {
267
+ const w = window;
268
+ if (typeof w.fbq === "function") return w.fbq;
269
+ const fbq = function(...args) {
270
+ if (fbq.callMethod) fbq.callMethod.apply(fbq, args);
271
+ else fbq.queue.push(args);
272
+ };
273
+ fbq.push = fbq;
274
+ fbq.loaded = true;
275
+ fbq.version = "2.0";
276
+ fbq.queue = [];
277
+ w.fbq = fbq;
278
+ if (!w._fbq) w._fbq = fbq;
279
+ return fbq;
280
+ }
281
+ function applyDefaultMetaConsentState() {
282
+ ensureFbqFunction()("consent", "revoke");
283
+ }
284
+ function loadFbeventsScript() {
285
+ if (typeof document === "undefined") return;
286
+ const marker = getScriptMarker2("fbq-loader");
287
+ const existing = document.querySelector(
288
+ `script[${TRACKING_SCRIPT_ATTRIBUTE}="${marker}"]`
289
+ );
290
+ if (existing) return;
291
+ const script = document.createElement("script");
292
+ script.async = true;
293
+ script.src = FB_EVENTS_SCRIPT_HOST;
294
+ script.setAttribute(TRACKING_SCRIPT_ATTRIBUTE, marker);
295
+ document.head.append(script);
190
296
  }
191
- function getCookieValueFromDocument(key) {
192
- if (typeof document === "undefined") return null;
193
- const cookies = document.cookie ? document.cookie.split("; ") : [];
194
- const match = cookies.find((cookie) => cookie.startsWith(`${key}=`));
195
- if (!match) return null;
196
- const [, rawValue = ""] = match.split("=");
197
- return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
297
+ function initializeMetaPixel(pixelId) {
298
+ const fbq = ensureFbqFunction();
299
+ fbq("init", pixelId);
300
+ fbq("track", "PageView");
198
301
  }
199
- function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
200
- if (typeof document === "undefined") return;
201
- const encodedValue = encodeURIComponent(value);
202
- document.cookie = `${key}=${encodedValue}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
302
+ function restoreMetaConsentState() {
303
+ if (typeof window === "undefined") return;
304
+ const state = getConsentState();
305
+ if (state === "granted") window.fbq?.("consent", "grant");
306
+ else if (state === "denied") window.fbq?.("consent", "revoke");
203
307
  }
204
- function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
205
- const trackingValues = getTrackingQueryValues(searchParams);
206
- Object.entries(trackingValues).forEach(([key, value]) => {
207
- setTrackingCookie(key, value, maxAgeSeconds);
208
- });
209
- return trackingValues;
308
+ function bootstrapMetaPixel(pixelId) {
309
+ if (typeof window === "undefined" || typeof document === "undefined") return;
310
+ if (!isValidMetaPixelId(pixelId)) return;
311
+ applyDefaultMetaConsentState();
312
+ loadFbeventsScript();
313
+ initializeMetaPixel(pixelId);
314
+ restoreMetaConsentState();
315
+ captureFbc();
316
+ }
317
+ function bootstrapMultiplePixels(pixelIds) {
318
+ if (typeof window === "undefined" || typeof document === "undefined") return;
319
+ const ids = Object.values(pixelIds).filter(
320
+ (id) => typeof id === "string" && isValidMetaPixelId(id)
321
+ );
322
+ if (ids.length === 0) return;
323
+ applyDefaultMetaConsentState();
324
+ loadFbeventsScript();
325
+ const fbq = ensureFbqFunction();
326
+ for (const id of ids) {
327
+ fbq("init", id);
328
+ }
329
+ fbq("track", "PageView");
330
+ restoreMetaConsentState();
331
+ captureFbc();
210
332
  }
211
- function captureTrackingParamsFromLocation(url = typeof window === "undefined" ? "" : window.location.href, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
212
- const resolvedUrl = typeof window === "undefined" ? new URL(url || "https://example.invalid") : new URL(url, window.location.origin);
213
- persistTrackingParamsFromSearchParams(resolvedUrl.searchParams, maxAgeSeconds);
214
- return getTrackingParamsFromCookieReader(getCookieValueFromDocument);
333
+
334
+ // ../tracking-core/src/payloads.ts
335
+ function createTrackingClientContext(surface, input = {}) {
336
+ return {
337
+ surface,
338
+ sdk_version: input.sdkVersion ?? null,
339
+ package_name: input.packageName ?? null,
340
+ site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
341
+ page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
342
+ referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
343
+ environment: input.environment ?? "production",
344
+ active_gtag_ids: input.activeGtagIds ?? null
345
+ };
346
+ }
347
+ function createTrackingSessionUpsertPayload(trackingParams, input, context) {
348
+ return {
349
+ session_id: input.sessionId,
350
+ visitor_id: input.visitorId ?? null,
351
+ gclid: trackingParams.gclid,
352
+ fbclid: trackingParams.fbclid,
353
+ fbc: getFbcCookie(),
354
+ fbp: getFbpCookie(),
355
+ utm_source: trackingParams.utm_source,
356
+ utm_medium: trackingParams.utm_medium,
357
+ utm_campaign: trackingParams.utm_campaign,
358
+ utm_term: trackingParams.utm_term,
359
+ utm_content: trackingParams.utm_content,
360
+ first_page: input.firstPage ?? null,
361
+ consent_state: input.consentState ?? null,
362
+ context
363
+ };
364
+ }
365
+ function createTrackingEventCreatePayload(trackingParams, input, context) {
366
+ return {
367
+ session_id: input.sessionId,
368
+ event_type: input.eventType,
369
+ gclid: trackingParams.gclid,
370
+ fbclid: trackingParams.fbclid,
371
+ fbc: getFbcCookie(),
372
+ fbp: getFbpCookie(),
373
+ page_url: input.pageUrl ?? (typeof window === "undefined" ? null : window.location.href),
374
+ metadata: input.metadata ?? null,
375
+ context
376
+ };
215
377
  }
216
378
 
217
379
  // ../tracking-core/src/session.ts
@@ -542,11 +704,22 @@ function createTrackingClient(config) {
542
704
  let queue = [];
543
705
  let flushTimer = null;
544
706
  let firstPage = null;
707
+ let initialParams = createEmptyTrackingParams();
545
708
  let destroyed = false;
546
709
  const visitorId = getVisitorId();
547
710
  const initialSession = getOrRotateSessionId();
548
711
  let sessionId = initialSession.id;
549
- if (typeof window !== "undefined") firstPage = window.location.href;
712
+ if (typeof window !== "undefined") {
713
+ firstPage = window.location.href;
714
+ try {
715
+ initialParams = captureTrackingParamsFromLocation();
716
+ } catch {
717
+ }
718
+ try {
719
+ captureFbc();
720
+ } catch {
721
+ }
722
+ }
550
723
  function enqueueHeartbeat() {
551
724
  const metadata = buildHeartbeatMetadata(
552
725
  config.surface,
@@ -571,7 +744,7 @@ function createTrackingClient(config) {
571
744
  enqueueHeartbeat();
572
745
  }
573
746
  sessionId = rotated.id;
574
- const params = readTrackingParams();
747
+ const params = mergeTrackingParams(readTrackingParams(), initialParams);
575
748
  const context = buildContext(
576
749
  config.surface,
577
750
  sdkVersion,
@@ -584,6 +757,8 @@ function createTrackingClient(config) {
584
757
  visitor_id: visitorId,
585
758
  gclid: params.gclid,
586
759
  fbclid: params.fbclid,
760
+ fbc: getFbcCookie(),
761
+ fbp: getFbpCookie(),
587
762
  utm_source: params.utm_source,
588
763
  utm_medium: params.utm_medium,
589
764
  utm_campaign: params.utm_campaign,
@@ -1833,11 +2008,19 @@ var ANIMATION_KEYFRAMES = `
1833
2008
  }
1834
2009
  `;
1835
2010
 
1836
- // src/GoogleAdsTracking.tsx
2011
+ // src/AdPlatformTracking.tsx
1837
2012
  import { useEffect as useEffect3, useMemo } from "react";
1838
- function GoogleAdsTracking(props) {
1839
- const { gtagId, gtagIds } = props;
2013
+ function AdPlatformTracking({
2014
+ gtagId,
2015
+ gtagIds,
2016
+ metaPixelId,
2017
+ metaPixelIds
2018
+ }) {
1840
2019
  const gtagIdsKey = useMemo(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2020
+ const metaPixelIdsKey = useMemo(
2021
+ () => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
2022
+ [metaPixelIds]
2023
+ );
1841
2024
  useEffect3(() => {
1842
2025
  if (gtagIds && Object.keys(gtagIds).length > 0) {
1843
2026
  bootstrapMultipleGtags(gtagIds);
@@ -1845,14 +2028,36 @@ function GoogleAdsTracking(props) {
1845
2028
  bootstrapGoogleAdsTracking(gtagId);
1846
2029
  }
1847
2030
  }, [gtagId, gtagIdsKey]);
2031
+ useEffect3(() => {
2032
+ if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
2033
+ bootstrapMultiplePixels(metaPixelIds);
2034
+ } else if (metaPixelId) {
2035
+ bootstrapMetaPixel(metaPixelId);
2036
+ }
2037
+ }, [metaPixelId, metaPixelIdsKey]);
2038
+ return null;
2039
+ }
2040
+
2041
+ // src/GoogleAdsTracking.tsx
2042
+ import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
2043
+ function GoogleAdsTracking(props) {
2044
+ const { gtagId, gtagIds } = props;
2045
+ const gtagIdsKey = useMemo2(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2046
+ useEffect4(() => {
2047
+ if (gtagIds && Object.keys(gtagIds).length > 0) {
2048
+ bootstrapMultipleGtags(gtagIds);
2049
+ } else if (gtagId) {
2050
+ bootstrapGoogleAdsTracking(gtagId);
2051
+ }
2052
+ }, [gtagId, gtagIdsKey]);
1848
2053
  return null;
1849
2054
  }
1850
2055
 
1851
2056
  // src/factory.tsx
1852
- import { createContext as createContext2, useContext as useContext2, useEffect as useEffect4, useMemo as useMemo3 } from "react";
2057
+ import { createContext as createContext2, useContext as useContext2, useEffect as useEffect5, useMemo as useMemo4 } from "react";
1853
2058
 
1854
2059
  // package.json
1855
- var version = "0.12.1";
2060
+ var version = "0.13.0";
1856
2061
 
1857
2062
  // ../tracking-core/src/phone-react.tsx
1858
2063
  import {
@@ -1860,7 +2065,7 @@ import {
1860
2065
  forwardRef,
1861
2066
  useCallback as useCallback2,
1862
2067
  useContext,
1863
- useMemo as useMemo2,
2068
+ useMemo as useMemo3,
1864
2069
  useState as useState3
1865
2070
  } from "react";
1866
2071
  import { jsx as jsx2 } from "react/jsx-runtime";
@@ -1889,7 +2094,7 @@ function usePhoneField(opts = {}) {
1889
2094
  const { onValueChange } = opts;
1890
2095
  const [value, setValue] = useState3(() => formatPhoneAsTyped(opts.defaultValue ?? "", country));
1891
2096
  const [touched, setTouched] = useState3(false);
1892
- const parsed = useMemo2(() => parsePhone(value, country), [value, country]);
2097
+ const parsed = useMemo3(() => parsePhone(value, country), [value, country]);
1893
2098
  const onChange = useCallback2(
1894
2099
  (event) => {
1895
2100
  const next = formatPhoneAsTyped(event.target.value, country);
@@ -1974,9 +2179,17 @@ function createTracking(options) {
1974
2179
  };
1975
2180
  }
1976
2181
  const TrackingContext = createContext2(null);
1977
- function TrackingProvider({ gtagId, gtagIds, children }) {
1978
- const resolvedGtagIds = gtagIds ?? (gtagId ? { default: gtagId } : void 0);
1979
- const client = useMemo3(
2182
+ function TrackingProvider({
2183
+ gtagId,
2184
+ gtagIds,
2185
+ metaPixelId,
2186
+ metaPixelIds,
2187
+ children
2188
+ }) {
2189
+ const resolvedGtagIds = gtagIds ? Object.fromEntries(
2190
+ Object.entries(gtagIds).filter((e) => e[1] != null)
2191
+ ) : gtagId ? { default: gtagId } : void 0;
2192
+ const client = useMemo4(
1980
2193
  () => createTypedClient(
1981
2194
  getOrCreateTrackingClient({
1982
2195
  apiKey,
@@ -1994,15 +2207,26 @@ function createTracking(options) {
1994
2207
  ),
1995
2208
  []
1996
2209
  );
1997
- const gtagIdsKey = useMemo3(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
1998
- useEffect4(() => {
2210
+ const gtagIdsKey = useMemo4(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2211
+ useEffect5(() => {
1999
2212
  if (gtagIds && Object.keys(gtagIds).length > 0) {
2000
2213
  bootstrapMultipleGtags(gtagIds);
2001
2214
  } else if (gtagId) {
2002
2215
  bootstrapGoogleAdsTracking(gtagId);
2003
2216
  }
2004
2217
  }, [gtagId, gtagIdsKey]);
2005
- useEffect4(() => {
2218
+ const metaPixelIdsKey = useMemo4(
2219
+ () => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
2220
+ [metaPixelIds]
2221
+ );
2222
+ useEffect5(() => {
2223
+ if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
2224
+ bootstrapMultiplePixels(metaPixelIds);
2225
+ } else if (metaPixelId) {
2226
+ bootstrapMetaPixel(metaPixelId);
2227
+ }
2228
+ }, [metaPixelId, metaPixelIdsKey]);
2229
+ useEffect5(() => {
2006
2230
  const detachers = [];
2007
2231
  const rawClient = getOrCreateTrackingClient({
2008
2232
  apiKey,
@@ -2056,6 +2280,7 @@ function createTracking(options) {
2056
2280
  return { TrackingProvider, useTracking };
2057
2281
  }
2058
2282
  export {
2283
+ AdPlatformTracking,
2059
2284
  AranovaApiError,
2060
2285
  ConsentBanner,
2061
2286
  DEFAULT_PHONE_COUNTRY,