@aranova/tracking-react 0.7.2 → 0.9.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/README.md +49 -0
- package/dist/index.d.mts +348 -1
- package/dist/index.d.ts +348 -1
- package/dist/index.js +131 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1398,6 +1398,353 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1398
1398
|
getVisitorId(): string;
|
|
1399
1399
|
}
|
|
1400
1400
|
|
|
1401
|
+
/**
|
|
1402
|
+
* Sales / Conversions wire schemas — the client-side source of truth.
|
|
1403
|
+
*
|
|
1404
|
+
* `saleCreateSchema` is mirrored by `SaleCreateSchema` in
|
|
1405
|
+
* `apps/api/src/schemas/tracking_sales.py` and enforced by the backend drift
|
|
1406
|
+
* test (the `resources` section of `events.schema.json`). Keep them in lockstep.
|
|
1407
|
+
*
|
|
1408
|
+
* Money is **integer minor units (cents)**; `quantity` is a decimal string;
|
|
1409
|
+
* `currency` is the required `SupportedCurrency` enum.
|
|
1410
|
+
*/
|
|
1411
|
+
declare const SUPPORTED_CURRENCIES: readonly ["USD", "CAD"];
|
|
1412
|
+
type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number];
|
|
1413
|
+
declare const TRACKING_ENVIRONMENTS: readonly ["production", "development"];
|
|
1414
|
+
declare const saleItemSchema: z.ZodObject<{
|
|
1415
|
+
external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1416
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1417
|
+
category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1418
|
+
quantity: z.ZodString;
|
|
1419
|
+
unit_price_cents: z.ZodNumber;
|
|
1420
|
+
unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
1421
|
+
}, "strict", z.ZodTypeAny, {
|
|
1422
|
+
quantity: string;
|
|
1423
|
+
unit_price_cents: number;
|
|
1424
|
+
name?: string | null | undefined;
|
|
1425
|
+
external_item_id?: string | null | undefined;
|
|
1426
|
+
category?: string | null | undefined;
|
|
1427
|
+
unit_cost_cents?: number | null | undefined;
|
|
1428
|
+
}, {
|
|
1429
|
+
quantity: string;
|
|
1430
|
+
unit_price_cents: number;
|
|
1431
|
+
name?: string | null | undefined;
|
|
1432
|
+
external_item_id?: string | null | undefined;
|
|
1433
|
+
category?: string | null | undefined;
|
|
1434
|
+
unit_cost_cents?: number | null | undefined;
|
|
1435
|
+
}>;
|
|
1436
|
+
declare const saleCreateSchema: z.ZodObject<{
|
|
1437
|
+
external_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1438
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1439
|
+
service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1440
|
+
currency: z.ZodEnum<["USD", "CAD"]>;
|
|
1441
|
+
amount_total_cents: z.ZodNumber;
|
|
1442
|
+
occurred_at: z.ZodString;
|
|
1443
|
+
environment: z.ZodDefault<z.ZodEnum<["production", "development"]>>;
|
|
1444
|
+
items: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1445
|
+
external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1446
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1447
|
+
category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1448
|
+
quantity: z.ZodString;
|
|
1449
|
+
unit_price_cents: z.ZodNumber;
|
|
1450
|
+
unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
1451
|
+
}, "strict", z.ZodTypeAny, {
|
|
1452
|
+
quantity: string;
|
|
1453
|
+
unit_price_cents: number;
|
|
1454
|
+
name?: string | null | undefined;
|
|
1455
|
+
external_item_id?: string | null | undefined;
|
|
1456
|
+
category?: string | null | undefined;
|
|
1457
|
+
unit_cost_cents?: number | null | undefined;
|
|
1458
|
+
}, {
|
|
1459
|
+
quantity: string;
|
|
1460
|
+
unit_price_cents: number;
|
|
1461
|
+
name?: string | null | undefined;
|
|
1462
|
+
external_item_id?: string | null | undefined;
|
|
1463
|
+
category?: string | null | undefined;
|
|
1464
|
+
unit_cost_cents?: number | null | undefined;
|
|
1465
|
+
}>, "many">>;
|
|
1466
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
1467
|
+
customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1468
|
+
customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1469
|
+
customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1470
|
+
}, "strict", z.ZodTypeAny, {
|
|
1471
|
+
currency: "USD" | "CAD";
|
|
1472
|
+
amount_total_cents: number;
|
|
1473
|
+
occurred_at: string;
|
|
1474
|
+
environment: "production" | "development";
|
|
1475
|
+
items: {
|
|
1476
|
+
quantity: string;
|
|
1477
|
+
unit_price_cents: number;
|
|
1478
|
+
name?: string | null | undefined;
|
|
1479
|
+
external_item_id?: string | null | undefined;
|
|
1480
|
+
category?: string | null | undefined;
|
|
1481
|
+
unit_cost_cents?: number | null | undefined;
|
|
1482
|
+
}[];
|
|
1483
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1484
|
+
external_id?: string | null | undefined;
|
|
1485
|
+
description?: string | null | undefined;
|
|
1486
|
+
service?: string | null | undefined;
|
|
1487
|
+
customer_name?: string | null | undefined;
|
|
1488
|
+
customer_phone?: string | null | undefined;
|
|
1489
|
+
customer_email?: string | null | undefined;
|
|
1490
|
+
}, {
|
|
1491
|
+
currency: "USD" | "CAD";
|
|
1492
|
+
amount_total_cents: number;
|
|
1493
|
+
occurred_at: string;
|
|
1494
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1495
|
+
external_id?: string | null | undefined;
|
|
1496
|
+
description?: string | null | undefined;
|
|
1497
|
+
service?: string | null | undefined;
|
|
1498
|
+
environment?: "production" | "development" | undefined;
|
|
1499
|
+
items?: {
|
|
1500
|
+
quantity: string;
|
|
1501
|
+
unit_price_cents: number;
|
|
1502
|
+
name?: string | null | undefined;
|
|
1503
|
+
external_item_id?: string | null | undefined;
|
|
1504
|
+
category?: string | null | undefined;
|
|
1505
|
+
unit_cost_cents?: number | null | undefined;
|
|
1506
|
+
}[] | undefined;
|
|
1507
|
+
customer_name?: string | null | undefined;
|
|
1508
|
+
customer_phone?: string | null | undefined;
|
|
1509
|
+
customer_email?: string | null | undefined;
|
|
1510
|
+
}>;
|
|
1511
|
+
declare const saleUpdateSchema: z.ZodObject<{
|
|
1512
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1513
|
+
service: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1514
|
+
currency: z.ZodOptional<z.ZodEnum<["USD", "CAD"]>>;
|
|
1515
|
+
amount_total_cents: z.ZodOptional<z.ZodNumber>;
|
|
1516
|
+
occurred_at: z.ZodOptional<z.ZodString>;
|
|
1517
|
+
items: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1518
|
+
external_item_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1519
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1520
|
+
category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1521
|
+
quantity: z.ZodString;
|
|
1522
|
+
unit_price_cents: z.ZodNumber;
|
|
1523
|
+
unit_cost_cents: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
1524
|
+
}, "strict", z.ZodTypeAny, {
|
|
1525
|
+
quantity: string;
|
|
1526
|
+
unit_price_cents: number;
|
|
1527
|
+
name?: string | null | undefined;
|
|
1528
|
+
external_item_id?: string | null | undefined;
|
|
1529
|
+
category?: string | null | undefined;
|
|
1530
|
+
unit_cost_cents?: number | null | undefined;
|
|
1531
|
+
}, {
|
|
1532
|
+
quantity: string;
|
|
1533
|
+
unit_price_cents: number;
|
|
1534
|
+
name?: string | null | undefined;
|
|
1535
|
+
external_item_id?: string | null | undefined;
|
|
1536
|
+
category?: string | null | undefined;
|
|
1537
|
+
unit_cost_cents?: number | null | undefined;
|
|
1538
|
+
}>, "many">>;
|
|
1539
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
1540
|
+
customer_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1541
|
+
customer_phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1542
|
+
customer_email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1543
|
+
}, "strict", z.ZodTypeAny, {
|
|
1544
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1545
|
+
description?: string | null | undefined;
|
|
1546
|
+
service?: string | null | undefined;
|
|
1547
|
+
currency?: "USD" | "CAD" | undefined;
|
|
1548
|
+
amount_total_cents?: number | undefined;
|
|
1549
|
+
occurred_at?: string | undefined;
|
|
1550
|
+
items?: {
|
|
1551
|
+
quantity: string;
|
|
1552
|
+
unit_price_cents: number;
|
|
1553
|
+
name?: string | null | undefined;
|
|
1554
|
+
external_item_id?: string | null | undefined;
|
|
1555
|
+
category?: string | null | undefined;
|
|
1556
|
+
unit_cost_cents?: number | null | undefined;
|
|
1557
|
+
}[] | undefined;
|
|
1558
|
+
customer_name?: string | null | undefined;
|
|
1559
|
+
customer_phone?: string | null | undefined;
|
|
1560
|
+
customer_email?: string | null | undefined;
|
|
1561
|
+
}, {
|
|
1562
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
1563
|
+
description?: string | null | undefined;
|
|
1564
|
+
service?: string | null | undefined;
|
|
1565
|
+
currency?: "USD" | "CAD" | undefined;
|
|
1566
|
+
amount_total_cents?: number | undefined;
|
|
1567
|
+
occurred_at?: string | undefined;
|
|
1568
|
+
items?: {
|
|
1569
|
+
quantity: string;
|
|
1570
|
+
unit_price_cents: number;
|
|
1571
|
+
name?: string | null | undefined;
|
|
1572
|
+
external_item_id?: string | null | undefined;
|
|
1573
|
+
category?: string | null | undefined;
|
|
1574
|
+
unit_cost_cents?: number | null | undefined;
|
|
1575
|
+
}[] | undefined;
|
|
1576
|
+
customer_name?: string | null | undefined;
|
|
1577
|
+
customer_phone?: string | null | undefined;
|
|
1578
|
+
customer_email?: string | null | undefined;
|
|
1579
|
+
}>;
|
|
1580
|
+
type SaleItemInput = z.input<typeof saleItemSchema>;
|
|
1581
|
+
type SaleInput = z.input<typeof saleCreateSchema>;
|
|
1582
|
+
type SaleUpdateInput = z.input<typeof saleUpdateSchema>;
|
|
1583
|
+
interface SaleItem {
|
|
1584
|
+
id: string;
|
|
1585
|
+
external_item_id: string | null;
|
|
1586
|
+
name: string | null;
|
|
1587
|
+
category: string | null;
|
|
1588
|
+
quantity: string;
|
|
1589
|
+
unit_price_cents: number;
|
|
1590
|
+
unit_cost_cents: number | null;
|
|
1591
|
+
}
|
|
1592
|
+
interface Sale {
|
|
1593
|
+
id: string;
|
|
1594
|
+
business_id: string;
|
|
1595
|
+
business_name?: string | null;
|
|
1596
|
+
external_id: string | null;
|
|
1597
|
+
currency: SupportedCurrency;
|
|
1598
|
+
amount_total_cents: number;
|
|
1599
|
+
description: string | null;
|
|
1600
|
+
service_id: string | null;
|
|
1601
|
+
service_key?: string | null;
|
|
1602
|
+
service_label?: string | null;
|
|
1603
|
+
occurred_at: string;
|
|
1604
|
+
environment: (typeof TRACKING_ENVIRONMENTS)[number];
|
|
1605
|
+
metadata: Record<string, unknown> | null;
|
|
1606
|
+
customer_name: string | null;
|
|
1607
|
+
customer_phone: string | null;
|
|
1608
|
+
customer_email: string | null;
|
|
1609
|
+
created_at: string;
|
|
1610
|
+
updated_at: string;
|
|
1611
|
+
items: SaleItem[];
|
|
1612
|
+
}
|
|
1613
|
+
interface SaleListPage {
|
|
1614
|
+
items: Sale[];
|
|
1615
|
+
total: number;
|
|
1616
|
+
}
|
|
1617
|
+
interface SaleCursorPage {
|
|
1618
|
+
items: Sale[];
|
|
1619
|
+
next_cursor: string | null;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Comprehensive filter shape mirrored from the backend's `SaleQueryFilters`.
|
|
1623
|
+
*
|
|
1624
|
+
* `search` runs case-insensitively across `customer_name`, `customer_phone`,
|
|
1625
|
+
* `customer_email`, `description`, and `external_id` — the human-facing
|
|
1626
|
+
* columns. `service_id` is the resolved per-business service UUID (different
|
|
1627
|
+
* from the create-time `service` *key*).
|
|
1628
|
+
*/
|
|
1629
|
+
interface SaleFilters {
|
|
1630
|
+
business_id?: string;
|
|
1631
|
+
external_id?: string;
|
|
1632
|
+
service_id?: string;
|
|
1633
|
+
currency?: SupportedCurrency;
|
|
1634
|
+
environment?: (typeof TRACKING_ENVIRONMENTS)[number];
|
|
1635
|
+
since?: string;
|
|
1636
|
+
until?: string;
|
|
1637
|
+
min_amount_cents?: number;
|
|
1638
|
+
max_amount_cents?: number;
|
|
1639
|
+
search?: string;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Full query input for `SalesClient.list()` — filters + pagination.
|
|
1643
|
+
*
|
|
1644
|
+
* Pagination is **keyset (cursor)**: `next_cursor` returned by one page is
|
|
1645
|
+
* passed back as `cursor` on the next. `null` / undefined cursor = first page.
|
|
1646
|
+
*
|
|
1647
|
+
* Ordering on this endpoint is fixed at **`occurred_at DESC, id DESC`** — the
|
|
1648
|
+
* cursor encodes a position in that index, so a different sort would
|
|
1649
|
+
* invalidate cursors mid-pagination. For ad-hoc sorted reads use the
|
|
1650
|
+
* dashboard admin endpoint, which is offset-paginated.
|
|
1651
|
+
*/
|
|
1652
|
+
interface SaleListQuery extends SaleFilters {
|
|
1653
|
+
limit?: number;
|
|
1654
|
+
cursor?: string | null;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/** Shared config for every sales HTTP helper. */
|
|
1658
|
+
interface SalesTransportConfig {
|
|
1659
|
+
/** Public (`aranv_pk_…`) or secret (`aranv_sk_…`) API key. */
|
|
1660
|
+
apiKey: string;
|
|
1661
|
+
/**
|
|
1662
|
+
* Base tracking endpoint, e.g. `https://aranovainternal-production.up.railway.app/tracking`.
|
|
1663
|
+
* The `/sales` path is appended by the helpers.
|
|
1664
|
+
*/
|
|
1665
|
+
endpoint: string;
|
|
1666
|
+
/** Optional SDK identity headers (mirrors the event ingest client). */
|
|
1667
|
+
sdkVersion?: string;
|
|
1668
|
+
packageName?: string;
|
|
1669
|
+
surface?: string;
|
|
1670
|
+
environment?: string;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/** Config for {@link createSalesClient}. */
|
|
1674
|
+
interface SalesClientConfig extends SalesTransportConfig {
|
|
1675
|
+
/** Applied when an individual `record()` call omits `currency`. */
|
|
1676
|
+
defaultCurrency?: SupportedCurrency;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* One isomorphic sales client — what a key may *do* is enforced by the backend,
|
|
1680
|
+
* not by hiding methods. A **public** key (`aranv_pk_…`) may `record` (the
|
|
1681
|
+
* backend rejects reads/CRUD from it with a `403`); a **secret** key
|
|
1682
|
+
* (`aranv_sk_…`), used **server-side only**, gets full read/list/update/delete.
|
|
1683
|
+
* Never ship a secret key in a browser bundle.
|
|
1684
|
+
*
|
|
1685
|
+
* Generic over the service-key union `TService`: bind the type emitted by
|
|
1686
|
+
* `@aranova/tracking-cli gen` for compile-time-checked `service` values.
|
|
1687
|
+
*/
|
|
1688
|
+
interface SalesClient<TService extends string = string> {
|
|
1689
|
+
record(input: Omit<SaleInput, 'currency' | 'occurred_at' | 'service'> & {
|
|
1690
|
+
service?: TService | null;
|
|
1691
|
+
currency?: SupportedCurrency;
|
|
1692
|
+
occurred_at?: string;
|
|
1693
|
+
}): Promise<Sale>;
|
|
1694
|
+
list(query?: SaleListQuery): Promise<SaleCursorPage>;
|
|
1695
|
+
get(id: string): Promise<Sale>;
|
|
1696
|
+
update(id: string, patch: Omit<SaleUpdateInput, 'service'> & {
|
|
1697
|
+
service?: TService | null;
|
|
1698
|
+
}): Promise<Sale>;
|
|
1699
|
+
delete(id: string): Promise<void>;
|
|
1700
|
+
}
|
|
1701
|
+
declare function createSalesClient<TService extends string = string>(config: SalesClientConfig): SalesClient<TService>;
|
|
1702
|
+
|
|
1703
|
+
/** A business's active service, as returned by `GET /tracking/services`. */
|
|
1704
|
+
interface PublicServiceItem {
|
|
1705
|
+
key: string;
|
|
1706
|
+
label: string;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Fetch the caller's business's active service taxonomy. Accepts a public or
|
|
1710
|
+
* secret key (the taxonomy is low-sensitivity category names). Powers the
|
|
1711
|
+
* `@aranova/tracking-cli gen` codegen.
|
|
1712
|
+
*/
|
|
1713
|
+
declare function fetchServices(config: SalesTransportConfig): Promise<PublicServiceItem[]>;
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* Convert a major amount (dollars `250.5`) to integer minor units (`25050`).
|
|
1717
|
+
*
|
|
1718
|
+
* Convenience only — the wire is always integer cents. Uses float multiply +
|
|
1719
|
+
* `Math.round`, so values that aren't exactly representable in binary float
|
|
1720
|
+
* (e.g. `1.005`) can round to the neighbouring cent. If you already hold an
|
|
1721
|
+
* exact cents integer, pass it straight through and skip this helper.
|
|
1722
|
+
*/
|
|
1723
|
+
declare function toMinor(amount: number, currency: SupportedCurrency): number;
|
|
1724
|
+
/** Convert integer minor units (`25050`) to a major amount (`250.5`). */
|
|
1725
|
+
declare function fromMinor(cents: number, currency: SupportedCurrency): number;
|
|
1726
|
+
/**
|
|
1727
|
+
* Format integer minor units as a localized currency string (e.g. `"$250.50"`).
|
|
1728
|
+
* Uses the built-in `Intl.NumberFormat` — no extra dependency.
|
|
1729
|
+
*/
|
|
1730
|
+
declare function formatMoney(cents: number, currency: SupportedCurrency, locale?: string): string;
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Error thrown by the sales client (`createSalesClient`) on a
|
|
1734
|
+
* non-2xx response. Unlike the fire-and-forget event queue (which swallows
|
|
1735
|
+
* failures), a sale is a transaction the caller must be able to react to.
|
|
1736
|
+
*/
|
|
1737
|
+
declare class AranovaApiError extends Error {
|
|
1738
|
+
readonly status: number;
|
|
1739
|
+
readonly code: string | undefined;
|
|
1740
|
+
readonly requestId: string | undefined;
|
|
1741
|
+
constructor(message: string, options: {
|
|
1742
|
+
status: number;
|
|
1743
|
+
code?: string;
|
|
1744
|
+
requestId?: string;
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1401
1748
|
/**
|
|
1402
1749
|
* Props for the Google Ads tracking component.
|
|
1403
1750
|
*
|
|
@@ -1506,4 +1853,4 @@ interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
|
|
|
1506
1853
|
}
|
|
1507
1854
|
declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
|
|
1508
1855
|
|
|
1509
|
-
export { type AutomaticEventName, ConsentBanner, type ConsentState, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, type EventConfig, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, type FormSubmitConfig, type FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, type JsonValue, type ManualEventName, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, type PhoneClickConfig, type PhoneClickMetadata, type RegisteredAutomaticEvents, type RegisteredManualEvents, type ScrollDepthConfig, type ScrollDepthMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackingClient, type TrackingClientContext, type TrackingEventCreatePayload, type TrackingInitConfig, type TrackingInstallSurface, type TrackingParams, type TrackingProviderProps, type TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, getConsentState, setConsentState, useConsentState, useGclid, useTrackingParams };
|
|
1856
|
+
export { AranovaApiError, type AutomaticEventName, ConsentBanner, type ConsentState, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, type EventConfig, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, type FormSubmitConfig, type FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, type JsonValue, type ManualEventName, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, type PhoneClickConfig, type PhoneClickMetadata, type PublicServiceItem, type RegisteredAutomaticEvents, type RegisteredManualEvents, type Sale, type SaleCursorPage, type SaleInput, type SaleItem, type SaleItemInput, type SaleListPage, type SaleListQuery, type SaleUpdateInput, type SalesClient, type SalesClientConfig, type SalesTransportConfig, type ScrollDepthConfig, type ScrollDepthMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, type SupportedCurrency, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackingClient, type TrackingClientContext, type TrackingEventCreatePayload, type TrackingInitConfig, type TrackingInstallSurface, type TrackingParams, type TrackingProviderProps, type TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createSalesClient, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, fetchServices, formatMoney, fromMinor, getConsentState, setConsentState, toMinor, useConsentState, useGclid, useTrackingParams };
|
package/dist/index.js
CHANGED
|
@@ -20,16 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
AranovaApiError: () => AranovaApiError,
|
|
23
24
|
ConsentBanner: () => ConsentBanner,
|
|
24
25
|
GoogleAdsTracking: () => GoogleAdsTracking,
|
|
25
26
|
TRACKING_PARAM_KEYS: () => TRACKING_PARAM_KEYS,
|
|
26
27
|
captureTrackingParamsFromLocation: () => captureTrackingParamsFromLocation,
|
|
28
|
+
createSalesClient: () => createSalesClient,
|
|
27
29
|
createTracking: () => createTracking,
|
|
28
30
|
createTrackingClientContext: () => createTrackingClientContext,
|
|
29
31
|
createTrackingEventCreatePayload: () => createTrackingEventCreatePayload,
|
|
30
32
|
createTrackingSessionUpsertPayload: () => createTrackingSessionUpsertPayload,
|
|
33
|
+
fetchServices: () => fetchServices,
|
|
34
|
+
formatMoney: () => formatMoney,
|
|
35
|
+
fromMinor: () => fromMinor,
|
|
31
36
|
getConsentState: () => getConsentState,
|
|
32
37
|
setConsentState: () => setConsentState,
|
|
38
|
+
toMinor: () => toMinor,
|
|
33
39
|
useConsentState: () => useConsentState,
|
|
34
40
|
useGclid: () => useGclid,
|
|
35
41
|
useTrackingParams: () => useTrackingParams
|
|
@@ -584,7 +590,7 @@ function createTrackingClient(config) {
|
|
|
584
590
|
const activeGtagIds = config.activeGtagIds ?? null;
|
|
585
591
|
const endpointBase = config.endpoint.replace(/\/$/, "");
|
|
586
592
|
const eventsUrl = `${endpointBase}/events`;
|
|
587
|
-
const
|
|
593
|
+
const identityHeaders2 = {
|
|
588
594
|
sdkVersion: sdkVersion ?? "",
|
|
589
595
|
packageName: packageName ?? "",
|
|
590
596
|
surface: config.surface,
|
|
@@ -665,7 +671,7 @@ function createTrackingClient(config) {
|
|
|
665
671
|
events
|
|
666
672
|
};
|
|
667
673
|
const serialized = JSON.stringify(body);
|
|
668
|
-
await postWithFetch(eventsUrl, serialized, config.apiKey,
|
|
674
|
+
await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, false);
|
|
669
675
|
}
|
|
670
676
|
function trackEvent(input) {
|
|
671
677
|
if (destroyed)
|
|
@@ -696,7 +702,7 @@ function createTrackingClient(config) {
|
|
|
696
702
|
events
|
|
697
703
|
};
|
|
698
704
|
const serialized = JSON.stringify(body);
|
|
699
|
-
void postWithFetch(eventsUrl, serialized, config.apiKey,
|
|
705
|
+
void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders2, true);
|
|
700
706
|
}
|
|
701
707
|
if (typeof window !== "undefined") {
|
|
702
708
|
window.addEventListener("pagehide", flushOnUnload);
|
|
@@ -1291,6 +1297,121 @@ function attachFormStart(client, config) {
|
|
|
1291
1297
|
};
|
|
1292
1298
|
}
|
|
1293
1299
|
|
|
1300
|
+
// ../tracking-core/src/resources/sales/errors.ts
|
|
1301
|
+
var AranovaApiError = class extends Error {
|
|
1302
|
+
constructor(message, options) {
|
|
1303
|
+
super(message);
|
|
1304
|
+
this.name = "AranovaApiError";
|
|
1305
|
+
this.status = options.status;
|
|
1306
|
+
this.code = options.code;
|
|
1307
|
+
this.requestId = options.requestId;
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
// ../tracking-core/src/resources/sales/transport.ts
|
|
1312
|
+
function identityHeaders(config) {
|
|
1313
|
+
const headers = { [API_KEY_HEADER]: config.apiKey };
|
|
1314
|
+
if (config.sdkVersion) headers[SDK_VERSION_HEADER] = config.sdkVersion;
|
|
1315
|
+
if (config.packageName) headers[SDK_PACKAGE_HEADER] = config.packageName;
|
|
1316
|
+
if (config.surface) headers[SDK_SURFACE_HEADER] = config.surface;
|
|
1317
|
+
if (config.environment) headers[SDK_ENVIRONMENT_HEADER] = config.environment;
|
|
1318
|
+
return headers;
|
|
1319
|
+
}
|
|
1320
|
+
function joinUrl(endpoint, path) {
|
|
1321
|
+
return `${endpoint.replace(/\/$/, "")}${path}`;
|
|
1322
|
+
}
|
|
1323
|
+
async function salesRequest(config, method, path, body) {
|
|
1324
|
+
const headers = identityHeaders(config);
|
|
1325
|
+
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
1326
|
+
const response = await fetch(joinUrl(config.endpoint, path), {
|
|
1327
|
+
method,
|
|
1328
|
+
headers,
|
|
1329
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
1330
|
+
});
|
|
1331
|
+
if (!response.ok) {
|
|
1332
|
+
let detail;
|
|
1333
|
+
let code;
|
|
1334
|
+
try {
|
|
1335
|
+
const parsed = await response.json();
|
|
1336
|
+
if (parsed && typeof parsed === "object") {
|
|
1337
|
+
const record = parsed;
|
|
1338
|
+
if (typeof record.detail === "string") detail = record.detail;
|
|
1339
|
+
if (typeof record.code === "string") code = record.code;
|
|
1340
|
+
}
|
|
1341
|
+
} catch {
|
|
1342
|
+
}
|
|
1343
|
+
throw new AranovaApiError(detail ?? response.statusText ?? "Request failed", {
|
|
1344
|
+
status: response.status,
|
|
1345
|
+
code,
|
|
1346
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
if (response.status === 204) return void 0;
|
|
1350
|
+
return await response.json();
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// ../tracking-core/src/resources/sales/client.ts
|
|
1354
|
+
function createSalesClient(config) {
|
|
1355
|
+
return {
|
|
1356
|
+
async record(input) {
|
|
1357
|
+
const currency = input.currency ?? config.defaultCurrency;
|
|
1358
|
+
if (!currency) {
|
|
1359
|
+
throw new Error(
|
|
1360
|
+
"record: `currency` is required (pass it on the sale or set config.defaultCurrency)"
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
const body = {
|
|
1364
|
+
...input,
|
|
1365
|
+
currency,
|
|
1366
|
+
occurred_at: input.occurred_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1367
|
+
};
|
|
1368
|
+
return salesRequest(config, "POST", "/sales", body);
|
|
1369
|
+
},
|
|
1370
|
+
async list(query) {
|
|
1371
|
+
const { cursor, limit, ...filters } = query ?? {};
|
|
1372
|
+
return salesRequest(config, "POST", "/sales/query", {
|
|
1373
|
+
filters,
|
|
1374
|
+
...limit !== void 0 ? { limit } : {},
|
|
1375
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
1376
|
+
});
|
|
1377
|
+
},
|
|
1378
|
+
async get(id) {
|
|
1379
|
+
return salesRequest(config, "GET", `/sales/${id}`);
|
|
1380
|
+
},
|
|
1381
|
+
async update(id, patch) {
|
|
1382
|
+
return salesRequest(config, "PATCH", `/sales/${id}`, patch);
|
|
1383
|
+
},
|
|
1384
|
+
async delete(id) {
|
|
1385
|
+
await salesRequest(config, "DELETE", `/sales/${id}`);
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// ../tracking-core/src/resources/services.ts
|
|
1391
|
+
async function fetchServices(config) {
|
|
1392
|
+
return salesRequest(config, "GET", "/services");
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// ../tracking-core/src/resources/sales/money.ts
|
|
1396
|
+
var MINOR_UNIT_EXPONENT = {
|
|
1397
|
+
USD: 2,
|
|
1398
|
+
CAD: 2
|
|
1399
|
+
};
|
|
1400
|
+
function exponentFor(currency) {
|
|
1401
|
+
return MINOR_UNIT_EXPONENT[currency] ?? 2;
|
|
1402
|
+
}
|
|
1403
|
+
function toMinor(amount, currency) {
|
|
1404
|
+
return Math.round(amount * 10 ** exponentFor(currency));
|
|
1405
|
+
}
|
|
1406
|
+
function fromMinor(cents, currency) {
|
|
1407
|
+
return cents / 10 ** exponentFor(currency);
|
|
1408
|
+
}
|
|
1409
|
+
function formatMoney(cents, currency, locale) {
|
|
1410
|
+
return new Intl.NumberFormat(locale, { style: "currency", currency }).format(
|
|
1411
|
+
fromMinor(cents, currency)
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1294
1415
|
// src/ConsentBanner.tsx
|
|
1295
1416
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1296
1417
|
function ConsentBanner() {
|
|
@@ -1389,7 +1510,7 @@ function useConsentState() {
|
|
|
1389
1510
|
var import_react4 = require("react");
|
|
1390
1511
|
|
|
1391
1512
|
// package.json
|
|
1392
|
-
var version = "0.
|
|
1513
|
+
var version = "0.9.0";
|
|
1393
1514
|
|
|
1394
1515
|
// src/factory.tsx
|
|
1395
1516
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -1499,16 +1620,22 @@ function createTracking(options) {
|
|
|
1499
1620
|
}
|
|
1500
1621
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1501
1622
|
0 && (module.exports = {
|
|
1623
|
+
AranovaApiError,
|
|
1502
1624
|
ConsentBanner,
|
|
1503
1625
|
GoogleAdsTracking,
|
|
1504
1626
|
TRACKING_PARAM_KEYS,
|
|
1505
1627
|
captureTrackingParamsFromLocation,
|
|
1628
|
+
createSalesClient,
|
|
1506
1629
|
createTracking,
|
|
1507
1630
|
createTrackingClientContext,
|
|
1508
1631
|
createTrackingEventCreatePayload,
|
|
1509
1632
|
createTrackingSessionUpsertPayload,
|
|
1633
|
+
fetchServices,
|
|
1634
|
+
formatMoney,
|
|
1635
|
+
fromMinor,
|
|
1510
1636
|
getConsentState,
|
|
1511
1637
|
setConsentState,
|
|
1638
|
+
toMinor,
|
|
1512
1639
|
useConsentState,
|
|
1513
1640
|
useGclid,
|
|
1514
1641
|
useTrackingParams
|