@aranova/tracking-react 0.12.0 → 0.12.1
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 +190 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +183 -84
- package/dist/index.mjs.map +1 -1
- package/dist/{phone-utils-CVX7JmqB.d.mts → phone-utils-DXAki8pO.d.mts} +7 -6
- package/dist/{phone-utils-CVX7JmqB.d.ts → phone-utils-DXAki8pO.d.ts} +7 -6
- 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,17 @@ 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
|
-
return;
|
|
202
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
205
203
|
const ids = Object.values(gtagIds).filter(isValidGtagId);
|
|
206
|
-
if (ids.length === 0)
|
|
207
|
-
return;
|
|
204
|
+
if (ids.length === 0) return;
|
|
208
205
|
applyDefaultConsentState();
|
|
209
206
|
loadGtagScript(ids[0]);
|
|
210
207
|
const gtag = ensureGtagFunction();
|
|
@@ -256,18 +253,15 @@ function getTrackingQueryValues(searchParams) {
|
|
|
256
253
|
}, {});
|
|
257
254
|
}
|
|
258
255
|
function getCookieValueFromDocument(key) {
|
|
259
|
-
if (typeof document === "undefined")
|
|
260
|
-
return null;
|
|
256
|
+
if (typeof document === "undefined") return null;
|
|
261
257
|
const cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
262
258
|
const match = cookies.find((cookie) => cookie.startsWith(`${key}=`));
|
|
263
|
-
if (!match)
|
|
264
|
-
return null;
|
|
259
|
+
if (!match) return null;
|
|
265
260
|
const [, rawValue = ""] = match.split("=");
|
|
266
261
|
return normalizeTrackingCookieValue(decodeURIComponent(rawValue));
|
|
267
262
|
}
|
|
268
263
|
function setTrackingCookie(key, value, maxAgeSeconds = TRACKING_COOKIE_MAX_AGE_SECONDS) {
|
|
269
|
-
if (typeof document === "undefined")
|
|
270
|
-
return;
|
|
264
|
+
if (typeof document === "undefined") return;
|
|
271
265
|
const encodedValue = encodeURIComponent(value);
|
|
272
266
|
document.cookie = `${key}=${encodedValue}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`;
|
|
273
267
|
}
|
|
@@ -307,18 +301,15 @@ function writeLocalStorage(key, value) {
|
|
|
307
301
|
}
|
|
308
302
|
}
|
|
309
303
|
function getVisitorId() {
|
|
310
|
-
if (typeof window === "undefined")
|
|
311
|
-
return safeUuid();
|
|
304
|
+
if (typeof window === "undefined") return safeUuid();
|
|
312
305
|
const existing = readLocalStorage(VISITOR_STORAGE_KEY);
|
|
313
|
-
if (existing && existing.length > 0)
|
|
314
|
-
return existing;
|
|
306
|
+
if (existing && existing.length > 0) return existing;
|
|
315
307
|
const fresh = safeUuid();
|
|
316
308
|
writeLocalStorage(VISITOR_STORAGE_KEY, fresh);
|
|
317
309
|
return fresh;
|
|
318
310
|
}
|
|
319
311
|
function getOrRotateSessionId(now = Date.now()) {
|
|
320
|
-
if (typeof window === "undefined")
|
|
321
|
-
return { id: safeUuid(), isNew: true };
|
|
312
|
+
if (typeof window === "undefined") return { id: safeUuid(), isNew: true };
|
|
322
313
|
const raw = readLocalStorage(SESSION_STORAGE_KEY);
|
|
323
314
|
if (raw) {
|
|
324
315
|
try {
|
|
@@ -391,8 +382,7 @@ function setLastFiredUrl(url) {
|
|
|
391
382
|
writeSessionStorage(LAST_FIRED_URL_STORAGE_KEY, url);
|
|
392
383
|
}
|
|
393
384
|
function buildPageViewMetadata(referrerOverride) {
|
|
394
|
-
if (typeof window === "undefined" || typeof document === "undefined")
|
|
395
|
-
return null;
|
|
385
|
+
if (typeof window === "undefined" || typeof document === "undefined") return null;
|
|
396
386
|
return pageViewMetadataSchema.parse({
|
|
397
387
|
page: {
|
|
398
388
|
title: document.title || null,
|
|
@@ -405,8 +395,7 @@ function buildPageViewMetadata(referrerOverride) {
|
|
|
405
395
|
});
|
|
406
396
|
}
|
|
407
397
|
function fireManualPageView(client) {
|
|
408
|
-
if (typeof window === "undefined")
|
|
409
|
-
return;
|
|
398
|
+
if (typeof window === "undefined") return;
|
|
410
399
|
const currentHref = window.location.href;
|
|
411
400
|
const previousFiredUrl = getLastFiredUrl();
|
|
412
401
|
const internalReferrer = previousFiredUrl !== null && previousFiredUrl !== currentHref ? previousFiredUrl : null;
|
|
@@ -442,8 +431,7 @@ function attachAutoPageView(client, options = {}) {
|
|
|
442
431
|
let lastPath = window.location.pathname + window.location.search;
|
|
443
432
|
function maybeFire() {
|
|
444
433
|
const current = window.location.pathname + window.location.search;
|
|
445
|
-
if (current === lastPath)
|
|
446
|
-
return;
|
|
434
|
+
if (current === lastPath) return;
|
|
447
435
|
lastPath = current;
|
|
448
436
|
fireManualPageView(client);
|
|
449
437
|
}
|
|
@@ -465,8 +453,7 @@ function attachAutoPageView(client, options = {}) {
|
|
|
465
453
|
history.replaceState = patchedReplaceState;
|
|
466
454
|
window.addEventListener("popstate", maybeFire);
|
|
467
455
|
window.addEventListener("pageshow", handlePageShow);
|
|
468
|
-
if (!options.skipInitial)
|
|
469
|
-
fireManualPageView(client);
|
|
456
|
+
if (!options.skipInitial) fireManualPageView(client);
|
|
470
457
|
return () => {
|
|
471
458
|
history.pushState = originalPushState;
|
|
472
459
|
history.replaceState = originalReplaceState;
|
|
@@ -548,8 +535,7 @@ function buildContext(surface, sdkVersion, packageName, environment, activeGtagI
|
|
|
548
535
|
};
|
|
549
536
|
}
|
|
550
537
|
function readTrackingParams() {
|
|
551
|
-
if (typeof window === "undefined")
|
|
552
|
-
return createEmptyTrackingParams();
|
|
538
|
+
if (typeof window === "undefined") return createEmptyTrackingParams();
|
|
553
539
|
try {
|
|
554
540
|
captureTrackingParamsFromLocation();
|
|
555
541
|
} catch {
|
|
@@ -564,8 +550,7 @@ function consentSnapshot() {
|
|
|
564
550
|
}
|
|
565
551
|
}
|
|
566
552
|
async function postWithFetch(url, body, apiKey, identity, keepalive) {
|
|
567
|
-
if (typeof fetch !== "function")
|
|
568
|
-
return;
|
|
553
|
+
if (typeof fetch !== "function") return;
|
|
569
554
|
try {
|
|
570
555
|
await fetch(url, {
|
|
571
556
|
method: "POST",
|
|
@@ -625,8 +610,7 @@ function createTrackingClient(config) {
|
|
|
625
610
|
const visitorId = getVisitorId();
|
|
626
611
|
const initialSession = getOrRotateSessionId();
|
|
627
612
|
let sessionId = initialSession.id;
|
|
628
|
-
if (typeof window !== "undefined")
|
|
629
|
-
firstPage = window.location.href;
|
|
613
|
+
if (typeof window !== "undefined") firstPage = window.location.href;
|
|
630
614
|
function enqueueHeartbeat() {
|
|
631
615
|
const metadata = buildHeartbeatMetadata(
|
|
632
616
|
config.surface,
|
|
@@ -652,7 +636,13 @@ function createTrackingClient(config) {
|
|
|
652
636
|
}
|
|
653
637
|
sessionId = rotated.id;
|
|
654
638
|
const params = readTrackingParams();
|
|
655
|
-
const context = buildContext(
|
|
639
|
+
const context = buildContext(
|
|
640
|
+
config.surface,
|
|
641
|
+
sdkVersion,
|
|
642
|
+
packageName,
|
|
643
|
+
environment,
|
|
644
|
+
activeGtagIds
|
|
645
|
+
);
|
|
656
646
|
return {
|
|
657
647
|
session_id: sessionId,
|
|
658
648
|
visitor_id: visitorId,
|
|
@@ -669,8 +659,7 @@ function createTrackingClient(config) {
|
|
|
669
659
|
};
|
|
670
660
|
}
|
|
671
661
|
function scheduleFlush() {
|
|
672
|
-
if (flushTimer !== null || destroyed)
|
|
673
|
-
return;
|
|
662
|
+
if (flushTimer !== null || destroyed) return;
|
|
674
663
|
flushTimer = setTimeout(() => {
|
|
675
664
|
flushTimer = null;
|
|
676
665
|
void flush();
|
|
@@ -683,8 +672,7 @@ function createTrackingClient(config) {
|
|
|
683
672
|
}
|
|
684
673
|
}
|
|
685
674
|
async function flush() {
|
|
686
|
-
if (queue.length === 0)
|
|
687
|
-
return;
|
|
675
|
+
if (queue.length === 0) return;
|
|
688
676
|
const events = queue.slice(0, HARD_MAX_BATCH);
|
|
689
677
|
queue = queue.slice(events.length);
|
|
690
678
|
clearScheduledFlush();
|
|
@@ -696,10 +684,8 @@ function createTrackingClient(config) {
|
|
|
696
684
|
await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, false);
|
|
697
685
|
}
|
|
698
686
|
function trackEvent(input) {
|
|
699
|
-
if (destroyed)
|
|
700
|
-
|
|
701
|
-
if (!input || typeof input.eventType !== "string" || input.eventType.length === 0)
|
|
702
|
-
return;
|
|
687
|
+
if (destroyed) return;
|
|
688
|
+
if (!input || typeof input.eventType !== "string" || input.eventType.length === 0) return;
|
|
703
689
|
const occurredAt = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : typeof input.occurredAt === "string" ? input.occurredAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
704
690
|
queue.push({
|
|
705
691
|
event_type: input.eventType,
|
|
@@ -714,8 +700,7 @@ function createTrackingClient(config) {
|
|
|
714
700
|
}
|
|
715
701
|
}
|
|
716
702
|
function flushOnUnload() {
|
|
717
|
-
if (queue.length === 0)
|
|
718
|
-
return;
|
|
703
|
+
if (queue.length === 0) return;
|
|
719
704
|
const events = queue.slice(0, HARD_MAX_BATCH);
|
|
720
705
|
queue = queue.slice(events.length);
|
|
721
706
|
clearScheduledFlush();
|
|
@@ -1481,11 +1466,6 @@ function createSalesClient(config) {
|
|
|
1481
1466
|
};
|
|
1482
1467
|
}
|
|
1483
1468
|
|
|
1484
|
-
// ../tracking-core/src/resources/services.ts
|
|
1485
|
-
async function fetchServices(config) {
|
|
1486
|
-
return salesRequest(config, "GET", "/services");
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
1469
|
// ../tracking-core/src/resources/sales/money.ts
|
|
1490
1470
|
var MINOR_UNIT_EXPONENT = {
|
|
1491
1471
|
USD: 2,
|
|
@@ -1519,6 +1499,123 @@ function formatDateInTz(iso, timeZone, opts, locale) {
|
|
|
1519
1499
|
}).format(date);
|
|
1520
1500
|
}
|
|
1521
1501
|
|
|
1502
|
+
// ../tracking-core/src/resources/sales/schema.ts
|
|
1503
|
+
var import_zod11 = require("zod");
|
|
1504
|
+
var SUPPORTED_CURRENCIES = ["USD", "CAD"];
|
|
1505
|
+
var TRACKING_ENVIRONMENTS = ["production", "development"];
|
|
1506
|
+
var currencySchema = import_zod11.z.enum(SUPPORTED_CURRENCIES);
|
|
1507
|
+
var centsSchema = import_zod11.z.number().int().nonnegative();
|
|
1508
|
+
var quantitySchema = import_zod11.z.string().regex(/^\d+(\.\d{1,3})?$/);
|
|
1509
|
+
var metadataSchema = import_zod11.z.record(import_zod11.z.unknown());
|
|
1510
|
+
var saleItemSchema = import_zod11.z.object({
|
|
1511
|
+
external_item_id: import_zod11.z.string().nullable().optional(),
|
|
1512
|
+
name: import_zod11.z.string().nullable().optional(),
|
|
1513
|
+
category: import_zod11.z.string().nullable().optional(),
|
|
1514
|
+
quantity: quantitySchema,
|
|
1515
|
+
unit_price_cents: centsSchema,
|
|
1516
|
+
// Non-negativity validated on the wire — same contract as the other cents
|
|
1517
|
+
// fields — and backstopped by the DB CHECK.
|
|
1518
|
+
unit_cost_cents: centsSchema.nullable().optional()
|
|
1519
|
+
}).strict();
|
|
1520
|
+
var saleServiceSchema = import_zod11.z.object({
|
|
1521
|
+
service: import_zod11.z.string(),
|
|
1522
|
+
amount_cents: centsSchema
|
|
1523
|
+
}).strict();
|
|
1524
|
+
var customerNameSchema = import_zod11.z.string().max(200);
|
|
1525
|
+
var customerPhoneSchema = import_zod11.z.string().max(64);
|
|
1526
|
+
var customerEmailSchema = import_zod11.z.string().max(320).email();
|
|
1527
|
+
function refineServiceXor(val, ctx, { requireAmount }) {
|
|
1528
|
+
if (val.services != null) {
|
|
1529
|
+
if (val.service != null) {
|
|
1530
|
+
ctx.addIssue({
|
|
1531
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1532
|
+
message: "pass either `service` or `services`, not both",
|
|
1533
|
+
path: ["services"]
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
if (val.services.length === 0) {
|
|
1537
|
+
ctx.addIssue({
|
|
1538
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1539
|
+
message: "`services` must not be empty",
|
|
1540
|
+
path: ["services"]
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
const keys = val.services.map((s) => s.service);
|
|
1544
|
+
if (new Set(keys).size !== keys.length) {
|
|
1545
|
+
ctx.addIssue({
|
|
1546
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1547
|
+
message: "`services` must not list the same service more than once",
|
|
1548
|
+
path: ["services"]
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
if (val.amount_total_cents != null) {
|
|
1552
|
+
const sum = val.services.reduce((acc, s) => acc + s.amount_cents, 0);
|
|
1553
|
+
if (val.amount_total_cents !== sum) {
|
|
1554
|
+
ctx.addIssue({
|
|
1555
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1556
|
+
message: "amount_total_cents must equal the sum of the services amounts (omit it to derive it automatically)",
|
|
1557
|
+
path: ["amount_total_cents"]
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
} else if (requireAmount && val.amount_total_cents == null) {
|
|
1562
|
+
ctx.addIssue({
|
|
1563
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
1564
|
+
message: "amount_total_cents is required unless `services` is provided",
|
|
1565
|
+
path: ["amount_total_cents"]
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
var saleCreateSchema = import_zod11.z.object({
|
|
1570
|
+
external_id: import_zod11.z.string().nullable().optional(),
|
|
1571
|
+
description: import_zod11.z.string().nullable().optional(),
|
|
1572
|
+
service: import_zod11.z.string().nullable().optional(),
|
|
1573
|
+
services: import_zod11.z.array(saleServiceSchema).nullable().optional(),
|
|
1574
|
+
currency: currencySchema,
|
|
1575
|
+
// Optional only because the plural `services` form derives it from the sum
|
|
1576
|
+
// (see refineServiceXor); the singular/serviceless path still requires it.
|
|
1577
|
+
amount_total_cents: centsSchema.nullable().optional(),
|
|
1578
|
+
occurred_at: import_zod11.z.string().datetime(),
|
|
1579
|
+
environment: import_zod11.z.enum(TRACKING_ENVIRONMENTS).default("production"),
|
|
1580
|
+
items: import_zod11.z.array(saleItemSchema).default([]),
|
|
1581
|
+
metadata: metadataSchema.nullable().optional(),
|
|
1582
|
+
customer_name: customerNameSchema.nullable().optional(),
|
|
1583
|
+
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
1584
|
+
customer_email: customerEmailSchema.nullable().optional()
|
|
1585
|
+
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: true }));
|
|
1586
|
+
var saleUpdateSchema = import_zod11.z.object({
|
|
1587
|
+
description: import_zod11.z.string().nullable().optional(),
|
|
1588
|
+
service: import_zod11.z.string().nullable().optional(),
|
|
1589
|
+
services: import_zod11.z.array(saleServiceSchema).nullable().optional(),
|
|
1590
|
+
currency: currencySchema.optional(),
|
|
1591
|
+
amount_total_cents: centsSchema.optional(),
|
|
1592
|
+
occurred_at: import_zod11.z.string().datetime().optional(),
|
|
1593
|
+
items: import_zod11.z.array(saleItemSchema).optional(),
|
|
1594
|
+
metadata: metadataSchema.nullable().optional(),
|
|
1595
|
+
customer_name: customerNameSchema.nullable().optional(),
|
|
1596
|
+
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
1597
|
+
customer_email: customerEmailSchema.nullable().optional()
|
|
1598
|
+
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: false }));
|
|
1599
|
+
var TRACKING_RANGES = ["24h", "7d", "30d"];
|
|
1600
|
+
var NAMED_RANGES = [
|
|
1601
|
+
"today",
|
|
1602
|
+
"yesterday",
|
|
1603
|
+
"wtd",
|
|
1604
|
+
"mtd",
|
|
1605
|
+
"qtd",
|
|
1606
|
+
"ytd",
|
|
1607
|
+
"24h",
|
|
1608
|
+
"7d",
|
|
1609
|
+
"30d",
|
|
1610
|
+
"90d",
|
|
1611
|
+
"custom"
|
|
1612
|
+
];
|
|
1613
|
+
|
|
1614
|
+
// ../tracking-core/src/resources/services.ts
|
|
1615
|
+
async function fetchServices(config) {
|
|
1616
|
+
return salesRequest(config, "GET", "/services");
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1522
1619
|
// ../tracking-core/src/phone.ts
|
|
1523
1620
|
var import_libphonenumber_js = require("libphonenumber-js");
|
|
1524
1621
|
var DEFAULT_PHONE_COUNTRY = "CA";
|
|
@@ -1804,10 +1901,7 @@ var ANIMATION_KEYFRAMES = `
|
|
|
1804
1901
|
var import_react3 = require("react");
|
|
1805
1902
|
function GoogleAdsTracking(props) {
|
|
1806
1903
|
const { gtagId, gtagIds } = props;
|
|
1807
|
-
const gtagIdsKey = (0, import_react3.useMemo)(
|
|
1808
|
-
() => gtagIds ? JSON.stringify(gtagIds) : "",
|
|
1809
|
-
[gtagIds]
|
|
1810
|
-
);
|
|
1904
|
+
const gtagIdsKey = (0, import_react3.useMemo)(() => gtagIds ? JSON.stringify(gtagIds) : "", [gtagIds]);
|
|
1811
1905
|
(0, import_react3.useEffect)(() => {
|
|
1812
1906
|
if (gtagIds && Object.keys(gtagIds).length > 0) {
|
|
1813
1907
|
bootstrapMultipleGtags(gtagIds);
|
|
@@ -1822,14 +1916,24 @@ function GoogleAdsTracking(props) {
|
|
|
1822
1916
|
var import_react5 = require("react");
|
|
1823
1917
|
|
|
1824
1918
|
// package.json
|
|
1825
|
-
var version = "0.12.
|
|
1919
|
+
var version = "0.12.1";
|
|
1826
1920
|
|
|
1827
1921
|
// ../tracking-core/src/phone-react.tsx
|
|
1828
1922
|
var import_react4 = require("react");
|
|
1829
1923
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1830
|
-
var
|
|
1924
|
+
var _phoneConfigContext;
|
|
1925
|
+
function phoneConfigContext() {
|
|
1926
|
+
return _phoneConfigContext ?? (_phoneConfigContext = (0, import_react4.createContext)(null));
|
|
1927
|
+
}
|
|
1928
|
+
function PhoneConfigProvider({
|
|
1929
|
+
value,
|
|
1930
|
+
children
|
|
1931
|
+
}) {
|
|
1932
|
+
const Ctx = phoneConfigContext();
|
|
1933
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ctx.Provider, { value, children });
|
|
1934
|
+
}
|
|
1831
1935
|
function usePhoneConfig() {
|
|
1832
|
-
const ctx = (0, import_react4.useContext)(
|
|
1936
|
+
const ctx = (0, import_react4.useContext)(phoneConfigContext());
|
|
1833
1937
|
return {
|
|
1834
1938
|
defaultCountry: ctx?.defaultCountry ?? DEFAULT_PHONE_COUNTRY,
|
|
1835
1939
|
display: ctx?.display ?? "national"
|
|
@@ -1922,7 +2026,7 @@ function createTracking(options) {
|
|
|
1922
2026
|
return {
|
|
1923
2027
|
// Still publish phone config so usePhoneField/<PhoneField> work even when
|
|
1924
2028
|
// tracking is disabled (missing apiKey/endpoint).
|
|
1925
|
-
TrackingProvider: ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2029
|
+
TrackingProvider: ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }),
|
|
1926
2030
|
useTracking: () => noopTyped
|
|
1927
2031
|
};
|
|
1928
2032
|
}
|
|
@@ -1995,7 +2099,7 @@ function createTracking(options) {
|
|
|
1995
2099
|
}
|
|
1996
2100
|
};
|
|
1997
2101
|
}, []);
|
|
1998
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TrackingContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PhoneConfigProvider, { value: phone ?? null, children }) });
|
|
1999
2103
|
}
|
|
2000
2104
|
function useTracking() {
|
|
2001
2105
|
const client = (0, import_react5.useContext)(TrackingContext);
|
|
@@ -2014,9 +2118,11 @@ function createTracking(options) {
|
|
|
2014
2118
|
ConsentBanner,
|
|
2015
2119
|
DEFAULT_PHONE_COUNTRY,
|
|
2016
2120
|
GoogleAdsTracking,
|
|
2017
|
-
|
|
2121
|
+
NAMED_RANGES,
|
|
2018
2122
|
PhoneField,
|
|
2123
|
+
SUPPORTED_CURRENCIES,
|
|
2019
2124
|
TRACKING_PARAM_KEYS,
|
|
2125
|
+
TRACKING_RANGES,
|
|
2020
2126
|
captureTrackingParamsFromLocation,
|
|
2021
2127
|
createSalesClient,
|
|
2022
2128
|
createTracking,
|
|
@@ -2033,6 +2139,11 @@ function createTracking(options) {
|
|
|
2033
2139
|
parsePhone,
|
|
2034
2140
|
phoneField,
|
|
2035
2141
|
resetConsent,
|
|
2142
|
+
saleCreateSchema,
|
|
2143
|
+
saleItemSchema,
|
|
2144
|
+
saleServiceSchema,
|
|
2145
|
+
saleUpdateSchema,
|
|
2146
|
+
salesRequest,
|
|
2036
2147
|
setConsentState,
|
|
2037
2148
|
toE164,
|
|
2038
2149
|
toMinor,
|