@aranova/tracking-react 0.12.2 → 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
@@ -214,70 +287,158 @@ function bootstrapMultipleGtags(gtagIds) {
214
287
  restoreStoredConsent();
215
288
  }
216
289
 
217
- // ../tracking-core/src/tracking.ts
218
- var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
219
- var TRACKING_PARAM_KEYS = [
220
- "gclid",
221
- "fbclid",
222
- "utm_source",
223
- "utm_medium",
224
- "utm_campaign",
225
- "utm_term",
226
- "utm_content"
227
- ];
228
- function createEmptyTrackingParams() {
229
- return {
230
- gclid: null,
231
- fbclid: null,
232
- utm_source: null,
233
- utm_medium: null,
234
- utm_campaign: null,
235
- utm_term: null,
236
- utm_content: null
237
- };
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
+ }
238
320
  }
239
- function normalizeTrackingCookieValue(value) {
240
- 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);
241
327
  }
242
- function getTrackingParamsFromCookieReader(readCookie) {
243
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
244
- params[key] = normalizeTrackingCookieValue(readCookie(key));
245
- return params;
246
- }, createEmptyTrackingParams());
328
+ function getScriptMarker2(id) {
329
+ return `aranova-${id}`;
247
330
  }
248
- function getTrackingQueryValues(searchParams) {
249
- return TRACKING_PARAM_KEYS.reduce((params, key) => {
250
- const value = searchParams.get(key);
251
- if (typeof value === "string" && value.trim().length > 0) {
252
- params[key] = value;
253
- }
254
- return params;
255
- }, {});
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);
256
361
  }
257
- function getCookieValueFromDocument(key) {
258
- if (typeof document === "undefined") return null;
259
- const cookies = document.cookie ? document.cookie.split("; ") : [];
260
- const match = cookies.find((cookie) => cookie.startsWith(`${key}=`));
261
- if (!match) return null;
262
- const [, rawValue = ""] = match.split("=");
263
- return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
362
+ function initializeMetaPixel(pixelId) {
363
+ const fbq = ensureFbqFunction();
364
+ fbq("init", pixelId);
365
+ fbq("track", "PageView");
264
366
  }
265
- function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
266
- if (typeof document === "undefined") return;
267
- const encodedValue = encodeURIComponent(value);
268
- 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");
269
372
  }
270
- function persistTrackingParamsFromSearchParams(searchParams, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
271
- const trackingValues = getTrackingQueryValues(searchParams);
272
- Object.entries(trackingValues).forEach(([key, value]) => {
273
- setTrackingCookie(key, value, maxAgeSeconds);
274
- });
275
- 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();
276
397
  }
277
- function captureTrackingParamsFromLocation(url = typeof window === "undefined" ? "" : window.location.href, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
278
- const resolvedUrl = typeof window === "undefined" ? new URL(url || "https://example.invalid") : new URL(url, window.location.origin);
279
- persistTrackingParamsFromSearchParams(resolvedUrl.searchParams, maxAgeSeconds);
280
- 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
+ };
281
442
  }
282
443
 
283
444
  // ../tracking-core/src/session.ts
@@ -608,11 +769,22 @@ function createTrackingClient(config) {
608
769
  let queue = [];
609
770
  let flushTimer = null;
610
771
  let firstPage = null;
772
+ let initialParams = createEmptyTrackingParams();
611
773
  let destroyed = false;
612
774
  const visitorId = getVisitorId();
613
775
  const initialSession = getOrRotateSessionId();
614
776
  let sessionId = initialSession.id;
615
- 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
+ }
616
788
  function enqueueHeartbeat() {
617
789
  const metadata = buildHeartbeatMetadata(
618
790
  config.surface,
@@ -637,7 +809,7 @@ function createTrackingClient(config) {
637
809
  enqueueHeartbeat();
638
810
  }
639
811
  sessionId = rotated.id;
640
- const params = readTrackingParams();
812
+ const params = mergeTrackingParams(readTrackingParams(), initialParams);
641
813
  const context = buildContext(
642
814
  config.surface,
643
815
  sdkVersion,
@@ -650,6 +822,8 @@ function createTrackingClient(config) {
650
822
  visitor_id: visitorId,
651
823
  gclid: params.gclid,
652
824
  fbclid: params.fbclid,
825
+ fbc: getFbcCookie(),
826
+ fbp: getFbpCookie(),
653
827
  utm_source: params.utm_source,
654
828
  utm_medium: params.utm_medium,
655
829
  utm_campaign: params.utm_campaign,
@@ -1899,12 +2073,42 @@ var ANIMATION_KEYFRAMES = `
1899
2073
  }
1900
2074
  `;
1901
2075
 
1902
- // src/GoogleAdsTracking.tsx
2076
+ // src/AdPlatformTracking.tsx
1903
2077
  var import_react3 = require("react");
1904
- function GoogleAdsTracking(props) {
1905
- const { gtagId, gtagIds } = props;
2078
+ function AdPlatformTracking({
2079
+ gtagId,
2080
+ gtagIds,
2081
+ metaPixelId,
2082
+ metaPixelIds
2083
+ }) {
1906
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]);
1907
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)(() => {
1908
2112
  if (gtagIds && Object.keys(gtagIds).length > 0) {
1909
2113
  bootstrapMultipleGtags(gtagIds);
1910
2114
  } else if (gtagId) {
@@ -1915,17 +2119,17 @@ function GoogleAdsTracking(props) {
1915
2119
  }
1916
2120
 
1917
2121
  // src/factory.tsx
1918
- var import_react5 = require("react");
2122
+ var import_react6 = require("react");
1919
2123
 
1920
2124
  // package.json
1921
- var version = "0.12.2";
2125
+ var version = "0.13.0";
1922
2126
 
1923
2127
  // ../tracking-core/src/phone-react.tsx
1924
- var import_react4 = require("react");
2128
+ var import_react5 = require("react");
1925
2129
  var import_jsx_runtime2 = require("react/jsx-runtime");
1926
2130
  var _phoneConfigContext;
1927
2131
  function phoneConfigContext() {
1928
- return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react4.createContext)(null));
2132
+ return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react5.createContext)(null));
1929
2133
  }
1930
2134
  function PhoneConfigProvider({
1931
2135
  value,
@@ -1935,7 +2139,7 @@ function PhoneConfigProvider({
1935
2139
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ctx.Provider, { value, children });
1936
2140
  }
1937
2141
  function usePhoneConfig() {
1938
- const ctx = (0, import_react4.useContext)(phoneConfigContext());
2142
+ const ctx = (0, import_react5.useContext)(phoneConfigContext());
1939
2143
  return {
1940
2144
  defaultCountry: ctx?.defaultCountry ?? DEFAULT_PHONE_COUNTRY,
1941
2145
  display: ctx?.display ?? "national"
@@ -1946,10 +2150,10 @@ function usePhoneField(opts = {}) {
1946
2150
  const country = opts.country ?? cfg.defaultCountry;
1947
2151
  const display = opts.display ?? cfg.display;
1948
2152
  const { onValueChange } = opts;
1949
- const [value, setValue] = (0, import_react4.useState)(() => formatPhoneAsTyped(opts.defaultValue ?? "", country));
1950
- const [touched, setTouched] = (0, import_react4.useState)(false);
1951
- const parsed = (0, import_react4.useMemo)(() => parsePhone(value, country), [value, country]);
1952
- 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)(
1953
2157
  (event) => {
1954
2158
  const next = formatPhoneAsTyped(event.target.value, country);
1955
2159
  setValue(next);
@@ -1957,7 +2161,7 @@ function usePhoneField(opts = {}) {
1957
2161
  },
1958
2162
  [country, onValueChange]
1959
2163
  );
1960
- const onBlur = (0, import_react4.useCallback)(
2164
+ const onBlur = (0, import_react5.useCallback)(
1961
2165
  (_event) => {
1962
2166
  setTouched(true);
1963
2167
  setValue((current) => {
@@ -1977,11 +2181,11 @@ function usePhoneField(opts = {}) {
1977
2181
  inputProps: { value, onChange, onBlur, type: "tel", inputMode: "tel", autoComplete: "tel" }
1978
2182
  };
1979
2183
  }
1980
- 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) {
1981
2185
  const cfg = usePhoneConfig();
1982
2186
  const resolvedCountry = country ?? cfg.defaultCountry;
1983
2187
  const isControlled = value !== void 0;
1984
- const [internal, setInternal] = (0, import_react4.useState)(
2188
+ const [internal, setInternal] = (0, import_react5.useState)(
1985
2189
  () => formatPhoneAsTyped(defaultValue ?? "", resolvedCountry)
1986
2190
  );
1987
2191
  const handleChange = (event) => {
@@ -2032,12 +2236,18 @@ function createTracking(options) {
2032
2236
  useTracking: () => noopTyped
2033
2237
  };
2034
2238
  }
2035
- const TrackingContext = (0, import_react5.createContext)(null);
2036
- function TrackingProvider({ gtagId, gtagIds, children }) {
2239
+ const TrackingContext = (0, import_react6.createContext)(null);
2240
+ function TrackingProvider({
2241
+ gtagId,
2242
+ gtagIds,
2243
+ metaPixelId,
2244
+ metaPixelIds,
2245
+ children
2246
+ }) {
2037
2247
  const resolvedGtagIds = gtagIds ? Object.fromEntries(
2038
2248
  Object.entries(gtagIds).filter((e) => e[1] != null)
2039
2249
  ) : gtagId ? { default: gtagId } : void 0;
2040
- const client = (0, import_react5.useMemo)(
2250
+ const client = (0, import_react6.useMemo)(
2041
2251
  () => createTypedClient(
2042
2252
  getOrCreateTrackingClient({
2043
2253
  apiKey,
@@ -2055,15 +2265,26 @@ function createTracking(options) {
2055
2265
  ),
2056
2266
  []
2057
2267
  );
2058
- const gtagIdsKey = (0, import_react5.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2059
- (0, import_react5.useEffect)(() => {
2268
+ const gtagIdsKey = (0, import_react6.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
2269
+ (0, import_react6.useEffect)(() => {
2060
2270
  if (gtagIds && Object.keys(gtagIds).length > 0) {
2061
2271
  bootstrapMultipleGtags(gtagIds);
2062
2272
  } else if (gtagId) {
2063
2273
  bootstrapGoogleAdsTracking(gtagId);
2064
2274
  }
2065
2275
  }, [gtagId, gtagIdsKey]);
2066
- (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)(() => {
2067
2288
  const detachers = [];
2068
2289
  const rawClient = getOrCreateTrackingClient({
2069
2290
  apiKey,
@@ -2106,7 +2327,7 @@ function createTracking(options) {
2106
2327
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
2107
2328
  }
2108
2329
  function useTracking() {
2109
- const client = (0, import_react5.useContext)(TrackingContext);
2330
+ const client = (0, import_react6.useContext)(TrackingContext);
2110
2331
  if (client === null) {
2111
2332
  throw new Error(
2112
2333
  "useTracking must be called inside a <TrackingProvider> returned by createTracking()"
@@ -2118,6 +2339,7 @@ function createTracking(options) {
2118
2339
  }
2119
2340
  // Annotate the CommonJS export names for ESM import in node:
2120
2341
  0 && (module.exports = {
2342
+ AdPlatformTracking,
2121
2343
  AranovaApiError,
2122
2344
  ConsentBanner,
2123
2345
  DEFAULT_PHONE_COUNTRY,