@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.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ AdPlatformTracking: () => AdPlatformTracking,
23
24
  AranovaApiError: () => AranovaApiError,
24
25
  ConsentBanner: () => ConsentBanner,
25
26
  DEFAULT_PHONE_COUNTRY: () => DEFAULT_PHONE_COUNTRY,
@@ -81,21 +82,32 @@ function buildConsentPayload(state) {
81
82
  }
82
83
  function getConsentState() {
83
84
  if (typeof window === "undefined") return "pending";
84
- const storedState = window.localStorage.getItem(CONSENT_STATE_KEY);
85
- if (storedState === "granted" || storedState === "denied") return storedState;
85
+ try {
86
+ const storedState = window.localStorage.getItem(CONSENT_STATE_KEY);
87
+ if (storedState === "granted" || storedState === "denied") return storedState;
88
+ } catch {
89
+ }
86
90
  return "pending";
87
91
  }
88
92
  function setConsentState(state) {
89
93
  if (typeof window === "undefined") return;
90
- window.localStorage.setItem(CONSENT_STATE_KEY, state);
91
- window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
94
+ try {
95
+ window.localStorage.setItem(CONSENT_STATE_KEY, state);
96
+ window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
97
+ } catch {
98
+ }
92
99
  if (typeof window.gtag === "function")
93
100
  window.gtag("consent", "update", buildConsentPayload(state));
101
+ if (typeof window.fbq === "function")
102
+ window.fbq("consent", state === "granted" ? "grant" : "revoke");
94
103
  }
95
104
  function resetConsent() {
96
105
  if (typeof window === "undefined") return;
97
- window.localStorage.removeItem(CONSENT_STATE_KEY);
98
- window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
106
+ try {
107
+ window.localStorage.removeItem(CONSENT_STATE_KEY);
108
+ window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
109
+ } catch {
110
+ }
99
111
  }
100
112
  function restoreStoredConsent() {
101
113
  const consentState = getConsentState();
@@ -103,45 +115,106 @@ function restoreStoredConsent() {
103
115
  return consentState;
104
116
  }
105
117
 
106
- // ../tracking-core/src/payloads.ts
107
- function createTrackingClientContext(surface, input = {}) {
118
+ // ../tracking-core/src/tracking.ts
119
+ var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
120
+ var TRACKING_PARAM_KEYS = [
121
+ "gclid",
122
+ "fbclid",
123
+ "utm_source",
124
+ "utm_medium",
125
+ "utm_campaign",
126
+ "utm_term",
127
+ "utm_content"
128
+ ];
129
+ function createEmptyTrackingParams() {
108
130
  return {
109
- surface,
110
- sdk_version: input.sdkVersion ?? null,
111
- package_name: input.packageName ?? null,
112
- site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
113
- page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
114
- referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
115
- environment: input.environment ?? "production",
116
- active_gtag_ids: input.activeGtagIds ?? null
131
+ gclid: null,
132
+ fbclid: null,
133
+ utm_source: null,
134
+ utm_medium: null,
135
+ utm_campaign: null,
136
+ utm_term: null,
137
+ utm_content: null
117
138
  };
118
139
  }
119
- function createTrackingSessionUpsertPayload(trackingParams, input, context) {
120
- return {
121
- session_id: input.sessionId,
122
- visitor_id: input.visitorId ?? null,
123
- gclid: trackingParams.gclid,
124
- fbclid: trackingParams.fbclid,
125
- utm_source: trackingParams.utm_source,
126
- utm_medium: trackingParams.utm_medium,
127
- utm_campaign: trackingParams.utm_campaign,
128
- utm_term: trackingParams.utm_term,
129
- utm_content: trackingParams.utm_content,
130
- first_page: input.firstPage ?? null,
131
- consent_state: input.consentState ?? null,
132
- context
133
- };
140
+ function normalizeTrackingCookieValue(value) {
141
+ return typeof value === "string" && value.length > 0 ? value : null;
134
142
  }
135
- function createTrackingEventCreatePayload(trackingParams, input, context) {
136
- return {
137
- session_id: input.sessionId,
138
- event_type: input.eventType,
139
- gclid: trackingParams.gclid,
140
- fbclid: trackingParams.fbclid,
141
- page_url: input.pageUrl ?? (typeof window === "undefined" ? null : window.location.href),
142
- metadata: input.metadata ?? null,
143
- context
144
- };
143
+ function getTrackingParamsFromCookieReader(readCookie) {
144
+ return TRACKING_PARAM_KEYS.reduce((params, key) => {
145
+ params[key] = normalizeTrackingCookieValue(readCookie(key));
146
+ return params;
147
+ }, createEmptyTrackingParams());
148
+ }
149
+ function getTrackingQueryValues(searchParams) {
150
+ return TRACKING_PARAM_KEYS.reduce((params, key) => {
151
+ const value = searchParams.get(key);
152
+ if (typeof value === "string" && value.trim().length > 0) {
153
+ params[key] = value;
154
+ }
155
+ return params;
156
+ }, {});
157
+ }
158
+ var FALLBACK_STORAGE_PREFIX = "_aranova_track_";
159
+ function fallbackKey(name) {
160
+ return `${FALLBACK_STORAGE_PREFIX}${name}`;
161
+ }
162
+ function persistCookieValue(name, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
163
+ const encoded = encodeURIComponent(value);
164
+ if (typeof document !== "undefined") {
165
+ try {
166
+ document.cookie = `${name}=${encoded}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
167
+ } catch {
168
+ }
169
+ }
170
+ if (typeof window !== "undefined") {
171
+ try {
172
+ window.localStorage.setItem(fallbackKey(name), encoded);
173
+ } catch {
174
+ }
175
+ }
176
+ }
177
+ function readCookieValue(name) {
178
+ if (typeof document !== "undefined") {
179
+ const cookies = document.cookie ? document.cookie.split("; ") : [];
180
+ const match = cookies.find((cookie) => cookie.startsWith(`${name}=`));
181
+ if (match) {
182
+ const [, rawValue = ""] = match.split("=");
183
+ return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
184
+ }
185
+ }
186
+ if (typeof window !== "undefined") {
187
+ try {
188
+ const stored = window.localStorage.getItem(fallbackKey(name));
189
+ if (stored) return normalizeTrackingCookieValue(decodeURIComponent(stored));
190
+ } catch {
191
+ }
192
+ }
193
+ return null;
194
+ }
195
+ function getCookieValueFromDocument(key) {
196
+ return readCookieValue(key);
197
+ }
198
+ function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
199
+ persistCookieValue(key, value, maxAgeSeconds);
200
+ }
201
+ function mergeTrackingParams(primary, fallback) {
202
+ return TRACKING_PARAM_KEYS.reduce((merged, key) => {
203
+ merged[key] = primary[key] ?? fallback[key];
204
+ return merged;
205
+ }, createEmptyTrackingParams());
206
+ }
207
+ function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
208
+ const trackingValues = getTrackingQueryValues(searchParams);
209
+ Object.entries(trackingValues).forEach(([key, value]) => {
210
+ setTrackingCookie(key, value, maxAgeSeconds);
211
+ });
212
+ return trackingValues;
213
+ }
214
+ function captureTrackingParamsFromLocation(url = typeof window === "undefined" ? "" : window.location.href, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
215
+ const resolvedUrl = typeof window === "undefined" ? new URL(url || "https://example.invalid") : new URL(url, window.location.origin);
216
+ persistTrackingParamsFromSearchParams(resolvedUrl.searchParams, maxAgeSeconds);
217
+ return getTrackingParamsFromCookieReader(getCookieValueFromDocument);
145
218
  }
146
219
 
147
220
  // ../tracking-core/src/gtag.ts
@@ -200,7 +273,9 @@ function bootstrapGoogleAdsTracking(gtagId) {
200
273
  }
201
274
  function bootstrapMultipleGtags(gtagIds) {
202
275
  if (typeof window === "undefined" || typeof document === "undefined") return;
203
- const ids = Object.values(gtagIds).filter(isValidGtagId);
276
+ const ids = Object.values(gtagIds).filter(
277
+ (id) => typeof id === "string" && isValidGtagId(id)
278
+ );
204
279
  if (ids.length === 0) return;
205
280
  applyDefaultConsentState();
206
281
  loadGtagScript(ids[0]);
@@ -212,70 +287,158 @@ function bootstrapMultipleGtags(gtagIds) {
212
287
  restoreStoredConsent();
213
288
  }
214
289
 
215
- // ../tracking-core/src/tracking.ts
216
- var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
217
- var TRACKING_PARAM_KEYS = [
218
- "gclid",
219
- "fbclid",
220
- "utm_source",
221
- "utm_medium",
222
- "utm_campaign",
223
- "utm_term",
224
- "utm_content"
225
- ];
226
- function createEmptyTrackingParams() {
227
- return {
228
- gclid: null,
229
- fbclid: null,
230
- utm_source: null,
231
- utm_medium: null,
232
- utm_campaign: null,
233
- utm_term: null,
234
- utm_content: null
235
- };
290
+ // ../tracking-core/src/fbq.ts
291
+ var FB_EVENTS_SCRIPT_HOST = "https://connect.facebook.net/en_US/fbevents.js";
292
+ var FBC_COOKIE = "_fbc";
293
+ var FBP_COOKIE = "_fbp";
294
+ var META_PIXEL_ID_PATTERN = /^\d{15,16}$/;
295
+ function isValidMetaPixelId(id) {
296
+ return META_PIXEL_ID_PATTERN.test(id);
297
+ }
298
+ function computeFbSubdomainIndex(hostname) {
299
+ const labels = hostname.split(".").filter(Boolean);
300
+ return Math.max(0, labels.length - 1);
301
+ }
302
+ function buildFbc(fbclid, now, hostname) {
303
+ const host = hostname ?? (typeof window === "undefined" ? "" : window.location.hostname);
304
+ return `fb.${computeFbSubdomainIndex(host)}.${now}.${fbclid}`;
305
+ }
306
+ function getFbcCookie() {
307
+ return readCookieValue(FBC_COOKIE);
308
+ }
309
+ function getFbpCookie() {
310
+ return readCookieValue(FBP_COOKIE);
311
+ }
312
+ function readFbclidFromUrl() {
313
+ if (typeof window === "undefined") return null;
314
+ try {
315
+ const value = new URL(window.location.href).searchParams.get("fbclid");
316
+ return value && value.trim().length > 0 ? value : null;
317
+ } catch {
318
+ return null;
319
+ }
236
320
  }
237
- function normalizeTrackingCookieValue(value) {
238
- return typeof value === "string" && value.length > 0 ? value : null;
321
+ function captureFbc(now = typeof Date === "undefined" ? 0 : Date.now()) {
322
+ if (typeof window === "undefined") return;
323
+ if (getFbcCookie()) return;
324
+ const fbclid = readFbclidFromUrl() ?? readCookieValue("fbclid");
325
+ if (!fbclid) return;
326
+ persistCookieValue(FBC_COOKIE, buildFbc(fbclid, now), TRACKING_COOKIE_MAX_AGE_SECONDS);
239
327
  }
240
- function getTrackingParamsFromCookieReader(readCookie) {
241
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
242
- params[key] = normalizeTrackingCookieValue(readCookie(key));
243
- return params;
244
- }, createEmptyTrackingParams());
328
+ function getScriptMarker2(id) {
329
+ return `aranova-${id}`;
245
330
  }
246
- function getTrackingQueryValues(searchParams) {
247
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
248
- const value = searchParams.get(key);
249
- if (typeof value === "string" && value.trim().length > 0) {
250
- params[key] = value;
251
- }
252
- return params;
253
- }, {});
331
+ function ensureFbqFunction() {
332
+ const w = window;
333
+ if (typeof w.fbq === "function") return w.fbq;
334
+ const fbq = function(...args) {
335
+ if (fbq.callMethod) fbq.callMethod.apply(fbq, args);
336
+ else fbq.queue.push(args);
337
+ };
338
+ fbq.push = fbq;
339
+ fbq.loaded = true;
340
+ fbq.version = "2.0";
341
+ fbq.queue = [];
342
+ w.fbq = fbq;
343
+ if (!w._fbq) w._fbq = fbq;
344
+ return fbq;
345
+ }
346
+ function applyDefaultMetaConsentState() {
347
+ ensureFbqFunction()("consent", "revoke");
348
+ }
349
+ function loadFbeventsScript() {
350
+ if (typeof document === "undefined") return;
351
+ const marker = getScriptMarker2("fbq-loader");
352
+ const existing = document.querySelector(
353
+ `script[${TRACKING_SCRIPT_ATTRIBUTE}="${marker}"]`
354
+ );
355
+ if (existing) return;
356
+ const script = document.createElement("script");
357
+ script.async = true;
358
+ script.src = FB_EVENTS_SCRIPT_HOST;
359
+ script.setAttribute(TRACKING_SCRIPT_ATTRIBUTE, marker);
360
+ document.head.append(script);
254
361
  }
255
- function getCookieValueFromDocument(key) {
256
- if (typeof document === "undefined") return null;
257
- const cookies = document.cookie ? document.cookie.split("; ") : [];
258
- const match = cookies.find((cookie) => cookie.startsWith(`${key}=`));
259
- if (!match) return null;
260
- const [, rawValue = ""] = match.split("=");
261
- return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
362
+ function initializeMetaPixel(pixelId) {
363
+ const fbq = ensureFbqFunction();
364
+ fbq("init", pixelId);
365
+ fbq("track", "PageView");
262
366
  }
263
- function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
264
- if (typeof document === "undefined") return;
265
- const encodedValue = encodeURIComponent(value);
266
- document.cookie = `${key}=${encodedValue}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
367
+ function restoreMetaConsentState() {
368
+ if (typeof window === "undefined") return;
369
+ const state = getConsentState();
370
+ if (state === "granted") window.fbq?.("consent", "grant");
371
+ else if (state === "denied") window.fbq?.("consent", "revoke");
267
372
  }
268
- function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
269
- const trackingValues = getTrackingQueryValues(searchParams);
270
- Object.entries(trackingValues).forEach(([key, value]) => {
271
- setTrackingCookie(key, value, maxAgeSeconds);
272
- });
273
- return trackingValues;
373
+ function bootstrapMetaPixel(pixelId) {
374
+ if (typeof window === "undefined" || typeof document === "undefined") return;
375
+ if (!isValidMetaPixelId(pixelId)) return;
376
+ applyDefaultMetaConsentState();
377
+ loadFbeventsScript();
378
+ initializeMetaPixel(pixelId);
379
+ restoreMetaConsentState();
380
+ captureFbc();
381
+ }
382
+ function bootstrapMultiplePixels(pixelIds) {
383
+ if (typeof window === "undefined" || typeof document === "undefined") return;
384
+ const ids = Object.values(pixelIds).filter(
385
+ (id) => typeof id === "string" && isValidMetaPixelId(id)
386
+ );
387
+ if (ids.length === 0) return;
388
+ applyDefaultMetaConsentState();
389
+ loadFbeventsScript();
390
+ const fbq = ensureFbqFunction();
391
+ for (const id of ids) {
392
+ fbq("init", id);
393
+ }
394
+ fbq("track", "PageView");
395
+ restoreMetaConsentState();
396
+ captureFbc();
274
397
  }
275
- function captureTrackingParamsFromLocation(url = typeof window === "undefined" ? "" : window.location.href, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
276
- const resolvedUrl = typeof window === "undefined" ? new URL(url || "https://example.invalid") : new URL(url, window.location.origin);
277
- persistTrackingParamsFromSearchParams(resolvedUrl.searchParams, maxAgeSeconds);
278
- return getTrackingParamsFromCookieReader(getCookieValueFromDocument);
398
+
399
+ // ../tracking-core/src/payloads.ts
400
+ function createTrackingClientContext(surface, input = {}) {
401
+ return {
402
+ surface,
403
+ sdk_version: input.sdkVersion ?? null,
404
+ package_name: input.packageName ?? null,
405
+ site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
406
+ page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
407
+ referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
408
+ environment: input.environment ?? "production",
409
+ active_gtag_ids: input.activeGtagIds ?? null
410
+ };
411
+ }
412
+ function createTrackingSessionUpsertPayload(trackingParams, input, context) {
413
+ return {
414
+ session_id: input.sessionId,
415
+ visitor_id: input.visitorId ?? null,
416
+ gclid: trackingParams.gclid,
417
+ fbclid: trackingParams.fbclid,
418
+ fbc: getFbcCookie(),
419
+ fbp: getFbpCookie(),
420
+ utm_source: trackingParams.utm_source,
421
+ utm_medium: trackingParams.utm_medium,
422
+ utm_campaign: trackingParams.utm_campaign,
423
+ utm_term: trackingParams.utm_term,
424
+ utm_content: trackingParams.utm_content,
425
+ first_page: input.firstPage ?? null,
426
+ consent_state: input.consentState ?? null,
427
+ context
428
+ };
429
+ }
430
+ function createTrackingEventCreatePayload(trackingParams, input, context) {
431
+ return {
432
+ session_id: input.sessionId,
433
+ event_type: input.eventType,
434
+ gclid: trackingParams.gclid,
435
+ fbclid: trackingParams.fbclid,
436
+ fbc: getFbcCookie(),
437
+ fbp: getFbpCookie(),
438
+ page_url: input.pageUrl ?? (typeof window === "undefined" ? null : window.location.href),
439
+ metadata: input.metadata ?? null,
440
+ context
441
+ };
279
442
  }
280
443
 
281
444
  // ../tracking-core/src/session.ts
@@ -606,11 +769,22 @@ function createTrackingClient(config) {
606
769
  let queue = [];
607
770
  let flushTimer = null;
608
771
  let firstPage = null;
772
+ let initialParams = createEmptyTrackingParams();
609
773
  let destroyed = false;
610
774
  const visitorId = getVisitorId();
611
775
  const initialSession = getOrRotateSessionId();
612
776
  let sessionId = initialSession.id;
613
- if (typeof window !== "undefined") firstPage = window.location.href;
777
+ if (typeof window !== "undefined") {
778
+ firstPage = window.location.href;
779
+ try {
780
+ initialParams = captureTrackingParamsFromLocation();
781
+ } catch {
782
+ }
783
+ try {
784
+ captureFbc();
785
+ } catch {
786
+ }
787
+ }
614
788
  function enqueueHeartbeat() {
615
789
  const metadata = buildHeartbeatMetadata(
616
790
  config.surface,
@@ -635,7 +809,7 @@ function createTrackingClient(config) {
635
809
  enqueueHeartbeat();
636
810
  }
637
811
  sessionId = rotated.id;
638
- const params = readTrackingParams();
812
+ const params = mergeTrackingParams(readTrackingParams(), initialParams);
639
813
  const context = buildContext(
640
814
  config.surface,
641
815
  sdkVersion,
@@ -648,6 +822,8 @@ function createTrackingClient(config) {
648
822
  visitor_id: visitorId,
649
823
  gclid: params.gclid,
650
824
  fbclid: params.fbclid,
825
+ fbc: getFbcCookie(),
826
+ fbp: getFbpCookie(),
651
827
  utm_source: params.utm_source,
652
828
  utm_medium: params.utm_medium,
653
829
  utm_campaign: params.utm_campaign,
@@ -1897,12 +2073,42 @@ var ANIMATION_KEYFRAMES = `
1897
2073
  }
1898
2074
  `;
1899
2075
 
1900
- // src/GoogleAdsTracking.tsx
2076
+ // src/AdPlatformTracking.tsx
1901
2077
  var import_react3 = require("react");
1902
- function GoogleAdsTracking(props) {
1903
- const { gtagId, gtagIds } = props;
2078
+ function AdPlatformTracking({
2079
+ gtagId,
2080
+ gtagIds,
2081
+ metaPixelId,
2082
+ metaPixelIds
2083
+ }) {
1904
2084
  const gtagIdsKey = (0, import_react3.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2085
+ const metaPixelIdsKey = (0, import_react3.useMemo)(
2086
+ () => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
2087
+ [metaPixelIds]
2088
+ );
2089
+ (0, import_react3.useEffect)(() => {
2090
+ if (gtagIds && Object.keys(gtagIds).length > 0) {
2091
+ bootstrapMultipleGtags(gtagIds);
2092
+ } else if (gtagId) {
2093
+ bootstrapGoogleAdsTracking(gtagId);
2094
+ }
2095
+ }, [gtagId, gtagIdsKey]);
1905
2096
  (0, import_react3.useEffect)(() => {
2097
+ if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
2098
+ bootstrapMultiplePixels(metaPixelIds);
2099
+ } else if (metaPixelId) {
2100
+ bootstrapMetaPixel(metaPixelId);
2101
+ }
2102
+ }, [metaPixelId, metaPixelIdsKey]);
2103
+ return null;
2104
+ }
2105
+
2106
+ // src/GoogleAdsTracking.tsx
2107
+ var import_react4 = require("react");
2108
+ function GoogleAdsTracking(props) {
2109
+ const { gtagId, gtagIds } = props;
2110
+ const gtagIdsKey = (0, import_react4.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2111
+ (0, import_react4.useEffect)(() => {
1906
2112
  if (gtagIds && Object.keys(gtagIds).length > 0) {
1907
2113
  bootstrapMultipleGtags(gtagIds);
1908
2114
  } else if (gtagId) {
@@ -1913,17 +2119,17 @@ function GoogleAdsTracking(props) {
1913
2119
  }
1914
2120
 
1915
2121
  // src/factory.tsx
1916
- var import_react5 = require("react");
2122
+ var import_react6 = require("react");
1917
2123
 
1918
2124
  // package.json
1919
- var version = "0.12.1";
2125
+ var version = "0.13.0";
1920
2126
 
1921
2127
  // ../tracking-core/src/phone-react.tsx
1922
- var import_react4 = require("react");
2128
+ var import_react5 = require("react");
1923
2129
  var import_jsx_runtime2 = require("react/jsx-runtime");
1924
2130
  var _phoneConfigContext;
1925
2131
  function phoneConfigContext() {
1926
- return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react4.createContext)(null));
2132
+ return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react5.createContext)(null));
1927
2133
  }
1928
2134
  function PhoneConfigProvider({
1929
2135
  value,
@@ -1933,7 +2139,7 @@ function PhoneConfigProvider({
1933
2139
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ctx.Provider, { value, children });
1934
2140
  }
1935
2141
  function usePhoneConfig() {
1936
- const ctx = (0, import_react4.useContext)(phoneConfigContext());
2142
+ const ctx = (0, import_react5.useContext)(phoneConfigContext());
1937
2143
  return {
1938
2144
  defaultCountry: ctx?.defaultCountry ?? DEFAULT_PHONE_COUNTRY,
1939
2145
  display: ctx?.display ?? "national"
@@ -1944,10 +2150,10 @@ function usePhoneField(opts = {}) {
1944
2150
  const country = opts.country ?? cfg.defaultCountry;
1945
2151
  const display = opts.display ?? cfg.display;
1946
2152
  const { onValueChange } = opts;
1947
- const [value, setValue] = (0, import_react4.useState)(() => formatPhoneAsTyped(opts.defaultValue ?? "", country));
1948
- const [touched, setTouched] = (0, import_react4.useState)(false);
1949
- const parsed = (0, import_react4.useMemo)(() => parsePhone(value, country), [value, country]);
1950
- const onChange = (0, import_react4.useCallback)(
2153
+ const [value, setValue] = (0, import_react5.useState)(() => formatPhoneAsTyped(opts.defaultValue ?? "", country));
2154
+ const [touched, setTouched] = (0, import_react5.useState)(false);
2155
+ const parsed = (0, import_react5.useMemo)(() => parsePhone(value, country), [value, country]);
2156
+ const onChange = (0, import_react5.useCallback)(
1951
2157
  (event) => {
1952
2158
  const next = formatPhoneAsTyped(event.target.value, country);
1953
2159
  setValue(next);
@@ -1955,7 +2161,7 @@ function usePhoneField(opts = {}) {
1955
2161
  },
1956
2162
  [country, onValueChange]
1957
2163
  );
1958
- const onBlur = (0, import_react4.useCallback)(
2164
+ const onBlur = (0, import_react5.useCallback)(
1959
2165
  (_event) => {
1960
2166
  setTouched(true);
1961
2167
  setValue((current) => {
@@ -1975,11 +2181,11 @@ function usePhoneField(opts = {}) {
1975
2181
  inputProps: { value, onChange, onBlur, type: "tel", inputMode: "tel", autoComplete: "tel" }
1976
2182
  };
1977
2183
  }
1978
- var PhoneField = (0, import_react4.forwardRef)(function PhoneField2({ country, value, defaultValue, onChange, onE164Change, ...rest }, ref) {
2184
+ var PhoneField = (0, import_react5.forwardRef)(function PhoneField2({ country, value, defaultValue, onChange, onE164Change, ...rest }, ref) {
1979
2185
  const cfg = usePhoneConfig();
1980
2186
  const resolvedCountry = country ?? cfg.defaultCountry;
1981
2187
  const isControlled = value !== void 0;
1982
- const [internal, setInternal] = (0, import_react4.useState)(
2188
+ const [internal, setInternal] = (0, import_react5.useState)(
1983
2189
  () => formatPhoneAsTyped(defaultValue ?? "", resolvedCountry)
1984
2190
  );
1985
2191
  const handleChange = (event) => {
@@ -2030,10 +2236,18 @@ function createTracking(options) {
2030
2236
  useTracking: () => noopTyped
2031
2237
  };
2032
2238
  }
2033
- const TrackingContext = (0, import_react5.createContext)(null);
2034
- function TrackingProvider({ gtagId, gtagIds, children }) {
2035
- const resolvedGtagIds = gtagIds ?? (gtagId ? { default: gtagId } : void 0);
2036
- const client = (0, import_react5.useMemo)(
2239
+ const TrackingContext = (0, import_react6.createContext)(null);
2240
+ function TrackingProvider({
2241
+ gtagId,
2242
+ gtagIds,
2243
+ metaPixelId,
2244
+ metaPixelIds,
2245
+ children
2246
+ }) {
2247
+ const resolvedGtagIds = gtagIds ? Object.fromEntries(
2248
+ Object.entries(gtagIds).filter((e) => e[1] != null)
2249
+ ) : gtagId ? { default: gtagId } : void 0;
2250
+ const client = (0, import_react6.useMemo)(
2037
2251
  () => createTypedClient(
2038
2252
  getOrCreateTrackingClient({
2039
2253
  apiKey,
@@ -2051,15 +2265,26 @@ function createTracking(options) {
2051
2265
  ),
2052
2266
  []
2053
2267
  );
2054
- const gtagIdsKey = (0, import_react5.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2055
- (0, import_react5.useEffect)(() => {
2268
+ const gtagIdsKey = (0, import_react6.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2269
+ (0, import_react6.useEffect)(() => {
2056
2270
  if (gtagIds && Object.keys(gtagIds).length > 0) {
2057
2271
  bootstrapMultipleGtags(gtagIds);
2058
2272
  } else if (gtagId) {
2059
2273
  bootstrapGoogleAdsTracking(gtagId);
2060
2274
  }
2061
2275
  }, [gtagId, gtagIdsKey]);
2062
- (0, import_react5.useEffect)(() => {
2276
+ const metaPixelIdsKey = (0, import_react6.useMemo)(
2277
+ () => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
2278
+ [metaPixelIds]
2279
+ );
2280
+ (0, import_react6.useEffect)(() => {
2281
+ if (metaPixelIds && Object.keys(metaPixelIds).length > 0) {
2282
+ bootstrapMultiplePixels(metaPixelIds);
2283
+ } else if (metaPixelId) {
2284
+ bootstrapMetaPixel(metaPixelId);
2285
+ }
2286
+ }, [metaPixelId, metaPixelIdsKey]);
2287
+ (0, import_react6.useEffect)(() => {
2063
2288
  const detachers = [];
2064
2289
  const rawClient = getOrCreateTrackingClient({
2065
2290
  apiKey,
@@ -2102,7 +2327,7 @@ function createTracking(options) {
2102
2327
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
2103
2328
  }
2104
2329
  function useTracking() {
2105
- const client = (0, import_react5.useContext)(TrackingContext);
2330
+ const client = (0, import_react6.useContext)(TrackingContext);
2106
2331
  if (client === null) {
2107
2332
  throw new Error(
2108
2333
  "useTracking must be called inside a <TrackingProvider> returned by createTracking()"
@@ -2114,6 +2339,7 @@ function createTracking(options) {
2114
2339
  }
2115
2340
  // Annotate the CommonJS export names for ESM import in node:
2116
2341
  0 && (module.exports = {
2342
+ AdPlatformTracking,
2117
2343
  AranovaApiError,
2118
2344
  ConsentBanner,
2119
2345
  DEFAULT_PHONE_COUNTRY,