@tagadapay/headless-sdk 1.14.1 → 1.17.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/core/client.d.ts +12 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +16 -4
- package/dist/core/client.js.map +1 -1
- package/dist/core/http.d.ts +2 -0
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +21 -5
- package/dist/core/http.js.map +1 -1
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/modules/checkout.d.ts +5 -1
- package/dist/core/modules/checkout.d.ts.map +1 -1
- package/dist/core/modules/checkout.js +22 -1
- package/dist/core/modules/checkout.js.map +1 -1
- package/dist/core/modules/commerce.d.ts +4 -0
- package/dist/core/modules/commerce.d.ts.map +1 -0
- package/dist/core/modules/commerce.js +5 -0
- package/dist/core/modules/commerce.js.map +1 -0
- package/dist/core/modules/customer.d.ts +47 -1
- package/dist/core/modules/customer.d.ts.map +1 -1
- package/dist/core/modules/customer.js +60 -3
- package/dist/core/modules/customer.js.map +1 -1
- package/dist/core/modules/experiments.d.ts +21 -0
- package/dist/core/modules/experiments.d.ts.map +1 -0
- package/dist/core/modules/experiments.js +85 -0
- package/dist/core/modules/experiments.js.map +1 -0
- package/dist/core/modules/funnel.d.ts +2 -1
- package/dist/core/modules/funnel.d.ts.map +1 -1
- package/dist/core/modules/funnel.js +6 -1
- package/dist/core/modules/funnel.js.map +1 -1
- package/dist/core/modules/lazyCommerce.d.ts +16 -0
- package/dist/core/modules/lazyCommerce.d.ts.map +1 -0
- package/dist/core/modules/lazyCommerce.js +20 -0
- package/dist/core/modules/lazyCommerce.js.map +1 -0
- package/dist/core/modules/offers.d.ts +30 -5
- package/dist/core/modules/offers.d.ts.map +1 -1
- package/dist/core/modules/offers.js +66 -7
- package/dist/core/modules/offers.js.map +1 -1
- package/dist/core/modules/payment.d.ts +19 -1
- package/dist/core/modules/payment.d.ts.map +1 -1
- package/dist/core/modules/payment.js +42 -3
- package/dist/core/modules/payment.js.map +1 -1
- package/dist/core/modules/portal/index.d.ts +102 -0
- package/dist/core/modules/portal/index.d.ts.map +1 -0
- package/dist/core/modules/portal/index.js +166 -0
- package/dist/core/modules/portal/index.js.map +1 -0
- package/dist/core/modules/portal/types.d.ts +617 -0
- package/dist/core/modules/portal/types.d.ts.map +1 -0
- package/dist/core/modules/portal/types.js +11 -0
- package/dist/core/modules/portal/types.js.map +1 -0
- package/dist/core/modules/rx.d.ts +32 -1
- package/dist/core/modules/rx.d.ts.map +1 -1
- package/dist/core/modules/rx.js +17 -1
- package/dist/core/modules/rx.js.map +1 -1
- package/dist/core/modules/track.d.ts +135 -0
- package/dist/core/modules/track.d.ts.map +1 -0
- package/dist/core/modules/track.js +412 -0
- package/dist/core/modules/track.js.map +1 -0
- package/dist/core/types.d.ts +13 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -3
- package/dist/core/types.js.map +1 -1
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +4 -0
- package/dist/core/version.js.map +1 -0
- package/dist/pixels/engine.d.ts +56 -0
- package/dist/pixels/engine.d.ts.map +1 -0
- package/dist/pixels/engine.js +263 -0
- package/dist/pixels/engine.js.map +1 -0
- package/dist/pixels/index.d.ts +10 -0
- package/dist/pixels/index.d.ts.map +1 -0
- package/dist/pixels/index.js +5 -0
- package/dist/pixels/index.js.map +1 -0
- package/dist/pixels/metaEventId.d.ts +15 -0
- package/dist/pixels/metaEventId.d.ts.map +1 -0
- package/dist/pixels/metaEventId.js +17 -0
- package/dist/pixels/metaEventId.js.map +1 -0
- package/dist/pixels/pixelIdentity.d.ts +34 -0
- package/dist/pixels/pixelIdentity.d.ts.map +1 -0
- package/dist/pixels/pixelIdentity.js +65 -0
- package/dist/pixels/pixelIdentity.js.map +1 -0
- package/dist/pixels/pixelMapping.d.ts +172 -0
- package/dist/pixels/pixelMapping.d.ts.map +1 -0
- package/dist/pixels/pixelMapping.js +574 -0
- package/dist/pixels/pixelMapping.js.map +1 -0
- package/dist/pixels/pixelTracker.d.ts +81 -0
- package/dist/pixels/pixelTracker.d.ts.map +1 -0
- package/dist/pixels/pixelTracker.js +797 -0
- package/dist/pixels/pixelTracker.js.map +1 -0
- package/dist/pixels/types.d.ts +103 -0
- package/dist/pixels/types.d.ts.map +1 -0
- package/dist/pixels/types.js +14 -0
- package/dist/pixels/types.js.map +1 -0
- package/dist/react/hooks/useStep.d.ts +7 -0
- package/dist/react/hooks/useStep.d.ts.map +1 -0
- package/dist/react/hooks/useStep.js +14 -0
- package/dist/react/hooks/useStep.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/stripe/index.d.ts +3 -1
- package/dist/stripe/index.d.ts.map +1 -1
- package/dist/stripe/index.js +13 -6
- package/dist/stripe/index.js.map +1 -1
- package/dist/stripe/useStripeExpress.d.ts.map +1 -1
- package/dist/stripe/useStripeExpress.js +15 -1
- package/dist/stripe/useStripeExpress.js.map +1 -1
- package/dist/tagada-headless-commerce.min.js +8 -0
- package/dist/tagada-headless-commerce.min.js.map +7 -0
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +4 -4
- package/dist/tagada-headless.js +722 -288
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +4 -4
- package/dist/tagada-pixels.min.js +7 -0
- package/dist/tagada-pixels.min.js.map +7 -0
- package/dist/tgd/contract/attribution.d.ts +28 -0
- package/dist/tgd/contract/attribution.d.ts.map +1 -0
- package/dist/tgd/contract/attribution.js +44 -0
- package/dist/tgd/contract/attribution.js.map +1 -0
- package/dist/tgd/contract/browser-api.d.ts +57 -0
- package/dist/tgd/contract/browser-api.d.ts.map +1 -0
- package/dist/tgd/contract/browser-api.js +2 -0
- package/dist/tgd/contract/browser-api.js.map +1 -0
- package/dist/tgd/contract/canvas.d.ts +120 -0
- package/dist/tgd/contract/canvas.d.ts.map +1 -0
- package/dist/tgd/contract/canvas.js +12 -0
- package/dist/tgd/contract/canvas.js.map +1 -0
- package/dist/tgd/contract/dedup-keys.d.ts +24 -0
- package/dist/tgd/contract/dedup-keys.d.ts.map +1 -0
- package/dist/tgd/contract/dedup-keys.js +23 -0
- package/dist/tgd/contract/dedup-keys.js.map +1 -0
- package/dist/tgd/contract/destination-names.d.ts +4 -0
- package/dist/tgd/contract/destination-names.d.ts.map +1 -0
- package/dist/tgd/contract/destination-names.js +66 -0
- package/dist/tgd/contract/destination-names.js.map +1 -0
- package/dist/tgd/contract/destinations.d.ts +124 -0
- package/dist/tgd/contract/destinations.d.ts.map +1 -0
- package/dist/tgd/contract/destinations.js +63 -0
- package/dist/tgd/contract/destinations.js.map +1 -0
- package/dist/tgd/contract/envelope.d.ts +203 -0
- package/dist/tgd/contract/envelope.d.ts.map +1 -0
- package/dist/tgd/contract/envelope.js +103 -0
- package/dist/tgd/contract/envelope.js.map +1 -0
- package/dist/tgd/contract/experiments.d.ts +87 -0
- package/dist/tgd/contract/experiments.d.ts.map +1 -0
- package/dist/tgd/contract/experiments.js +2 -0
- package/dist/tgd/contract/experiments.js.map +1 -0
- package/dist/tgd/contract/index.d.ts +20 -0
- package/dist/tgd/contract/index.d.ts.map +1 -0
- package/dist/tgd/contract/index.js +20 -0
- package/dist/tgd/contract/index.js.map +1 -0
- package/dist/tgd/contract/is-test.d.ts +2 -0
- package/dist/tgd/contract/is-test.d.ts.map +1 -0
- package/dist/tgd/contract/is-test.js +3 -0
- package/dist/tgd/contract/is-test.js.map +1 -0
- package/dist/tgd/contract/junk-ids.d.ts +4 -0
- package/dist/tgd/contract/junk-ids.d.ts.map +1 -0
- package/dist/tgd/contract/junk-ids.js +7 -0
- package/dist/tgd/contract/junk-ids.js.map +1 -0
- package/dist/tgd/contract/limits.d.ts +19 -0
- package/dist/tgd/contract/limits.d.ts.map +1 -0
- package/dist/tgd/contract/limits.js +20 -0
- package/dist/tgd/contract/limits.js.map +1 -0
- package/dist/tgd/contract/names.d.ts +13 -0
- package/dist/tgd/contract/names.d.ts.map +1 -0
- package/dist/tgd/contract/names.js +15 -0
- package/dist/tgd/contract/names.js.map +1 -0
- package/dist/tgd/contract/registry.d.ts +116 -0
- package/dist/tgd/contract/registry.d.ts.map +1 -0
- package/dist/tgd/contract/registry.js +59 -0
- package/dist/tgd/contract/registry.js.map +1 -0
- package/dist/tgd/contract/signed-ids.d.ts +33 -0
- package/dist/tgd/contract/signed-ids.d.ts.map +1 -0
- package/dist/tgd/contract/signed-ids.js +26 -0
- package/dist/tgd/contract/signed-ids.js.map +1 -0
- package/dist/tgd/contract/snapshots.d.ts +69 -0
- package/dist/tgd/contract/snapshots.d.ts.map +1 -0
- package/dist/tgd/contract/snapshots.js +2 -0
- package/dist/tgd/contract/snapshots.js.map +1 -0
- package/dist/tgd/contract/time.d.ts +9 -0
- package/dist/tgd/contract/time.d.ts.map +1 -0
- package/dist/tgd/contract/time.js +9 -0
- package/dist/tgd/contract/time.js.map +1 -0
- package/dist/tgd/contract/unions.d.ts +21 -0
- package/dist/tgd/contract/unions.d.ts.map +1 -0
- package/dist/tgd/contract/unions.js +17 -0
- package/dist/tgd/contract/unions.js.map +1 -0
- package/dist/tgd/contract/unit.d.ts +12 -0
- package/dist/tgd/contract/unit.d.ts.map +1 -0
- package/dist/tgd/contract/unit.js +18 -0
- package/dist/tgd/contract/unit.js.map +1 -0
- package/dist/tgd/contract/wire.d.ts +59 -0
- package/dist/tgd/contract/wire.d.ts.map +1 -0
- package/dist/tgd/contract/wire.js +2 -0
- package/dist/tgd/contract/wire.js.map +1 -0
- package/package.json +8 -1
|
@@ -123,9 +123,40 @@ export interface RxCaseSummary {
|
|
|
123
123
|
lastShipmentShippedAt: string | null;
|
|
124
124
|
createdAt: string;
|
|
125
125
|
}
|
|
126
|
+
export type RxActivationStepKey = 'application' | 'approval' | 'payouts' | 'statement_descriptor' | 'storefront';
|
|
127
|
+
export type RxActivationMissingItem = 'application' | 'approval' | 'payout_kyc' | 'payout_bank_account' | 'statement_descriptor' | 'statement_descriptor_rejected' | 'storefront' | 'partner_rx_option';
|
|
128
|
+
/**
|
|
129
|
+
* Tagada Rx activation status of a store.
|
|
130
|
+
*
|
|
131
|
+
* `payments` is `'ready'` once the brand's Rx payment account is live and its
|
|
132
|
+
* payment flow is bound; `'setting_up'` before. It is a status, not a step:
|
|
133
|
+
* there is nothing for the brand to do while payments are being set up.
|
|
134
|
+
* The public storefront route leaves out payout verification and partner
|
|
135
|
+
* contract items (`payouts`, `payout_*`, `partner_rx_option`).
|
|
136
|
+
*/
|
|
137
|
+
export interface RxActivationStatus {
|
|
138
|
+
storeId: string;
|
|
139
|
+
state: 'not_requested' | 'pending_review' | 'active';
|
|
140
|
+
steps: {
|
|
141
|
+
key: RxActivationStepKey;
|
|
142
|
+
done: boolean;
|
|
143
|
+
}[];
|
|
144
|
+
missing: RxActivationMissingItem[];
|
|
145
|
+
payments: 'setting_up' | 'ready';
|
|
146
|
+
descriptorStatus: 'none' | 'pending' | 'approved' | 'rejected';
|
|
147
|
+
}
|
|
126
148
|
export declare class RxModule {
|
|
127
149
|
private readonly http;
|
|
128
|
-
|
|
150
|
+
private readonly storeId?;
|
|
151
|
+
constructor(http: HttpClient, storeId?: string | undefined);
|
|
152
|
+
/**
|
|
153
|
+
* Activation status of the store: steps, missing items and whether Rx
|
|
154
|
+
* payments are `setting_up` or `ready`. Storefronts use it to show
|
|
155
|
+
* "Payments are being set up" instead of letting a checkout fail.
|
|
156
|
+
*
|
|
157
|
+
* Read-only / public. Defaults to the client's `storeId`.
|
|
158
|
+
*/
|
|
159
|
+
getActivationStatus(storeId?: string): Promise<RxActivationStatus>;
|
|
129
160
|
/**
|
|
130
161
|
* Check whether a product requires an Rx case. Storefronts call this
|
|
131
162
|
* before rendering the intake form so they only ask the patient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx.d.ts","sourceRoot":"","sources":["../../../src/core/modules/rx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,GACV,SAAS,GACT,WAAW,GACX,UAAU,GACV,WAAW,GACX,OAAO,CAAC;AAEZ,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,OAAO,CAAC;IACtB,sBAAsB,EAAE,OAAO,CAAC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,2BAA2B;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,aAAa,CAAC;IAC9C,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,uCAAuC;QACvC,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAA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IAShC;;;;OAIG;IACG,gBAAgB,CAAC,KAAK,EAAE;QAC5B,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;IAOvC;;;;OAIG;IACG,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIvE;;;OAGG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,CAAC;CAKlC"}
|
package/dist/core/modules/rx.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
export class RxModule {
|
|
2
|
-
constructor(http) {
|
|
2
|
+
constructor(http, storeId) {
|
|
3
3
|
this.http = http;
|
|
4
|
+
this.storeId = storeId;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Activation status of the store: steps, missing items and whether Rx
|
|
8
|
+
* payments are `setting_up` or `ready`. Storefronts use it to show
|
|
9
|
+
* "Payments are being set up" instead of letting a checkout fail.
|
|
10
|
+
*
|
|
11
|
+
* Read-only / public. Defaults to the client's `storeId`.
|
|
12
|
+
*/
|
|
13
|
+
async getActivationStatus(storeId) {
|
|
14
|
+
const id = storeId ?? this.storeId;
|
|
15
|
+
if (!id)
|
|
16
|
+
throw new Error('rx.getActivationStatus: storeId is required');
|
|
17
|
+
return this.http.get('/api/public/v1/rx/activation-status', {
|
|
18
|
+
params: { storeId: id },
|
|
19
|
+
});
|
|
4
20
|
}
|
|
5
21
|
/**
|
|
6
22
|
* Check whether a product requires an Rx case. Storefronts call this
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx.js","sourceRoot":"","sources":["../../../src/core/modules/rx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rx.js","sourceRoot":"","sources":["../../../src/core/modules/rx.ts"],"names":[],"mapp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E;SAC7D,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `track` capability: the merchant's coded funnel reports its steps and events,
|
|
3
|
+
* and the browser pixels bound on the canvas fire from here.
|
|
4
|
+
*
|
|
5
|
+
* Three rules hold this file together:
|
|
6
|
+
* - the constructor assigns fields and nothing else (the React provider builds the
|
|
7
|
+
* client inside a `useMemo` that also runs during SSR);
|
|
8
|
+
* - every public method returns at once without a `window`;
|
|
9
|
+
* - everything automatic is gated on an opt-in flag that only `step()` writes, so a
|
|
10
|
+
* site that upgrades and never calls `track.step()` makes zero new request.
|
|
11
|
+
*/
|
|
12
|
+
import type { TgdBootstrap, TgdPublicApi } from '../../tgd/contract/index.js';
|
|
13
|
+
import type { CheckoutLineItem } from '../types.js';
|
|
14
|
+
import { SDK_NAME, SDK_VERSION } from '../version.js';
|
|
15
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
16
|
+
[key: string]: JsonValue;
|
|
17
|
+
};
|
|
18
|
+
export interface StepData {
|
|
19
|
+
/** Overrides `location.pathname` for display and for the dedup key. */
|
|
20
|
+
path?: string;
|
|
21
|
+
props?: Record<string, JsonValue>;
|
|
22
|
+
}
|
|
23
|
+
export type EventData = Record<string, JsonValue>;
|
|
24
|
+
export interface TrackIdentity {
|
|
25
|
+
email?: string;
|
|
26
|
+
phone?: string;
|
|
27
|
+
customerId?: string;
|
|
28
|
+
}
|
|
29
|
+
/** One cart line, as the pixel mappers read it. Amounts stay in MINOR units. */
|
|
30
|
+
export interface PixelContent {
|
|
31
|
+
id: string;
|
|
32
|
+
quantity: number;
|
|
33
|
+
item_price?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface TrackSignalNote {
|
|
36
|
+
signal: string;
|
|
37
|
+
value: string;
|
|
38
|
+
detail?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/** A local view: what this page loaded and what it could not do. No server call of its own. */
|
|
41
|
+
export interface TrackHealth {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
storeId: string;
|
|
44
|
+
funnelKey: string;
|
|
45
|
+
sdk: {
|
|
46
|
+
name: typeof SDK_NAME;
|
|
47
|
+
version: typeof SDK_VERSION;
|
|
48
|
+
};
|
|
49
|
+
manifestHash: string | null;
|
|
50
|
+
pixels: {
|
|
51
|
+
loaded: boolean;
|
|
52
|
+
providers: string[];
|
|
53
|
+
};
|
|
54
|
+
signals: TrackSignalNote[];
|
|
55
|
+
}
|
|
56
|
+
/** Cart lines as the pixel mappers read them. `unitAmount` stays minor; `baseTransform` converts. */
|
|
57
|
+
export declare function toContents(items?: CheckoutLineItem[]): PixelContent[] | undefined;
|
|
58
|
+
export declare class TrackModule {
|
|
59
|
+
private readonly baseUrl;
|
|
60
|
+
private readonly storeId;
|
|
61
|
+
private readonly funnelKey;
|
|
62
|
+
private readonly records;
|
|
63
|
+
private readonly lastStep;
|
|
64
|
+
private readonly signals;
|
|
65
|
+
private currentStepId;
|
|
66
|
+
private manifestHash;
|
|
67
|
+
private loadedProviders;
|
|
68
|
+
private configPromise;
|
|
69
|
+
private corePromise;
|
|
70
|
+
/** @internal Server assignment passed to the lazy runtime. */
|
|
71
|
+
bootstrap?: TgdBootstrap;
|
|
72
|
+
private enginePromise;
|
|
73
|
+
private flushTimer;
|
|
74
|
+
private listening;
|
|
75
|
+
constructor(baseUrl: string, storeId: string, funnelKey: string);
|
|
76
|
+
/**
|
|
77
|
+
* The flag is `<storeId>:<funnelKey>`. Only the storeId half arms it; the funnel half is DATA,
|
|
78
|
+
* read back by `flagFunnelKey()` so automatic events report the funnel the last `step()` named.
|
|
79
|
+
* A funnel-key mismatch never disarms tracking; only another tenant's storeId reads as disabled.
|
|
80
|
+
*/
|
|
81
|
+
private flag;
|
|
82
|
+
private enabled;
|
|
83
|
+
private flagFunnelKey;
|
|
84
|
+
/** Every automatic path is off under SSR and off without the flag. */
|
|
85
|
+
private off;
|
|
86
|
+
private arm;
|
|
87
|
+
step(stepId: string, data?: StepData): void;
|
|
88
|
+
event(name: string, data?: EventData): void;
|
|
89
|
+
/** Keep the dedup map to entries still inside the window, and never past `STEP_MEMORY`. */
|
|
90
|
+
private remember;
|
|
91
|
+
identify(who: TrackIdentity): void;
|
|
92
|
+
consent(state: {
|
|
93
|
+
marketing: boolean;
|
|
94
|
+
}): void;
|
|
95
|
+
health(): Promise<TrackHealth>;
|
|
96
|
+
/** @internal */
|
|
97
|
+
noteCheckout(input: {
|
|
98
|
+
checkoutSessionId: string;
|
|
99
|
+
amount?: number;
|
|
100
|
+
currency?: string;
|
|
101
|
+
items?: PixelContent[];
|
|
102
|
+
}): void;
|
|
103
|
+
/** @internal */
|
|
104
|
+
notePaid(input: {
|
|
105
|
+
orderId: string;
|
|
106
|
+
amount?: number;
|
|
107
|
+
currency?: string;
|
|
108
|
+
items?: PixelContent[];
|
|
109
|
+
}): void;
|
|
110
|
+
/** The `eventId` formula is the server's `makeMetaEventId`, so Meta and TikTok dedup. */
|
|
111
|
+
private notePixel;
|
|
112
|
+
/** @internal */
|
|
113
|
+
noteSignal(signal: 'wallet_unavailable', value: 'applePay' | 'googlePay' | 'express', detail: {
|
|
114
|
+
reason: string;
|
|
115
|
+
}): void;
|
|
116
|
+
private snapshot;
|
|
117
|
+
/**
|
|
118
|
+
* R4, once per page. Plain `fetch`, no header, no credentials — never `HttpClient`,
|
|
119
|
+
* which adds `Content-Type` and `x-cms-token` and so preflights against a fixed allow-list.
|
|
120
|
+
*/
|
|
121
|
+
private config;
|
|
122
|
+
/** @internal R4 is reused; loading is allowed only when it opts this store in. */
|
|
123
|
+
core(): Promise<TgdPublicApi | null>;
|
|
124
|
+
/** @internal Funnel navigation alone must not opt a site into tracking. */
|
|
125
|
+
noteFunnelSession(funnelSessionId: string): void;
|
|
126
|
+
private pixels;
|
|
127
|
+
private startEngine;
|
|
128
|
+
private onPixelSignal;
|
|
129
|
+
private listen;
|
|
130
|
+
private push;
|
|
131
|
+
/** `localStorage` is an undeclared identifier in Node, so it is read inside the try. */
|
|
132
|
+
private identifier;
|
|
133
|
+
private flush;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../../../src/core/modules/track.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAatD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,MAAM,WAAW,QAAQ;IACvB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC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AC;IAsBpC,2EAA2E;IAC3E,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;IAKhD,OAAO,CAAC,MAAM;YAMA,WAAW;IAqBzB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,IAAI;IAUZ,wFAAwF;IACxF,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,KAAK;CAoCd"}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { SDK_NAME, SDK_VERSION } from '../version.js';
|
|
2
|
+
const CDN_URL = typeof __TGD_PIXELS_CDN__ === 'undefined' ? '' : __TGD_PIXELS_CDN__;
|
|
3
|
+
function loadScript(src, isReady) {
|
|
4
|
+
if (isReady())
|
|
5
|
+
return Promise.resolve();
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const script = document.createElement('script');
|
|
8
|
+
script.src = src;
|
|
9
|
+
script.async = true;
|
|
10
|
+
script.onload = () => resolve();
|
|
11
|
+
script.onerror = () => reject(new Error('runtime script failed to load'));
|
|
12
|
+
document.head.appendChild(script);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async function loadPixels() {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return null;
|
|
18
|
+
if (CDN_URL) {
|
|
19
|
+
const w = window;
|
|
20
|
+
if (w.TagadaPixels)
|
|
21
|
+
return w.TagadaPixels;
|
|
22
|
+
await loadScript(CDN_URL, () => Boolean(w.TagadaPixels));
|
|
23
|
+
return w.TagadaPixels ?? null;
|
|
24
|
+
}
|
|
25
|
+
return (await import('../../pixels/index.js'));
|
|
26
|
+
}
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Helpers
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
const FLAG_KEY = '__tgd_track';
|
|
31
|
+
const ANON_KEY = '__tgd_aid';
|
|
32
|
+
const SESSION_KEY = '__tgd_sid';
|
|
33
|
+
const QUEUE_LIMIT = 50;
|
|
34
|
+
const FLUSH_MS = 2000;
|
|
35
|
+
const DEDUP_MS = 1000;
|
|
36
|
+
/** Hard ceiling on the dedup map. A long-lived SPA visiting hundreds of paths must not grow it. */
|
|
37
|
+
const STEP_MEMORY = 64;
|
|
38
|
+
/** Cart lines as the pixel mappers read them. `unitAmount` stays minor; `baseTransform` converts. */
|
|
39
|
+
export function toContents(items) {
|
|
40
|
+
if (!Array.isArray(items) || items.length === 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
return items.map((item) => ({ id: item.variantId, quantity: item.quantity, item_price: item.unitAmount }));
|
|
43
|
+
}
|
|
44
|
+
/** R5 carries flat scalars only; anything nested is dropped rather than stringified. */
|
|
45
|
+
function scalars(data) {
|
|
46
|
+
if (!data)
|
|
47
|
+
return undefined;
|
|
48
|
+
const out = {};
|
|
49
|
+
for (const [key, value] of Object.entries(data)) {
|
|
50
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
51
|
+
out[key] = value;
|
|
52
|
+
}
|
|
53
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Contract §3: the three SDK event names that carry a pixel meaning, and the standard event a
|
|
57
|
+
* canvas binding writes for them. The back end auto-binds `Lead`, not `lead`, so an event sent
|
|
58
|
+
* under its own name would be gated against a key `config.steps[...].events` never holds, and
|
|
59
|
+
* would reach Meta as an unknown custom event. Any other name is a custom event.
|
|
60
|
+
*/
|
|
61
|
+
const STANDARD_EVENTS = {
|
|
62
|
+
lead: 'Lead',
|
|
63
|
+
product_viewed: 'ViewContent',
|
|
64
|
+
added_to_cart: 'AddToCart',
|
|
65
|
+
};
|
|
66
|
+
function uuid() {
|
|
67
|
+
try {
|
|
68
|
+
return crypto.randomUUID();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* R4 answers a flat array (one entry per configured integration); the engine reads the
|
|
76
|
+
* hosted runtime's per-provider map. This is the only place the two shapes meet.
|
|
77
|
+
*/
|
|
78
|
+
function toPixelsConfig(pixels) {
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const pixel of pixels) {
|
|
81
|
+
// R4 builds each entry key by key, so spreading its own answer carries nothing extra.
|
|
82
|
+
const { provider, id, idKey, ...rest } = pixel;
|
|
83
|
+
(out[provider] ?? (out[provider] = [])).push({ ...rest, enabled: true, [idKey]: id, events: pixel.events ?? {} });
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// The module
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
export class TrackModule {
|
|
91
|
+
constructor(baseUrl, storeId, funnelKey) {
|
|
92
|
+
this.baseUrl = baseUrl;
|
|
93
|
+
this.storeId = storeId;
|
|
94
|
+
this.funnelKey = funnelKey;
|
|
95
|
+
this.records = [];
|
|
96
|
+
this.lastStep = new Map();
|
|
97
|
+
this.signals = [];
|
|
98
|
+
this.currentStepId = null;
|
|
99
|
+
this.manifestHash = null;
|
|
100
|
+
this.loadedProviders = [];
|
|
101
|
+
this.configPromise = null;
|
|
102
|
+
this.corePromise = null;
|
|
103
|
+
this.enginePromise = null;
|
|
104
|
+
this.flushTimer = null;
|
|
105
|
+
this.listening = false;
|
|
106
|
+
}
|
|
107
|
+
// -- opt-in flag ----------------------------------------------------------
|
|
108
|
+
/**
|
|
109
|
+
* The flag is `<storeId>:<funnelKey>`. Only the storeId half arms it; the funnel half is DATA,
|
|
110
|
+
* read back by `flagFunnelKey()` so automatic events report the funnel the last `step()` named.
|
|
111
|
+
* A funnel-key mismatch never disarms tracking; only another tenant's storeId reads as disabled.
|
|
112
|
+
*/
|
|
113
|
+
flag() {
|
|
114
|
+
try {
|
|
115
|
+
return (localStorage.getItem(FLAG_KEY) ?? '').split(':');
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
enabled() {
|
|
122
|
+
return this.flag()[0] === this.storeId;
|
|
123
|
+
}
|
|
124
|
+
flagFunnelKey() {
|
|
125
|
+
return this.flag()[1] || this.funnelKey;
|
|
126
|
+
}
|
|
127
|
+
/** Every automatic path is off under SSR and off without the flag. */
|
|
128
|
+
off() {
|
|
129
|
+
return typeof window === 'undefined' || !this.enabled();
|
|
130
|
+
}
|
|
131
|
+
arm() {
|
|
132
|
+
try {
|
|
133
|
+
localStorage.setItem(FLAG_KEY, `${this.storeId}:${this.funnelKey}`);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
/* private mode: tracking simply stays off */
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// -- public API -----------------------------------------------------------
|
|
140
|
+
step(stepId, data) {
|
|
141
|
+
if (typeof window === 'undefined')
|
|
142
|
+
return;
|
|
143
|
+
this.arm();
|
|
144
|
+
const path = data?.path ?? window.location.pathname;
|
|
145
|
+
const key = `${stepId}|${path}`;
|
|
146
|
+
const at = Date.now();
|
|
147
|
+
const previous = this.lastStep.get(key);
|
|
148
|
+
if (previous !== undefined && at - previous < DEDUP_MS)
|
|
149
|
+
return;
|
|
150
|
+
this.remember(key, at);
|
|
151
|
+
this.currentStepId = stepId;
|
|
152
|
+
this.listen();
|
|
153
|
+
this.push({ kind: 'step', stepId, at, path });
|
|
154
|
+
void this.pixels().then((engine) => engine?.pageView(path, { stepId }));
|
|
155
|
+
void this.core().then((t) => t?.page({ step_id: stepId })).catch(() => undefined);
|
|
156
|
+
}
|
|
157
|
+
event(name, data) {
|
|
158
|
+
if (this.off())
|
|
159
|
+
return;
|
|
160
|
+
const stepId = this.currentStepId;
|
|
161
|
+
// An event before the first `step()` belongs to no step: it reaches neither R5 nor a pixel.
|
|
162
|
+
if (stepId === null)
|
|
163
|
+
return;
|
|
164
|
+
// One id, both destinations (contract §7.5: `'<PixelEvent>_' + uuid`). The pixel event is the
|
|
165
|
+
// standard name when there is one, so the id Meta receives is the id R5 recorded.
|
|
166
|
+
const standard = STANDARD_EVENTS[name];
|
|
167
|
+
const eventId = `${standard ?? name}_${uuid()}`;
|
|
168
|
+
this.push({ kind: 'event', stepId, name, at: Date.now(), eventId, props: scalars(data) });
|
|
169
|
+
void this.pixels().then((engine) => standard ? engine?.track(standard, data, { stepId, eventId }) : engine?.trackCustom(name, data, { stepId }));
|
|
170
|
+
void this.core().then((t) => t?.track(name, { ...(scalars(data) ?? {}), step_id: stepId, pixel_event_id: eventId })).catch(() => undefined);
|
|
171
|
+
}
|
|
172
|
+
/** Keep the dedup map to entries still inside the window, and never past `STEP_MEMORY`. */
|
|
173
|
+
remember(key, at) {
|
|
174
|
+
for (const [seen, when] of this.lastStep) {
|
|
175
|
+
if (at - when >= DEDUP_MS)
|
|
176
|
+
this.lastStep.delete(seen);
|
|
177
|
+
}
|
|
178
|
+
// Map iterates in insertion order, so the first key is the oldest one still held.
|
|
179
|
+
while (this.lastStep.size >= STEP_MEMORY) {
|
|
180
|
+
const oldest = this.lastStep.keys().next();
|
|
181
|
+
if (oldest.done === true)
|
|
182
|
+
break;
|
|
183
|
+
this.lastStep.delete(oldest.value);
|
|
184
|
+
}
|
|
185
|
+
this.lastStep.set(key, at);
|
|
186
|
+
}
|
|
187
|
+
identify(who) {
|
|
188
|
+
if (this.off())
|
|
189
|
+
return;
|
|
190
|
+
// The engine's identity field is `externalId`; the Tagada customer id is what fills it.
|
|
191
|
+
void this.pixels().then((engine) => engine?.identify({ email: who.email, phone: who.phone, externalId: who.customerId }));
|
|
192
|
+
void this.core().then((t) => t?.identify(who.customerId ?? null, { email: who.email, phone: who.phone, customerId: who.customerId })).catch(() => undefined);
|
|
193
|
+
}
|
|
194
|
+
consent(state) {
|
|
195
|
+
if (this.off())
|
|
196
|
+
return;
|
|
197
|
+
void this.pixels().then((engine) => engine?.consent(state));
|
|
198
|
+
}
|
|
199
|
+
async health() {
|
|
200
|
+
if (typeof window === 'undefined')
|
|
201
|
+
return this.snapshot();
|
|
202
|
+
if (this.enabled())
|
|
203
|
+
await this.config();
|
|
204
|
+
return this.snapshot();
|
|
205
|
+
}
|
|
206
|
+
// -- internal hooks, called by the checkout and payment modules -----------
|
|
207
|
+
/** @internal */
|
|
208
|
+
noteCheckout(input) {
|
|
209
|
+
this.notePixel('InitiateCheckout', input.checkoutSessionId, input);
|
|
210
|
+
}
|
|
211
|
+
/** @internal */
|
|
212
|
+
notePaid(input) {
|
|
213
|
+
this.notePixel('Purchase', input.orderId, input);
|
|
214
|
+
}
|
|
215
|
+
/** The `eventId` formula is the server's `makeMetaEventId`, so Meta and TikTok dedup. */
|
|
216
|
+
notePixel(event, id, input) {
|
|
217
|
+
if (this.off())
|
|
218
|
+
return;
|
|
219
|
+
void this.pixels().then((engine) => engine?.track(event, { value: input.amount, currency: input.currency, contents: input.items, num_items: input.items?.length }, { eventId: `${event}_${id}` }));
|
|
220
|
+
}
|
|
221
|
+
/** @internal */
|
|
222
|
+
noteSignal(signal, value, detail) {
|
|
223
|
+
if (this.off())
|
|
224
|
+
return;
|
|
225
|
+
this.signals.push({ signal, value, detail });
|
|
226
|
+
this.listen();
|
|
227
|
+
this.push({ kind: 'signal', signal, value, detail });
|
|
228
|
+
}
|
|
229
|
+
// -- config, engine -------------------------------------------------------
|
|
230
|
+
snapshot() {
|
|
231
|
+
return {
|
|
232
|
+
enabled: typeof window === 'undefined' ? false : this.enabled(),
|
|
233
|
+
storeId: this.storeId,
|
|
234
|
+
funnelKey: this.flagFunnelKey(),
|
|
235
|
+
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
|
236
|
+
manifestHash: this.manifestHash,
|
|
237
|
+
pixels: { loaded: this.loadedProviders.length > 0, providers: [...this.loadedProviders] },
|
|
238
|
+
signals: [...this.signals],
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* R4, once per page. Plain `fetch`, no header, no credentials — never `HttpClient`,
|
|
243
|
+
* which adds `Content-Type` and `x-cms-token` and so preflights against a fixed allow-list.
|
|
244
|
+
*/
|
|
245
|
+
config() {
|
|
246
|
+
if (this.configPromise !== null)
|
|
247
|
+
return this.configPromise;
|
|
248
|
+
const url = `${this.baseUrl}/api/public/v1/sdk/config` +
|
|
249
|
+
`?storeId=${encodeURIComponent(this.storeId)}&funnel=${encodeURIComponent(this.flagFunnelKey())}`;
|
|
250
|
+
this.configPromise = (async () => {
|
|
251
|
+
try {
|
|
252
|
+
const response = await fetch(url);
|
|
253
|
+
if (!response.ok)
|
|
254
|
+
return null;
|
|
255
|
+
const config = (await response.json());
|
|
256
|
+
this.manifestHash = config.manifestHash || null;
|
|
257
|
+
return config;
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
})();
|
|
263
|
+
return this.configPromise;
|
|
264
|
+
}
|
|
265
|
+
/** @internal R4 is reused; loading is allowed only when it opts this store in. */
|
|
266
|
+
core() {
|
|
267
|
+
if (typeof window === 'undefined')
|
|
268
|
+
return Promise.resolve(null);
|
|
269
|
+
this.corePromise ?? (this.corePromise = (async () => {
|
|
270
|
+
try {
|
|
271
|
+
const config = await this.config();
|
|
272
|
+
if (!config || (!config.collect && !config.experiments))
|
|
273
|
+
return null;
|
|
274
|
+
const base = this.baseUrl.replace(/\/+$/, '');
|
|
275
|
+
const w = window;
|
|
276
|
+
if (typeof w.tgd?.init !== 'function') {
|
|
277
|
+
await loadScript(base + '/assets/js/tgd.js', () => typeof w.tgd?.init === 'function');
|
|
278
|
+
}
|
|
279
|
+
if (typeof w.tgd?.init !== 'function')
|
|
280
|
+
return null;
|
|
281
|
+
w.tgd.init({ storeId: this.storeId, apiHost: config.collect ? new URL(config.collect.url).origin : base,
|
|
282
|
+
bootstrap: this.bootstrap, _source: 'headless', _manualPages: true });
|
|
283
|
+
return w.tgd;
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
})());
|
|
289
|
+
return this.corePromise;
|
|
290
|
+
}
|
|
291
|
+
/** @internal Funnel navigation alone must not opt a site into tracking. */
|
|
292
|
+
noteFunnelSession(funnelSessionId) {
|
|
293
|
+
if (this.off())
|
|
294
|
+
return;
|
|
295
|
+
void this.core().then((t) => t?._link(funnelSessionId)).catch(() => undefined);
|
|
296
|
+
}
|
|
297
|
+
pixels() {
|
|
298
|
+
if (!this.enabled())
|
|
299
|
+
return Promise.resolve(null);
|
|
300
|
+
this.enginePromise ?? (this.enginePromise = this.startEngine());
|
|
301
|
+
return this.enginePromise;
|
|
302
|
+
}
|
|
303
|
+
async startEngine() {
|
|
304
|
+
try {
|
|
305
|
+
const config = await this.config();
|
|
306
|
+
if (config === null)
|
|
307
|
+
return null;
|
|
308
|
+
const module = await loadPixels();
|
|
309
|
+
if (module === null)
|
|
310
|
+
return null;
|
|
311
|
+
const engine = module.createPixelEngine({
|
|
312
|
+
pixels: toPixelsConfig(config.pixels ?? []),
|
|
313
|
+
steps: config.steps,
|
|
314
|
+
checkout: config.checkout,
|
|
315
|
+
requireConsent: config.consent?.required === true,
|
|
316
|
+
onSignal: (signal) => this.onPixelSignal(signal),
|
|
317
|
+
});
|
|
318
|
+
await engine.init();
|
|
319
|
+
this.loadedProviders = [...new Set((config.pixels ?? []).map((pixel) => pixel.provider))];
|
|
320
|
+
return engine;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
onPixelSignal(signal) {
|
|
327
|
+
const detail = signal.detail ?? {};
|
|
328
|
+
this.signals.push({ signal: signal.kind, value: signal.provider, detail });
|
|
329
|
+
this.push({ kind: 'signal', signal: signal.kind, value: signal.provider, detail });
|
|
330
|
+
}
|
|
331
|
+
// -- R5 queue -------------------------------------------------------------
|
|
332
|
+
listen() {
|
|
333
|
+
if (this.listening || typeof window === 'undefined')
|
|
334
|
+
return;
|
|
335
|
+
this.listening = true;
|
|
336
|
+
const onLeave = (event) => {
|
|
337
|
+
if (event.type === 'visibilitychange' && document.visibilityState !== 'hidden')
|
|
338
|
+
return;
|
|
339
|
+
this.flush();
|
|
340
|
+
};
|
|
341
|
+
window.addEventListener('pagehide', onLeave);
|
|
342
|
+
window.addEventListener('visibilitychange', onLeave);
|
|
343
|
+
}
|
|
344
|
+
push(record) {
|
|
345
|
+
if (!this.enabled())
|
|
346
|
+
return;
|
|
347
|
+
this.records.push(record);
|
|
348
|
+
if (this.records.length >= QUEUE_LIMIT) {
|
|
349
|
+
this.flush();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (this.flushTimer === null)
|
|
353
|
+
this.flushTimer = setTimeout(() => this.flush(), FLUSH_MS);
|
|
354
|
+
}
|
|
355
|
+
/** `localStorage` is an undeclared identifier in Node, so it is read inside the try. */
|
|
356
|
+
identifier(scope, key) {
|
|
357
|
+
try {
|
|
358
|
+
const store = scope === 'local' ? localStorage : sessionStorage;
|
|
359
|
+
const existing = store.getItem(key);
|
|
360
|
+
if (existing)
|
|
361
|
+
return existing;
|
|
362
|
+
const fresh = uuid();
|
|
363
|
+
store.setItem(key, fresh);
|
|
364
|
+
return fresh;
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return uuid();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
flush() {
|
|
371
|
+
if (this.flushTimer !== null) {
|
|
372
|
+
clearTimeout(this.flushTimer);
|
|
373
|
+
this.flushTimer = null;
|
|
374
|
+
}
|
|
375
|
+
if (this.records.length === 0)
|
|
376
|
+
return;
|
|
377
|
+
const records = this.records.splice(0, QUEUE_LIMIT);
|
|
378
|
+
const payload = {
|
|
379
|
+
storeId: this.storeId,
|
|
380
|
+
funnelKey: this.flagFunnelKey(),
|
|
381
|
+
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
|
382
|
+
anonymousId: this.identifier('local', ANON_KEY),
|
|
383
|
+
sessionId: this.identifier('session', SESSION_KEY),
|
|
384
|
+
records,
|
|
385
|
+
};
|
|
386
|
+
if (this.manifestHash !== null)
|
|
387
|
+
payload.manifestHash = this.manifestHash;
|
|
388
|
+
const body = JSON.stringify(payload);
|
|
389
|
+
const url = `${this.baseUrl}/api/public/v1/sdk/events`;
|
|
390
|
+
try {
|
|
391
|
+
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
|
392
|
+
if (navigator.sendBeacon(url, new Blob([body], { type: 'text/plain;charset=UTF-8' })))
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
/* swallowed: tracking never surfaces an error */
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
void fetch(url, {
|
|
401
|
+
method: 'POST',
|
|
402
|
+
body,
|
|
403
|
+
keepalive: true,
|
|
404
|
+
headers: { 'content-type': 'text/plain;charset=UTF-8' },
|
|
405
|
+
}).catch(() => undefined);
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
/* swallowed */
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=track.js.map
|