@aranova/tracking-react 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -48
- package/dist/index.d.mts +61 -802
- package/dist/index.d.ts +61 -802
- package/dist/index.js +196 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +189 -86
- package/dist/index.mjs.map +1 -1
- package/dist/{phone-utils-CVX7JmqB.d.mts → phone-utils-Du-alwyM.d.mts} +14 -9
- package/dist/{phone-utils-CVX7JmqB.d.ts → phone-utils-Du-alwyM.d.ts} +14 -9
- package/dist/phone.d.mts +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/phone.js +98 -0
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs +98 -0
- package/dist/phone.mjs.map +1 -1
- package/dist/sales.d.mts +784 -0
- package/dist/sales.d.ts +784 -0
- package/dist/sales.js +400 -0
- package/dist/sales.js.map +1 -0
- package/dist/sales.mjs +359 -0
- package/dist/sales.mjs.map +1 -0
- package/package.json +30 -7
package/dist/index.js
CHANGED
|
@@ -24,9 +24,11 @@ __export(src_exports, {
|
|
|
24
24
|
ConsentBanner: () => ConsentBanner,
|
|
25
25
|
DEFAULT_PHONE_COUNTRY: () => DEFAULT_PHONE_COUNTRY,
|
|
26
26
|
GoogleAdsTracking: () => GoogleAdsTracking,
|
|
27
|
-
|
|
27
|
+
NAMED_RANGES: () => NAMED_RANGES,
|
|
28
28
|
PhoneField: () => PhoneField,
|
|
29
|
+
SUPPORTED_CURRENCIES: () => SUPPORTED_CURRENCIES,
|
|
29
30
|
TRACKING_PARAM_KEYS: () => TRACKING_PARAM_KEYS,
|
|
31
|
+
TRACKING_RANGES: () => TRACKING_RANGES,
|
|
30
32
|
captureTrackingParamsFromLocation: () => captureTrackingParamsFromLocation,
|
|
31
33
|
createSalesClient: () => createSalesClient,
|
|
32
34
|
createTracking: () => createTracking,
|
|
@@ -43,6 +45,11 @@ __export(src_exports, {
|
|
|
43
45
|
parsePhone: () => parsePhone,
|
|
44
46
|
phoneField: () => phoneField,
|
|
45
47
|
resetConsent: () => resetConsent,
|
|
48
|
+
saleCreateSchema: () => saleCreateSchema,
|
|
49
|
+
saleItemSchema: () => saleItemSchema,
|
|
50
|
+
saleServiceSchema: () => saleServiceSchema,
|
|
51
|
+
saleUpdateSchema: () => saleUpdateSchema,
|
|
52
|
+
salesRequest: () => salesRequest,
|
|
46
53
|
setConsentState: () => setConsentState,
|
|
47
54
|
toE164: () => toE164,
|
|
48
55
|
toMinor: () => toMinor,
|
|
@@ -73,31 +80,26 @@ function buildConsentPayload(state) {
|
|
|
73
80
|
};
|
|
74
81
|
}
|
|
75
82
|
function getConsentState() {
|
|
76
|
-
if (typeof window === "undefined")
|
|
77
|
-
return "pending";
|
|
83
|
+
if (typeof window === "undefined") return "pending";
|
|
78
84
|
const storedState = window.localStorage.getItem(CONSENT_STATE_KEY);
|
|
79
|
-
if (storedState === "granted" || storedState === "denied")
|
|
80
|
-
return storedState;
|
|
85
|
+
if (storedState === "granted" || storedState === "denied") return storedState;
|
|
81
86
|
return "pending";
|
|
82
87
|
}
|
|
83
88
|
function setConsentState(state) {
|
|
84
|
-
if (typeof window === "undefined")
|
|
85
|
-
return;
|
|
89
|
+
if (typeof window === "undefined") return;
|
|
86
90
|
window.localStorage.setItem(CONSENT_STATE_KEY, state);
|
|
87
91
|
window.localStorage.setItem(CONSENT_TIMESTAMP_KEY, (/* @__PURE__ */ new Date()).toISOString());
|
|
88
92
|
if (typeof window.gtag === "function")
|
|
89
93
|
window.gtag("consent", "update", buildConsentPayload(state));
|
|
90
94
|
}
|
|
91
95
|
function resetConsent() {
|
|
92
|
-
if (typeof window === "undefined")
|
|
93
|
-
return;
|
|
96
|
+
if (typeof window === "undefined") return;
|
|
94
97
|
window.localStorage.removeItem(CONSENT_STATE_KEY);
|
|
95
98
|
window.localStorage.removeItem(CONSENT_TIMESTAMP_KEY);
|
|
96
99
|
}
|
|
97
100
|
function restoreStoredConsent() {
|
|
98
101
|
const consentState = getConsentState();
|
|
99
|
-
if (consentState === "granted" || consentState === "denied")
|
|
100
|
-
setConsentState(consentState);
|
|
102
|
+
if (consentState === "granted" || consentState === "denied") setConsentState(consentState);
|
|
101
103
|
return consentState;
|
|
102
104
|
}
|
|
103
105
|
|
|
@@ -154,8 +156,7 @@ function isValidGtagId(id) {
|
|
|
154
156
|
}
|
|
155
157
|
function ensureGtagFunction() {
|
|
156
158
|
window.dataLayer = window.dataLayer || [];
|
|
157
|
-
if (typeof window.gtag === "function")
|
|
158
|
-
return window.gtag;
|
|
159
|
+
if (typeof window.gtag === "function") return window.gtag;
|
|
159
160
|
window.gtag = (...args) => {
|
|
160
161
|
window.dataLayer?.push(args);
|
|
161
162
|
};
|
|
@@ -172,17 +173,17 @@ function applyDefaultConsentState() {
|
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
function loadGtagScript(gtagId) {
|
|
175
|
-
if (typeof document === "undefined")
|
|
176
|
-
return;
|
|
176
|
+
if (typeof document === "undefined") return;
|
|
177
177
|
const marker = getScriptMarker("gtag-loader");
|
|
178
|
-
const existingScript = document.querySelector(
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
const existingScript = document.querySelector(
|
|
179
|
+
`script[${TRACKING_SCRIPT_ATTRIBUTE}="${marker}"]`
|
|
180
|
+
);
|
|
181
|
+
if (existingScript) return;
|
|
181
182
|
const script = document.createElement("script");
|
|
182
183
|
script.async = true;
|
|
183
184
|
script.src = `${GTAG_SCRIPT_HOST}?id=${encodeURIComponent(gtagId)}`;
|
|
184
185
|
script.setAttribute(TRACKING_SCRIPT_ATTRIBUTE, marker);
|
|
185
|
-
document.head.
|
|
186
|
+
document.head.append(script);
|
|
186
187
|
}
|
|
187
188
|
function initializeGtag(gtagId) {
|
|
188
189
|
const gtag = ensureGtagFunction();
|
|
@@ -190,21 +191,19 @@ function initializeGtag(gtagId) {
|
|
|
190
191
|
gtag("config", gtagId);
|
|
191
192
|
}
|
|
192
193
|
function bootstrapGoogleAdsTracking(gtagId) {
|
|
193
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
194
|
-
|
|
195
|
-
if (!isValidGtagId(gtagId))
|
|
196
|
-
return;
|
|
194
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
195
|
+
if (!isValidGtagId(gtagId)) return;
|
|
197
196
|
applyDefaultConsentState();
|
|
198
197
|
loadGtagScript(gtagId);
|
|
199
198
|
initializeGtag(gtagId);
|
|
200
199
|
restoreStoredConsent();
|
|
201
200
|
}
|
|
202
201
|
function bootstrapMultipleGtags(gtagIds) {
|
|
203
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
203
|
+
const ids = Object.values(gtagIds).filter(
|
|
204
|
+
(id) => typeof id === "string" && isValidGtagId(id)
|
|
205
|
+
);
|
|
206
|
+
if (ids.length === 0) return;
|
|
208
207
|
applyDefaultConsentState();
|
|
209
208
|
loadGtagScript(ids[0]);
|
|
210
209
|
const gtag = ensureGtagFunction();
|
|
@@ -256,18 +255,15 @@ function getTrackingQueryValues(searchParams) {
|
|
|
256
255
|
}, {});
|
|
257
256
|
}
|
|
258
257
|
function getCookieValueFromDocument(key) {
|
|
259
|
-
if (typeof document === "undefined")
|
|
260
|
-
return null;
|
|
258
|
+
if (typeof document === "undefined") return null;
|
|
261
259
|
const cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
262
260
|
const match = cookies.find((cookie) => cookie.startsWith(`${key}=`));
|
|
263
|
-
if (!match)
|
|
264
|
-
return null;
|
|
261
|
+
if (!match) return null;
|
|
265
262
|
const [, rawValue = ""] = match.split("=");
|
|
266
263
|
return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
|
|
267
264
|
}
|
|
268
265
|
function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
|
|
269
|
-
if (typeof document === "undefined")
|
|
270
|
-
return;
|
|
266
|
+
if (typeof document === "undefined") return;
|
|
271
267
|
const encodedValue = encodeURIComponent(value);
|
|
272
268
|
document.cookie = `${key}=${encodedValue}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
|
|
273
269
|
}
|
|
@@ -307,18 +303,15 @@ function writeLocalStorage(key, value) {
|
|
|
307
303
|
}
|
|
308
304
|
}
|
|
309
305
|
function getVisitorId() {
|
|
310
|
-
if (typeof window === "undefined")
|
|
311
|
-
return safeUuid();
|
|
306
|
+
if (typeof window === "undefined") return safeUuid();
|
|
312
307
|
const existing = readLocalStorage(VISITOR_STORAGE_KEY);
|
|
313
|
-
if (existing && existing.length > 0)
|
|
314
|
-
return existing;
|
|
308
|
+
if (existing && existing.length > 0) return existing;
|
|
315
309
|
const fresh = safeUuid();
|
|
316
310
|
writeLocalStorage(VISITOR_STORAGE_KEY, fresh);
|
|
317
311
|
return fresh;
|
|
318
312
|
}
|
|
319
313
|
function getOrRotateSessionId(now = Date.now()) {
|
|
320
|
-
if (typeof window === "undefined")
|
|
321
|
-
return { id: safeUuid(), isNew: true };
|
|
314
|
+
if (typeof window === "undefined") return { id: safeUuid(), isNew: true };
|
|
322
315
|
const raw = readLocalStorage(SESSION_STORAGE_KEY);
|
|
323
316
|
if (raw) {
|
|
324
317
|
try {
|
|
@@ -391,8 +384,7 @@ function setLastFiredUrl(url) {
|
|
|
391
384
|
writeSessionStorage(LAST_FIRED_URL_STORAGE_KEY, url);
|
|
392
385
|
}
|
|
393
386
|
function buildPageViewMetadata(referrerOverride) {
|
|
394
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
395
|
-
return null;
|
|
387
|
+
if (typeof window === "undefined" || typeof document === "undefined") return null;
|
|
396
388
|
return pageViewMetadataSchema.parse({
|
|
397
389
|
page: {
|
|
398
390
|
title: document.title || null,
|
|
@@ -405,8 +397,7 @@ function buildPageViewMetadata(referrerOverride) {
|
|
|
405
397
|
});
|
|
406
398
|
}
|
|
407
399
|
function fireManualPageView(client) {
|
|
408
|
-
if (typeof window === "undefined")
|
|
409
|
-
return;
|
|
400
|
+
if (typeof window === "undefined") return;
|
|
410
401
|
const currentHref = window.location.href;
|
|
411
402
|
const previousFiredUrl = getLastFiredUrl();
|
|
412
403
|
const internalReferrer = previousFiredUrl !== null && previousFiredUrl !== currentHref ? previousFiredUrl : null;
|
|
@@ -442,8 +433,7 @@ function attachAutoPageView(client, options = {}) {
|
|
|
442
433
|
let lastPath = window.location.pathname + window.location.search;
|
|
443
434
|
function maybeFire() {
|
|
444
435
|
const current = window.location.pathname + window.location.search;
|
|
445
|
-
if (current === lastPath)
|
|
446
|
-
return;
|
|
436
|
+
if (current === lastPath) return;
|
|
447
437
|
lastPath = current;
|
|
448
438
|
fireManualPageView(client);
|
|
449
439
|
}
|
|
@@ -465,8 +455,7 @@ function attachAutoPageView(client, options = {}) {
|
|
|
465
455
|
history.replaceState = patchedReplaceState;
|
|
466
456
|
window.addEventListener("popstate", maybeFire);
|
|
467
457
|
window.addEventListener("pageshow", handlePageShow);
|
|
468
|
-
if (!options.skipInitial)
|
|
469
|
-
fireManualPageView(client);
|
|
458
|
+
if (!options.skipInitial) fireManualPageView(client);
|
|
470
459
|
return () => {
|
|
471
460
|
history.pushState = originalPushState;
|
|
472
461
|
history.replaceState = originalReplaceState;
|
|
@@ -548,8 +537,7 @@ function buildContext(surface, sdkVersion, packageName, environment, activeGtagI
|
|
|
548
537
|
};
|
|
549
538
|
}
|
|
550
539
|
function readTrackingParams() {
|
|
551
|
-
if (typeof window === "undefined")
|
|
552
|
-
return createEmptyTrackingParams();
|
|
540
|
+
if (typeof window === "undefined") return createEmptyTrackingParams();
|
|
553
541
|
try {
|
|
554
542
|
captureTrackingParamsFromLocation();
|
|
555
543
|
} catch {
|
|
@@ -564,8 +552,7 @@ function consentSnapshot() {
|
|
|
564
552
|
}
|
|
565
553
|
}
|
|
566
554
|
async function postWithFetch(url, body, apiKey, identity, keepalive) {
|
|
567
|
-
if (typeof fetch !== "function")
|
|
568
|
-
return;
|
|
555
|
+
if (typeof fetch !== "function") return;
|
|
569
556
|
try {
|
|
570
557
|
await fetch(url, {
|
|
571
558
|
method: "POST",
|
|
@@ -625,8 +612,7 @@ function createTrackingClient(config) {
|
|
|
625
612
|
const visitorId = getVisitorId();
|
|
626
613
|
const initialSession = getOrRotateSessionId();
|
|
627
614
|
let sessionId = initialSession.id;
|
|
628
|
-
if (typeof window !== "undefined")
|
|
629
|
-
firstPage = window.location.href;
|
|
615
|
+
if (typeof window !== "undefined") firstPage = window.location.href;
|
|
630
616
|
function enqueueHeartbeat() {
|
|
631
617
|
const metadata = buildHeartbeatMetadata(
|
|
632
618
|
config.surface,
|
|
@@ -652,7 +638,13 @@ function createTrackingClient(config) {
|
|
|
652
638
|
}
|
|
653
639
|
sessionId = rotated.id;
|
|
654
640
|
const params = readTrackingParams();
|
|
655
|
-
const context = buildContext(
|
|
641
|
+
const context = buildContext(
|
|
642
|
+
config.surface,
|
|
643
|
+
sdkVersion,
|
|
644
|
+
packageName,
|
|
645
|
+
environment,
|
|
646
|
+
activeGtagIds
|
|
647
|
+
);
|
|
656
648
|
return {
|
|
657
649
|
session_id: sessionId,
|
|
658
650
|
visitor_id: visitorId,
|
|
@@ -669,8 +661,7 @@ function createTrackingClient(config) {
|
|
|
669
661
|
};
|
|
670
662
|
}
|
|
671
663
|
function scheduleFlush() {
|
|
672
|
-
if (flushTimer !== null || destroyed)
|
|
673
|
-
return;
|
|
664
|
+
if (flushTimer !== null || destroyed) return;
|
|
674
665
|
flushTimer = setTimeout(() => {
|
|
675
666
|
flushTimer = null;
|
|
676
667
|
void flush();
|
|
@@ -683,8 +674,7 @@ function createTrackingClient(config) {
|
|
|
683
674
|
}
|
|
684
675
|
}
|
|
685
676
|
async function flush() {
|
|
686
|
-
if (queue.length === 0)
|
|
687
|
-
return;
|
|
677
|
+
if (queue.length === 0) return;
|
|
688
678
|
const events = queue.slice(0, HARD_MAX_BATCH);
|
|
689
679
|
queue = queue.slice(events.length);
|
|
690
680
|
clearScheduledFlush();
|
|
@@ -696,10 +686,8 @@ function createTrackingClient(config) {
|
|
|
696
686
|
await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, false);
|
|
697
687
|
}
|
|
698
688
|
function trackEvent(input) {
|
|
699
|
-
if (destroyed)
|
|
700
|
-
|
|
701
|
-
if (!input || typeof input.eventType !== "string" || input.eventType.length === 0)
|
|
702
|
-
return;
|
|
689
|
+
if (destroyed) return;
|
|
690
|
+
if (!input || typeof input.eventType !== "string" || input.eventType.length === 0) return;
|
|
703
691
|
const occurredAt = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : typeof input.occurredAt === "string" ? input.occurredAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
704
692
|
queue.push({
|
|
705
693
|
event_type: input.eventType,
|
|
@@ -714,8 +702,7 @@ function createTrackingClient(config) {
|
|
|
714
702
|
}
|
|
715
703
|
}
|
|
716
704
|
function flushOnUnload() {
|
|
717
|
-
if (queue.length === 0)
|
|
718
|
-
return;
|
|
705
|
+
if (queue.length === 0) return;
|
|
719
706
|
const events = queue.slice(0, HARD_MAX_BATCH);
|
|
720
707
|
queue = queue.slice(events.length);
|
|
721
708
|
clearScheduledFlush();
|
|
@@ -1481,11 +1468,6 @@ function createSalesClient(config) {
|
|
|
1481
1468
|
};
|
|
1482
1469
|
}
|
|
1483
1470
|
|
|
1484
|
-
// ../tracking-core/src/resources/services.ts
|
|
1485
|
-
async function fetchServices(config) {
|
|
1486
|
-
return salesRequest(config, "GET", "/services");
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
1471
|
// ../tracking-core/src/resources/sales/money.ts
|
|
1490
1472
|
var MINOR_UNIT_EXPONENT = {
|
|
1491
1473
|
USD: 2,
|
|
@@ -1519,6 +1501,123 @@ function formatDateInTz(iso, timeZone, opts, locale) {
|
|
|
1519
1501
|
}).format(date);
|
|
1520
1502
|
}
|
|
1521
1503
|
|
|
1504
|
+
// ../tracking-core/src/resources/sales/schema.ts
|
|
1505
|
+
var import_zod11 = require("zod");
|
|
1506
|
+
var SUPPORTED_CURRENCIES = ["USD", "CAD"];
|
|
1507
|
+
var TRACKING_ENVIRONMENTS = ["production", "development"];
|
|
1508
|
+
var currencySchema = import_zod11.z.enum(SUPPORTED_CURRENCIES);
|
|
1509
|
+
var centsSchema = import_zod11.z.number().int().nonnegative();
|
|
1510
|
+
var quantitySchema = import_zod11.z.string().regex(/^\d+(\.\d{1,3})?$/);
|
|
1511
|
+
var metadataSchema = import_zod11.z.record(import_zod11.z.unknown());
|
|
1512
|
+
var saleItemSchema = import_zod11.z.object({
|
|
1513
|
+
external_item_id: import_zod11.z.string().nullable().optional(),
|
|
1514
|
+
name: import_zod11.z.string().nullable().optional(),
|
|
1515
|
+
category: import_zod11.z.string().nullable().optional(),
|
|
1516
|
+
quantity: quantitySchema,
|
|
1517
|
+
unit_price_cents: centsSchema,
|
|
1518
|
+
// Non-negativity validated on the wire — same contract as the other cents
|
|
1519
|
+
// fields — and backstopped by the DB CHECK.
|
|
1520
|
+
unit_cost_cents: centsSchema.nullable().optional()
|
|
1521
|
+
}).strict();
|
|
1522
|
+
var saleServiceSchema = import_zod11.z.object({
|
|
1523
|
+
service: import_zod11.z.string(),
|
|
1524
|
+
amount_cents: centsSchema
|
|
1525
|
+
}).strict();
|
|
1526
|
+
var customerNameSchema = import_zod11.z.string().max(200);
|
|
1527
|
+
var customerPhoneSchema = import_zod11.z.string().max(64);
|
|
1528
|
+
var customerEmailSchema = import_zod11.z.string().max(320).email();
|
|
1529
|
+
function refineServiceXor(val, ctx, { requireAmount }) {
|
|
1530
|
+
if (val.services != null) {
|
|
1531
|
+
if (val.service != null) {
|
|
1532
|
+
ctx.addIssue({
|
|
1533
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1534
|
+
message: "pass either `service` or `services`, not both",
|
|
1535
|
+
path: ["services"]
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
if (val.services.length === 0) {
|
|
1539
|
+
ctx.addIssue({
|
|
1540
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1541
|
+
message: "`services` must not be empty",
|
|
1542
|
+
path: ["services"]
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
const keys = val.services.map((s) => s.service);
|
|
1546
|
+
if (new Set(keys).size !== keys.length) {
|
|
1547
|
+
ctx.addIssue({
|
|
1548
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1549
|
+
message: "`services` must not list the same service more than once",
|
|
1550
|
+
path: ["services"]
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
if (val.amount_total_cents != null) {
|
|
1554
|
+
const sum = val.services.reduce((acc, s) => acc + s.amount_cents, 0);
|
|
1555
|
+
if (val.amount_total_cents !== sum) {
|
|
1556
|
+
ctx.addIssue({
|
|
1557
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1558
|
+
message: "amount_total_cents must equal the sum of the services amounts (omit it to derive it automatically)",
|
|
1559
|
+
path: ["amount_total_cents"]
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
} else if (requireAmount && val.amount_total_cents == null) {
|
|
1564
|
+
ctx.addIssue({
|
|
1565
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1566
|
+
message: "amount_total_cents is required unless `services` is provided",
|
|
1567
|
+
path: ["amount_total_cents"]
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
var saleCreateSchema = import_zod11.z.object({
|
|
1572
|
+
external_id: import_zod11.z.string().nullable().optional(),
|
|
1573
|
+
description: import_zod11.z.string().nullable().optional(),
|
|
1574
|
+
service: import_zod11.z.string().nullable().optional(),
|
|
1575
|
+
services: import_zod11.z.array(saleServiceSchema).nullable().optional(),
|
|
1576
|
+
currency: currencySchema,
|
|
1577
|
+
// Optional only because the plural `services` form derives it from the sum
|
|
1578
|
+
// (see refineServiceXor); the singular/serviceless path still requires it.
|
|
1579
|
+
amount_total_cents: centsSchema.nullable().optional(),
|
|
1580
|
+
occurred_at: import_zod11.z.string().datetime(),
|
|
1581
|
+
environment: import_zod11.z.enum(TRACKING_ENVIRONMENTS).default("production"),
|
|
1582
|
+
items: import_zod11.z.array(saleItemSchema).default([]),
|
|
1583
|
+
metadata: metadataSchema.nullable().optional(),
|
|
1584
|
+
customer_name: customerNameSchema.nullable().optional(),
|
|
1585
|
+
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
1586
|
+
customer_email: customerEmailSchema.nullable().optional()
|
|
1587
|
+
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: true }));
|
|
1588
|
+
var saleUpdateSchema = import_zod11.z.object({
|
|
1589
|
+
description: import_zod11.z.string().nullable().optional(),
|
|
1590
|
+
service: import_zod11.z.string().nullable().optional(),
|
|
1591
|
+
services: import_zod11.z.array(saleServiceSchema).nullable().optional(),
|
|
1592
|
+
currency: currencySchema.optional(),
|
|
1593
|
+
amount_total_cents: centsSchema.optional(),
|
|
1594
|
+
occurred_at: import_zod11.z.string().datetime().optional(),
|
|
1595
|
+
items: import_zod11.z.array(saleItemSchema).optional(),
|
|
1596
|
+
metadata: metadataSchema.nullable().optional(),
|
|
1597
|
+
customer_name: customerNameSchema.nullable().optional(),
|
|
1598
|
+
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
1599
|
+
customer_email: customerEmailSchema.nullable().optional()
|
|
1600
|
+
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: false }));
|
|
1601
|
+
var TRACKING_RANGES = ["24h", "7d", "30d"];
|
|
1602
|
+
var NAMED_RANGES = [
|
|
1603
|
+
"today",
|
|
1604
|
+
"yesterday",
|
|
1605
|
+
"wtd",
|
|
1606
|
+
"mtd",
|
|
1607
|
+
"qtd",
|
|
1608
|
+
"ytd",
|
|
1609
|
+
"24h",
|
|
1610
|
+
"7d",
|
|
1611
|
+
"30d",
|
|
1612
|
+
"90d",
|
|
1613
|
+
"custom"
|
|
1614
|
+
];
|
|
1615
|
+
|
|
1616
|
+
// ../tracking-core/src/resources/services.ts
|
|
1617
|
+
async function fetchServices(config) {
|
|
1618
|
+
return salesRequest(config, "GET", "/services");
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1522
1621
|
// ../tracking-core/src/phone.ts
|
|
1523
1622
|
var import_libphonenumber_js = require("libphonenumber-js");
|
|
1524
1623
|
var DEFAULT_PHONE_COUNTRY = "CA";
|
|
@@ -1804,10 +1903,7 @@ var ANIMATION_KEYFRAMES = `
|
|
|
1804
1903
|
var import_react3 = require("react");
|
|
1805
1904
|
function GoogleAdsTracking(props) {
|
|
1806
1905
|
const { gtagId, gtagIds } = props;
|
|
1807
|
-
const gtagIdsKey = (0, import_react3.useMemo)(
|
|
1808
|
-
() => gtagIds ? JSON.stringify(gtagIds) : "",
|
|
1809
|
-
[gtagIds]
|
|
1810
|
-
);
|
|
1906
|
+
const gtagIdsKey = (0, import_react3.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
1811
1907
|
(0, import_react3.useEffect)(() => {
|
|
1812
1908
|
if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
1813
1909
|
bootstrapMultipleGtags(gtagIds);
|
|
@@ -1822,14 +1918,24 @@ function GoogleAdsTracking(props) {
|
|
|
1822
1918
|
var import_react5 = require("react");
|
|
1823
1919
|
|
|
1824
1920
|
// package.json
|
|
1825
|
-
var version = "0.12.
|
|
1921
|
+
var version = "0.12.2";
|
|
1826
1922
|
|
|
1827
1923
|
// ../tracking-core/src/phone-react.tsx
|
|
1828
1924
|
var import_react4 = require("react");
|
|
1829
1925
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1830
|
-
var
|
|
1926
|
+
var _phoneConfigContext;
|
|
1927
|
+
function phoneConfigContext() {
|
|
1928
|
+
return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react4.createContext)(null));
|
|
1929
|
+
}
|
|
1930
|
+
function PhoneConfigProvider({
|
|
1931
|
+
value,
|
|
1932
|
+
children
|
|
1933
|
+
}) {
|
|
1934
|
+
const Ctx = phoneConfigContext();
|
|
1935
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ctx.Provider, { value, children });
|
|
1936
|
+
}
|
|
1831
1937
|
function usePhoneConfig() {
|
|
1832
|
-
const ctx = (0, import_react4.useContext)(
|
|
1938
|
+
const ctx = (0, import_react4.useContext)(phoneConfigContext());
|
|
1833
1939
|
return {
|
|
1834
1940
|
defaultCountry: ctx?.defaultCountry ?? DEFAULT_PHONE_COUNTRY,
|
|
1835
1941
|
display: ctx?.display ?? "national"
|
|
@@ -1922,13 +2028,15 @@ function createTracking(options) {
|
|
|
1922
2028
|
return {
|
|
1923
2029
|
// Still publish phone config so usePhoneField/<PhoneField> work even when
|
|
1924
2030
|
// tracking is disabled (missing apiKey/endpoint).
|
|
1925
|
-
TrackingProvider: ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2031
|
+
TrackingProvider: ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }),
|
|
1926
2032
|
useTracking: () => noopTyped
|
|
1927
2033
|
};
|
|
1928
2034
|
}
|
|
1929
2035
|
const TrackingContext = (0, import_react5.createContext)(null);
|
|
1930
2036
|
function TrackingProvider({ gtagId, gtagIds, children }) {
|
|
1931
|
-
const resolvedGtagIds = gtagIds
|
|
2037
|
+
const resolvedGtagIds = gtagIds ? Object.fromEntries(
|
|
2038
|
+
Object.entries(gtagIds).filter((e) => e[1] != null)
|
|
2039
|
+
) : gtagId ? { default: gtagId } : void 0;
|
|
1932
2040
|
const client = (0, import_react5.useMemo)(
|
|
1933
2041
|
() => createTypedClient(
|
|
1934
2042
|
getOrCreateTrackingClient({
|
|
@@ -1995,7 +2103,7 @@ function createTracking(options) {
|
|
|
1995
2103
|
}
|
|
1996
2104
|
};
|
|
1997
2105
|
}, []);
|
|
1998
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
|
|
1999
2107
|
}
|
|
2000
2108
|
function useTracking() {
|
|
2001
2109
|
const client = (0, import_react5.useContext)(TrackingContext);
|
|
@@ -2014,9 +2122,11 @@ function createTracking(options) {
|
|
|
2014
2122
|
ConsentBanner,
|
|
2015
2123
|
DEFAULT_PHONE_COUNTRY,
|
|
2016
2124
|
GoogleAdsTracking,
|
|
2017
|
-
|
|
2125
|
+
NAMED_RANGES,
|
|
2018
2126
|
PhoneField,
|
|
2127
|
+
SUPPORTED_CURRENCIES,
|
|
2019
2128
|
TRACKING_PARAM_KEYS,
|
|
2129
|
+
TRACKING_RANGES,
|
|
2020
2130
|
captureTrackingParamsFromLocation,
|
|
2021
2131
|
createSalesClient,
|
|
2022
2132
|
createTracking,
|
|
@@ -2033,6 +2143,11 @@ function createTracking(options) {
|
|
|
2033
2143
|
parsePhone,
|
|
2034
2144
|
phoneField,
|
|
2035
2145
|
resetConsent,
|
|
2146
|
+
saleCreateSchema,
|
|
2147
|
+
saleItemSchema,
|
|
2148
|
+
saleServiceSchema,
|
|
2149
|
+
saleUpdateSchema,
|
|
2150
|
+
salesRequest,
|
|
2036
2151
|
setConsentState,
|
|
2037
2152
|
toE164,
|
|
2038
2153
|
toMinor,
|