@aranova/tracking-next 0.18.1 → 0.19.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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-CVCzW04Z.mjs';
2
- export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-CVCzW04Z.mjs';
3
- import { T as TrackingConfigReference, C as ConversionConfig } from './sales-QqKh6_iy.mjs';
4
- export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as CurrencyRevenue, f as CustomerCurrencyDelta, g as CustomerCurrencyTotal, h as CustomerGetOptions, i as CustomerGetResult, j as CustomerKpis, k as CustomerKpisDeltas, l as CustomerKpisPrevious, m as CustomerListPage, n as CustomerListQuery, o as CustomerProfile, p as CustomerSegment, q as CustomerSegmentCount, r as CustomerSortField, s as CustomerSummary, t as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, u as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, v as Sale, w as SaleCursorPage, x as SaleFilters, y as SaleInput, z as SaleItem, E as SaleItemInput, F as SaleKeysetSortField, H as SaleListPage, I as SaleListQuery, J as SaleListQueryV2, K as SaleService, L as SaleServiceInput, M as SaleSortField, O as SaleSortOrder, Q as SaleSummary, R as SaleSummaryPrevious, U as SaleSummaryQuery, V as SaleSummaryQueryV2, W as SaleSummaryV2, X as SaleUpdateInput, Y as SalesBusinessClient, Z as SalesCategoryBreakdown, _ as SalesClient, $ as SalesClientConfig, a0 as SalesCustomersClient, a1 as SalesServiceBreakdown, a2 as SalesTransportConfig, a3 as SalesTrendPoint, a4 as SummaryCurrencyDelta, a5 as SummaryDeltas, a6 as SummaryWindow, a7 as SupportedCurrency, a8 as TRACKING_RANGES, a9 as TrackingOverviewRange, aa as createSalesClient, ab as fetchServices, ac as formatDateInTz, ad as formatMoney, ae as fromMinor, af as getTrackingConfigRuntime, ag as resolveConversionConfig, ah as saleCreateSchema, ai as saleItemSchema, aj as saleServiceSchema, ak as saleUpdateSchema, al as salesRequest, am as toMinor } from './sales-QqKh6_iy.mjs';
1
+ import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-B2vHJkNz.mjs';
2
+ export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-B2vHJkNz.mjs';
3
+ import { T as TrackingConfigReference, C as ConversionConfig } from './sales--WzOzyiO.mjs';
4
+ export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales--WzOzyiO.mjs';
5
5
  import { z } from 'zod';
6
6
  import * as src from 'src';
7
7
  import * as react from 'react';
@@ -13,7 +13,7 @@ export { CountryCode } from 'libphonenumber-js';
13
13
  /**
14
14
  * Attribution query/cookie keys captured by the SDK.
15
15
  */
16
- declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
16
+ declare const TRACKING_PARAM_KEYS: readonly ["gclid", "wbraid", "gbraid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
17
17
  type TrackingParamKey = (typeof TRACKING_PARAM_KEYS)[number];
18
18
  /**
19
19
  * Capture tracking params from a URL, persist them to first-party cookies, and
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-CVCzW04Z.js';
2
- export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-CVCzW04Z.js';
3
- import { T as TrackingConfigReference, C as ConversionConfig } from './sales-QqKh6_iy.js';
4
- export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as CurrencyRevenue, f as CustomerCurrencyDelta, g as CustomerCurrencyTotal, h as CustomerGetOptions, i as CustomerGetResult, j as CustomerKpis, k as CustomerKpisDeltas, l as CustomerKpisPrevious, m as CustomerListPage, n as CustomerListQuery, o as CustomerProfile, p as CustomerSegment, q as CustomerSegmentCount, r as CustomerSortField, s as CustomerSummary, t as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, u as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, v as Sale, w as SaleCursorPage, x as SaleFilters, y as SaleInput, z as SaleItem, E as SaleItemInput, F as SaleKeysetSortField, H as SaleListPage, I as SaleListQuery, J as SaleListQueryV2, K as SaleService, L as SaleServiceInput, M as SaleSortField, O as SaleSortOrder, Q as SaleSummary, R as SaleSummaryPrevious, U as SaleSummaryQuery, V as SaleSummaryQueryV2, W as SaleSummaryV2, X as SaleUpdateInput, Y as SalesBusinessClient, Z as SalesCategoryBreakdown, _ as SalesClient, $ as SalesClientConfig, a0 as SalesCustomersClient, a1 as SalesServiceBreakdown, a2 as SalesTransportConfig, a3 as SalesTrendPoint, a4 as SummaryCurrencyDelta, a5 as SummaryDeltas, a6 as SummaryWindow, a7 as SupportedCurrency, a8 as TRACKING_RANGES, a9 as TrackingOverviewRange, aa as createSalesClient, ab as fetchServices, ac as formatDateInTz, ad as formatMoney, ae as fromMinor, af as getTrackingConfigRuntime, ag as resolveConversionConfig, ah as saleCreateSchema, ai as saleItemSchema, aj as saleServiceSchema, ak as saleUpdateSchema, al as salesRequest, am as toMinor } from './sales-QqKh6_iy.js';
1
+ import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-B2vHJkNz.js';
2
+ export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-B2vHJkNz.js';
3
+ import { T as TrackingConfigReference, C as ConversionConfig } from './sales--WzOzyiO.js';
4
+ export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as ConversionUserData, f as CurrencyRevenue, g as CustomerCurrencyDelta, h as CustomerCurrencyTotal, i as CustomerGetOptions, j as CustomerGetResult, k as CustomerKpis, l as CustomerKpisDeltas, m as CustomerKpisPrevious, n as CustomerListPage, o as CustomerListQuery, p as CustomerProfile, q as CustomerSegment, r as CustomerSegmentCount, s as CustomerSortField, t as CustomerSummary, u as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, v as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, w as Sale, x as SaleCursorPage, y as SaleFilters, z as SaleInput, E as SaleItem, F as SaleItemInput, H as SaleKeysetSortField, I as SaleListPage, J as SaleListQuery, K as SaleListQueryV2, L as SaleService, M as SaleServiceInput, O as SaleSortField, Q as SaleSortOrder, R as SaleSummary, U as SaleSummaryPrevious, V as SaleSummaryQuery, W as SaleSummaryQueryV2, X as SaleSummaryV2, Y as SaleUpdateInput, Z as SalesBusinessClient, _ as SalesCategoryBreakdown, $ as SalesClient, a0 as SalesClientConfig, a1 as SalesCustomersClient, a2 as SalesServiceBreakdown, a3 as SalesTransportConfig, a4 as SalesTrendPoint, a5 as SummaryCurrencyDelta, a6 as SummaryDeltas, a7 as SummaryWindow, a8 as SupportedCurrency, a9 as TRACKING_RANGES, aa as TrackingOverviewRange, ab as clearStashedUserData, ac as createSalesClient, ad as fetchServices, ae as formatDateInTz, af as formatMoney, ag as fromMinor, ah as getTrackingConfigRuntime, ai as resolveConversionConfig, aj as saleCreateSchema, ak as saleItemSchema, al as saleServiceSchema, am as saleUpdateSchema, an as salesRequest, ao as stashUserData, ap as toMinor } from './sales--WzOzyiO.js';
5
5
  import { z } from 'zod';
6
6
  import * as src from 'src';
7
7
  import * as react from 'react';
@@ -13,7 +13,7 @@ export { CountryCode } from 'libphonenumber-js';
13
13
  /**
14
14
  * Attribution query/cookie keys captured by the SDK.
15
15
  */
16
- declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
16
+ declare const TRACKING_PARAM_KEYS: readonly ["gclid", "wbraid", "gbraid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
17
17
  type TrackingParamKey = (typeof TRACKING_PARAM_KEYS)[number];
18
18
  /**
19
19
  * Capture tracking params from a URL, persist them to first-party cookies, and
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  TRACKING_PARAM_KEYS: () => TRACKING_PARAM_KEYS,
44
44
  TRACKING_RANGES: () => TRACKING_RANGES,
45
45
  captureTrackingParamsFromLocation: () => captureTrackingParamsFromLocation,
46
+ clearStashedUserData: () => clearStashedUserData,
46
47
  createSalesClient: () => createSalesClient,
47
48
  createTracking: () => createTracking,
48
49
  createTrackingClientContext: () => createTrackingClientContext,
@@ -71,6 +72,7 @@ __export(src_exports, {
71
72
  saleUpdateSchema: () => saleUpdateSchema,
72
73
  salesRequest: () => salesRequest,
73
74
  setConsentState: () => setConsentState,
75
+ stashUserData: () => stashUserData,
74
76
  toE164: () => toE164,
75
77
  toMinor: () => toMinor,
76
78
  useConsent: () => useConsent,
@@ -83,6 +85,140 @@ __export(src_exports, {
83
85
  });
84
86
  module.exports = __toCommonJS(src_exports);
85
87
 
88
+ // ../tracking-core/src/phone.ts
89
+ var import_libphonenumber_js = require("libphonenumber-js");
90
+ var DEFAULT_PHONE_COUNTRY = "CA";
91
+ function parsePhone(raw, country) {
92
+ const region = country ?? DEFAULT_PHONE_COUNTRY;
93
+ const parsed = (0, import_libphonenumber_js.parsePhoneNumberFromString)(raw ?? "", region);
94
+ if (!parsed) {
95
+ return { e164: null, national: "", international: "", country: region, isValid: false };
96
+ }
97
+ const isValid = parsed.isValid();
98
+ return {
99
+ // E.164 is only surfaced for a *valid* number — a possible-but-invalid input
100
+ // (e.g. too few digits) still parses but must not be transmitted.
101
+ e164: isValid ? parsed.number : null,
102
+ national: parsed.formatNational(),
103
+ international: parsed.formatInternational(),
104
+ country: parsed.country ?? region,
105
+ isValid
106
+ };
107
+ }
108
+ function toE164(raw, country) {
109
+ return parsePhone(raw, country).e164;
110
+ }
111
+ function formatPhone(value, format = "national", country) {
112
+ const parsed = parsePhone(value, country);
113
+ if (typeof format === "function") return format(parsed);
114
+ switch (format) {
115
+ case "international":
116
+ return parsed.international || value;
117
+ case "e164":
118
+ return parsed.e164 ?? value;
119
+ case "national":
120
+ default:
121
+ return parsed.national || value;
122
+ }
123
+ }
124
+ function formatPhoneAsTyped(raw, country) {
125
+ return new import_libphonenumber_js.AsYouType(country ?? DEFAULT_PHONE_COUNTRY).input(raw ?? "");
126
+ }
127
+
128
+ // ../tracking-core/src/user-data.ts
129
+ var EMAIL_SHAPE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
130
+ var EMAIL_NAME_HINT = /e[-_]?mail/i;
131
+ var PHONE_NAME_HINT = /(^|[^a-z])(phone|tel|mobile|cell)/i;
132
+ var stash = { email: null, phoneNumber: null };
133
+ function normalizeEmail(raw) {
134
+ if (typeof raw !== "string") return null;
135
+ const cleaned = raw.trim().toLowerCase();
136
+ return EMAIL_SHAPE.test(cleaned) ? cleaned : null;
137
+ }
138
+ function fieldText(field, key) {
139
+ const value = field[key];
140
+ return typeof value === "string" ? value : "";
141
+ }
142
+ function extractUserDataFromFormFields(fields, country) {
143
+ const result = { email: null, phoneNumber: null };
144
+ if (!Array.isArray(fields)) return result;
145
+ const passes = [
146
+ (field, _hint, type) => fieldText(field, "type").toLowerCase() === type,
147
+ (field, hint) => hint.test(fieldText(field, "name")) || hint.test(fieldText(field, "label"))
148
+ ];
149
+ for (const matches of passes) {
150
+ for (const raw of fields) {
151
+ if (raw === null || typeof raw !== "object") continue;
152
+ const field = raw;
153
+ if (typeof field.value !== "string" || field.value.length === 0) continue;
154
+ if (result.email === null && matches(field, EMAIL_NAME_HINT, "email")) {
155
+ result.email = normalizeEmail(field.value);
156
+ }
157
+ if (result.phoneNumber === null && matches(field, PHONE_NAME_HINT, "tel")) {
158
+ try {
159
+ result.phoneNumber = toE164(field.value, country);
160
+ } catch {
161
+ }
162
+ }
163
+ }
164
+ if (result.email !== null && result.phoneNumber !== null) break;
165
+ }
166
+ return result;
167
+ }
168
+ function stashUserData(data, country) {
169
+ const email = normalizeEmail(data.email);
170
+ let phoneNumber = null;
171
+ if (typeof data.phone === "string" && data.phone.length > 0) {
172
+ try {
173
+ phoneNumber = toE164(data.phone, country);
174
+ } catch {
175
+ phoneNumber = null;
176
+ }
177
+ }
178
+ stash = {
179
+ email: email ?? stash.email,
180
+ phoneNumber: phoneNumber ?? stash.phoneNumber
181
+ };
182
+ }
183
+ function stashUserDataFromFormFields(fields, country) {
184
+ try {
185
+ const extracted = extractUserDataFromFormFields(fields, country);
186
+ stash = {
187
+ email: extracted.email ?? stash.email,
188
+ phoneNumber: extracted.phoneNumber ?? stash.phoneNumber
189
+ };
190
+ } catch {
191
+ }
192
+ }
193
+ function clearStashedUserData() {
194
+ stash = { email: null, phoneNumber: null };
195
+ }
196
+ function applyUserDataForConversion(explicit, country) {
197
+ if (typeof window === "undefined" || typeof window.gtag !== "function") return false;
198
+ let email = stash.email;
199
+ let phoneNumber = stash.phoneNumber;
200
+ if (explicit) {
201
+ const normalizedEmail = normalizeEmail(explicit.email);
202
+ if (normalizedEmail) email = normalizedEmail;
203
+ if (typeof explicit.phone === "string" && explicit.phone.length > 0) {
204
+ try {
205
+ phoneNumber = toE164(explicit.phone, country) ?? phoneNumber;
206
+ } catch {
207
+ }
208
+ }
209
+ }
210
+ if (email === null && phoneNumber === null) return false;
211
+ try {
212
+ window.gtag("set", "user_data", {
213
+ ...email !== null ? { email } : {},
214
+ ...phoneNumber !== null ? { phone_number: phoneNumber } : {}
215
+ });
216
+ return true;
217
+ } catch {
218
+ return false;
219
+ }
220
+ }
221
+
86
222
  // ../tracking-core/src/consent.ts
87
223
  var CONSENT_STATE_KEY = "consent_state";
88
224
  var CONSENT_TIMESTAMP_KEY = "consent_timestamp";
@@ -168,6 +304,13 @@ function setConsentState(state, options) {
168
304
  } catch {
169
305
  }
170
306
  pushConsentToPlatforms(state);
307
+ if (state === "denied") {
308
+ clearStashedUserData();
309
+ try {
310
+ if (typeof window.gtag === "function") window.gtag("set", "user_data", null);
311
+ } catch {
312
+ }
313
+ }
171
314
  notifyConsentChanged({ state, source: "explicit", updatedAt, expiresAt });
172
315
  }
173
316
  function optIn() {
@@ -206,6 +349,11 @@ var aranovaConsent = (function () {
206
349
  var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
207
350
  var TRACKING_PARAM_KEYS = [
208
351
  "gclid",
352
+ // Google's iOS/Safari replacement click IDs — issued when privacy features
353
+ // withhold gclid (wbraid: web-to-web, gbraid: app-to-web). First-class
354
+ // citizens: captured, persisted, and attributed exactly like gclid.
355
+ "wbraid",
356
+ "gbraid",
209
357
  "fbclid",
210
358
  "utm_source",
211
359
  "utm_medium",
@@ -216,6 +364,8 @@ var TRACKING_PARAM_KEYS = [
216
364
  function createEmptyTrackingParams() {
217
365
  return {
218
366
  gclid: null,
367
+ wbraid: null,
368
+ gbraid: null,
219
369
  fbclid: null,
220
370
  utm_source: null,
221
371
  utm_medium: null,
@@ -518,6 +668,8 @@ function buildLandingPayloadFields(sessionId, override) {
518
668
  if (params === null) return {};
519
669
  return {
520
670
  landing_gclid: params.gclid ?? null,
671
+ landing_wbraid: params.wbraid ?? null,
672
+ landing_gbraid: params.gbraid ?? null,
521
673
  landing_fbclid: params.fbclid ?? null,
522
674
  landing_utm_source: params.utm_source ?? null,
523
675
  landing_utm_medium: params.utm_medium ?? null,
@@ -545,6 +697,8 @@ function createTrackingSessionUpsertPayload(trackingParams, input, context) {
545
697
  session_id: input.sessionId,
546
698
  visitor_id: input.visitorId ?? null,
547
699
  gclid: trackingParams.gclid,
700
+ wbraid: trackingParams.wbraid,
701
+ gbraid: trackingParams.gbraid,
548
702
  fbclid: trackingParams.fbclid,
549
703
  fbc: getFbcCookie(),
550
704
  fbp: getFbpCookie(),
@@ -566,6 +720,8 @@ function createTrackingEventCreatePayload(trackingParams, input, context) {
566
720
  session_id: input.sessionId,
567
721
  event_type: input.eventType,
568
722
  gclid: trackingParams.gclid,
723
+ wbraid: trackingParams.wbraid,
724
+ gbraid: trackingParams.gbraid,
569
725
  fbclid: trackingParams.fbclid,
570
726
  fbc: getFbcCookie(),
571
727
  fbp: getFbpCookie(),
@@ -595,14 +751,12 @@ function markFired(input) {
595
751
  } catch {
596
752
  }
597
753
  }
598
- function fireOnce(input) {
754
+ function fireConversionWithConsent(input, options) {
755
+ if (getConsentState() === "denied") return;
599
756
  if (alreadyFired(input)) return;
757
+ applyUserDataForConversion(options?.userData);
600
758
  if (fireGtagConversion(input)) markFired(input);
601
759
  }
602
- function fireConversionWithConsent(input) {
603
- if (getConsentState() === "denied") return;
604
- fireOnce(input);
605
- }
606
760
 
607
761
  // ../tracking-core/src/resources/conversion-config.ts
608
762
  function isStringMap(value) {
@@ -1047,6 +1201,7 @@ var TrackingConfigRuntime = class {
1047
1201
  if (!firing || getConsentState() === "denied") continue;
1048
1202
  const currency = item.currency ?? firing.currency ?? null;
1049
1203
  const value = item.value ?? (firing.value_cents != null && currency ? fromMinor(firing.value_cents, currency) : null);
1204
+ applyUserDataForConversion();
1050
1205
  fireGtagConversion({
1051
1206
  sendTo: firing.send_to,
1052
1207
  value,
@@ -1540,6 +1695,8 @@ function createTrackingClient(config) {
1540
1695
  session_id: sessionId,
1541
1696
  visitor_id: visitorId,
1542
1697
  gclid: params.gclid,
1698
+ wbraid: params.wbraid,
1699
+ gbraid: params.gbraid,
1543
1700
  fbclid: params.fbclid,
1544
1701
  fbc: getFbcCookie(),
1545
1702
  fbp: getFbpCookie(),
@@ -1586,6 +1743,13 @@ function createTrackingClient(config) {
1586
1743
  function trackEvent(input) {
1587
1744
  if (destroyed) return;
1588
1745
  if (!input || typeof input.eventType !== "string" || input.eventType.length === 0) return;
1746
+ if (input.eventType === "form_submit" && getConsentState() !== "denied") {
1747
+ try {
1748
+ const fields = input.metadata?.form?.fields;
1749
+ if (fields) stashUserDataFromFormFields(fields, config.phone?.defaultCountry);
1750
+ } catch {
1751
+ }
1752
+ }
1589
1753
  const occurredAt = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : typeof input.occurredAt === "string" ? input.occurredAt : (/* @__PURE__ */ new Date()).toISOString();
1590
1754
  queue.push({
1591
1755
  event_type: input.eventType,
@@ -2414,46 +2578,6 @@ function attachCtaClickCapture(client, config) {
2414
2578
  };
2415
2579
  }
2416
2580
 
2417
- // ../tracking-core/src/phone.ts
2418
- var import_libphonenumber_js = require("libphonenumber-js");
2419
- var DEFAULT_PHONE_COUNTRY = "CA";
2420
- function parsePhone(raw, country) {
2421
- const region = country ?? DEFAULT_PHONE_COUNTRY;
2422
- const parsed = (0, import_libphonenumber_js.parsePhoneNumberFromString)(raw ?? "", region);
2423
- if (!parsed) {
2424
- return { e164: null, national: "", international: "", country: region, isValid: false };
2425
- }
2426
- const isValid = parsed.isValid();
2427
- return {
2428
- // E.164 is only surfaced for a *valid* number — a possible-but-invalid input
2429
- // (e.g. too few digits) still parses but must not be transmitted.
2430
- e164: isValid ? parsed.number : null,
2431
- national: parsed.formatNational(),
2432
- international: parsed.formatInternational(),
2433
- country: parsed.country ?? region,
2434
- isValid
2435
- };
2436
- }
2437
- function toE164(raw, country) {
2438
- return parsePhone(raw, country).e164;
2439
- }
2440
- function formatPhone(value, format = "national", country) {
2441
- const parsed = parsePhone(value, country);
2442
- if (typeof format === "function") return format(parsed);
2443
- switch (format) {
2444
- case "international":
2445
- return parsed.international || value;
2446
- case "e164":
2447
- return parsed.e164 ?? value;
2448
- case "national":
2449
- default:
2450
- return parsed.national || value;
2451
- }
2452
- }
2453
- function formatPhoneAsTyped(raw, country) {
2454
- return new import_libphonenumber_js.AsYouType(country ?? DEFAULT_PHONE_COUNTRY).input(raw ?? "");
2455
- }
2456
-
2457
2581
  // ../tracking-core/src/triggers/phone-click-capture.ts
2458
2582
  var DEFAULT_TEL_SELECTOR = 'a[href^="tel:"]';
2459
2583
  function safeDecodeURIComponent(value) {
@@ -2563,6 +2687,8 @@ async function salesRequest(config, method, path, body) {
2563
2687
  // ../tracking-core/src/resources/sales/client.ts
2564
2688
  function fireRecordedConversions(firing, input, recorded, sale, currency) {
2565
2689
  if (!firing) return;
2690
+ const userData = input.customer_email || input.customer_phone ? { email: input.customer_email ?? null, phone: input.customer_phone ?? null } : null;
2691
+ if (userData && getConsentState() !== "denied") stashUserData(userData);
2566
2692
  const txnBase = input.external_id ?? sale.id;
2567
2693
  for (const item of recorded) {
2568
2694
  if (!item.service) continue;
@@ -2577,12 +2703,15 @@ function fireRecordedConversions(firing, input, recorded, sale, currency) {
2577
2703
  const config = firing.getFiring(item.service);
2578
2704
  if (!config) continue;
2579
2705
  const cents = item.amount_cents ?? config.value_cents ?? null;
2580
- fireConversionWithConsent({
2581
- sendTo: config.send_to,
2582
- value: cents != null ? fromMinor(cents, currency) : null,
2583
- currency: config.currency ?? currency,
2584
- transactionId: `${txnBase}:${item.service}`
2585
- });
2706
+ fireConversionWithConsent(
2707
+ {
2708
+ sendTo: config.send_to,
2709
+ value: cents != null ? fromMinor(cents, currency) : null,
2710
+ currency: config.currency ?? currency,
2711
+ transactionId: `${txnBase}:${item.service}`
2712
+ },
2713
+ { userData }
2714
+ );
2586
2715
  }
2587
2716
  }
2588
2717
  function createSalesClient(config) {
@@ -2617,6 +2746,7 @@ function createSalesClient(config) {
2617
2746
  recordSale: record,
2618
2747
  trackConversion(key, options) {
2619
2748
  if (config.firing && "fireConversion" in config.firing) {
2749
+ if (options?.userData && getConsentState() !== "denied") stashUserData(options.userData);
2620
2750
  config.firing.fireConversion(key, {
2621
2751
  value: options?.value ?? void 0,
2622
2752
  currency: options?.currency ?? config.defaultCurrency ?? void 0,
@@ -2629,12 +2759,15 @@ function createSalesClient(config) {
2629
2759
  const currency = firing.currency ?? options?.currency ?? config.defaultCurrency ?? null;
2630
2760
  const cents = firing.value_cents ?? null;
2631
2761
  const value = options?.value ?? (cents != null && currency ? fromMinor(cents, currency) : null);
2632
- fireConversionWithConsent({
2633
- sendTo: firing.send_to,
2634
- value,
2635
- currency,
2636
- transactionId: options?.transactionId ?? null
2637
- });
2762
+ fireConversionWithConsent(
2763
+ {
2764
+ sendTo: firing.send_to,
2765
+ value,
2766
+ currency,
2767
+ transactionId: options?.transactionId ?? null
2768
+ },
2769
+ { userData: options?.userData }
2770
+ );
2638
2771
  },
2639
2772
  async list(query) {
2640
2773
  const { cursor, limit, sort, order, want_total, ...filters } = query ?? {};
@@ -3196,7 +3329,7 @@ function GoogleAdsTracking(props) {
3196
3329
  var import_navigation3 = require("next/navigation");
3197
3330
 
3198
3331
  // package.json
3199
- var version = "0.18.1";
3332
+ var version = "0.19.0";
3200
3333
 
3201
3334
  // src/factory.tsx
3202
3335
  var import_react5 = require("react");
@@ -3528,6 +3661,7 @@ function createTracking(options) {
3528
3661
  TRACKING_PARAM_KEYS,
3529
3662
  TRACKING_RANGES,
3530
3663
  captureTrackingParamsFromLocation,
3664
+ clearStashedUserData,
3531
3665
  createSalesClient,
3532
3666
  createTracking,
3533
3667
  createTrackingClientContext,
@@ -3556,6 +3690,7 @@ function createTracking(options) {
3556
3690
  saleUpdateSchema,
3557
3691
  salesRequest,
3558
3692
  setConsentState,
3693
+ stashUserData,
3559
3694
  toE164,
3560
3695
  toMinor,
3561
3696
  useConsent,