@aranova/tracking-react 0.24.0 → 0.25.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 +1 -1
- package/dist/client.d.mts +366 -0
- package/dist/client.d.ts +366 -0
- package/dist/client.js +3710 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +3680 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +9 -1726
- package/dist/index.d.ts +9 -1726
- package/dist/index.js +17 -2041
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2034
- package/dist/index.mjs.map +1 -1
- package/dist/ingest-typed-BioxtBJD.d.mts +1365 -0
- package/dist/ingest-typed-C-SPiigr.d.ts +1365 -0
- package/dist/{phone-utils-FTQnybMz.d.mts → phone-utils-BVzSNBf1.d.mts} +8 -4
- package/dist/{phone-utils-FTQnybMz.d.ts → phone-utils-BVzSNBf1.d.ts} +8 -4
- package/dist/phone.d.mts +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs.map +1 -1
- package/dist/{sales-BwWnvl8L.d.mts → sales-BIij04IG.d.ts} +2 -190
- package/dist/{sales-BwWnvl8L.d.ts → sales-C3B0BOBQ.d.mts} +2 -190
- package/dist/sales.d.mts +2 -1
- package/dist/sales.d.ts +2 -1
- package/dist/tracking-config-runtime-BnUlS_Ae.d.mts +190 -0
- package/dist/tracking-config-runtime-BnUlS_Ae.d.ts +190 -0
- package/package.json +18 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
interface ServiceFiring {
|
|
2
|
+
send_to: string;
|
|
3
|
+
/** Action's configured default value (cents); the SDK fires it only when a sale has no amount. */
|
|
4
|
+
value_cents?: number | null;
|
|
5
|
+
currency?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/** Serializable on-page trigger (owned by tracking-core/src/events/trigger-spec.ts). The shape
|
|
8
|
+
* varies by `event_type`; only the parameter for that type is set. */
|
|
9
|
+
interface ConfigTriggerSpec {
|
|
10
|
+
event_type: string;
|
|
11
|
+
threshold_percent?: number;
|
|
12
|
+
threshold_seconds?: number;
|
|
13
|
+
page_threshold?: number;
|
|
14
|
+
page_name?: string;
|
|
15
|
+
}
|
|
16
|
+
/** One unified conversion goal: a revenue `sale` or an on-page `event`. */
|
|
17
|
+
interface ConversionGoal {
|
|
18
|
+
key: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
kind: "sale" | "event";
|
|
21
|
+
/** Structured fire-when for event-goals; null for sales. */
|
|
22
|
+
trigger: ConfigTriggerSpec | null;
|
|
23
|
+
firing: ServiceFiring | null;
|
|
24
|
+
}
|
|
25
|
+
interface ConversionConfig {
|
|
26
|
+
schema_version: number;
|
|
27
|
+
config_version: number;
|
|
28
|
+
business_id?: string;
|
|
29
|
+
customer_id?: string | null;
|
|
30
|
+
environment?: string;
|
|
31
|
+
google_tracking_state: "active" | "disabled";
|
|
32
|
+
gtag_ids: Record<string, string>;
|
|
33
|
+
meta_pixel_ids: Record<string, string>;
|
|
34
|
+
/** LEGACY: sale-goals only (for pre-unified-goal readers). */
|
|
35
|
+
services: Array<{
|
|
36
|
+
key: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
firing: ServiceFiring | null;
|
|
39
|
+
}>;
|
|
40
|
+
/** Unified goal list (sales + on-page events). Superset of `services`. */
|
|
41
|
+
goals: ConversionGoal[];
|
|
42
|
+
}
|
|
43
|
+
interface ConversionConfigStore {
|
|
44
|
+
/** Firing config for a goal/service key, or null when it doesn't fire on-site. */
|
|
45
|
+
getFiring(key: string): ServiceFiring | null;
|
|
46
|
+
/** The full goal for a key, or null when unknown. */
|
|
47
|
+
getGoal(key: string): ConversionGoal | null;
|
|
48
|
+
/** Every adopted goal (sales + events). */
|
|
49
|
+
listGoals(): ConversionGoal[];
|
|
50
|
+
/** The currently adopted config (baked / cached fallback until the fetch lands). */
|
|
51
|
+
current(): ConversionConfig | null;
|
|
52
|
+
/** True once a config is adopted (seeded synchronously from cache/baked, or fetched). */
|
|
53
|
+
isReady(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Run `listener` when a config first becomes available — immediately if already
|
|
56
|
+
* ready, otherwise on the first adopt. Lets auto-fire replay automatic events that
|
|
57
|
+
* occurred before the async CDN fetch resolved. Returns an unsubscribe fn.
|
|
58
|
+
*/
|
|
59
|
+
onResolve(listener: () => void): () => void;
|
|
60
|
+
/** Force a background revalidate against the CDN object. */
|
|
61
|
+
revalidate(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
interface ResolveConversionConfigOptions {
|
|
64
|
+
/** Full URL of the per-business CDN object. */
|
|
65
|
+
cdnUrl: string;
|
|
66
|
+
/** Offline-correct fallback (e.g. the CLI-baked snapshot). */
|
|
67
|
+
baked?: ConversionConfig | null;
|
|
68
|
+
/** Injectable for tests / non-global-fetch runtimes. */
|
|
69
|
+
fetchImpl?: typeof fetch;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the config with stale-while-revalidate: seed synchronously from the
|
|
73
|
+
* sessionStorage cache (or the baked fallback), then conditionally re-fetch the CDN object
|
|
74
|
+
* with `If-None-Match`. A fetched object is adopted only if its `config_version` is strictly
|
|
75
|
+
* greater than what's cached, so a reordered edge copy can't downgrade fresher state.
|
|
76
|
+
* Non-blocking and browser-only; a failed fetch leaves the seed in place.
|
|
77
|
+
*/
|
|
78
|
+
declare function resolveConversionConfig(options: ResolveConversionConfigOptions): ConversionConfigStore;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Where a business's published tracking config lives.
|
|
82
|
+
*
|
|
83
|
+
* `businessId` + `environment` are the stable identity; the ORIGIN it is fetched
|
|
84
|
+
* from is deployment-specific (production CDN vs. a local object store), which is
|
|
85
|
+
* why `cdnBaseUrl` exists. Codegen bakes only the identity, so one committed
|
|
86
|
+
* generated file works in every environment and only an env var changes.
|
|
87
|
+
*
|
|
88
|
+
* `cdnUrl` remains supported and WINS when present — every client repo generated
|
|
89
|
+
* before `cdnBaseUrl` passes one, and those must keep working untouched.
|
|
90
|
+
*/
|
|
91
|
+
interface TrackingConfigReference {
|
|
92
|
+
/**
|
|
93
|
+
* Fully-resolved object URL. Optional: omit it and pass `cdnBaseUrl` (or rely
|
|
94
|
+
* on the production default) to have it composed from the identity below.
|
|
95
|
+
*/
|
|
96
|
+
cdnUrl?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Origin (optionally with a path prefix) the config object is served from, e.g.
|
|
99
|
+
* `https://demos.aranova.io` in production or
|
|
100
|
+
* `http://localhost:9100/aranova-demos` against a local MinIO. Ignored when
|
|
101
|
+
* `cdnUrl` is set; blank or omitted falls back to {@link DEFAULT_CDN_BASE_URL}.
|
|
102
|
+
* `tracking-cli gen` wires this to an env var so retargeting is config, not code.
|
|
103
|
+
*/
|
|
104
|
+
cdnBaseUrl?: string;
|
|
105
|
+
businessId: string;
|
|
106
|
+
environment: "production" | "test";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The URL a reference resolves to. An explicit `cdnUrl` wins (back-compat);
|
|
110
|
+
* otherwise compose from `cdnBaseUrl` (or the production default).
|
|
111
|
+
*
|
|
112
|
+
* A blank/whitespace `cdnBaseUrl` is treated as UNSET rather than composed: the
|
|
113
|
+
* generated module reads it from an env var, and a var that is present-but-empty
|
|
114
|
+
* (a stray `NEXT_PUBLIC_ARANOVA_CDN_BASE_URL=` line) would otherwise produce
|
|
115
|
+
* `/tracking-config/...` — a same-origin request to the client's own site.
|
|
116
|
+
*/
|
|
117
|
+
declare function resolveTrackingConfigUrl(ref: TrackingConfigReference): string;
|
|
118
|
+
type RuntimeState = "unconfirmed" | "active" | "tombstone";
|
|
119
|
+
interface QueuedConversion {
|
|
120
|
+
key: string;
|
|
121
|
+
value?: number | null;
|
|
122
|
+
currency?: string | null;
|
|
123
|
+
transactionId?: string | null;
|
|
124
|
+
}
|
|
125
|
+
type TrackingConfigConversionOptions = Omit<QueuedConversion, "key">;
|
|
126
|
+
interface QueuedPageView {
|
|
127
|
+
href: string;
|
|
128
|
+
title: string | null;
|
|
129
|
+
referrer: string | null;
|
|
130
|
+
}
|
|
131
|
+
declare class TrackingConfigRuntime {
|
|
132
|
+
readonly ref: TrackingConfigReference;
|
|
133
|
+
private readonly fetchImpl;
|
|
134
|
+
/** Resolved config URL — see the constructor for why it is computed once. */
|
|
135
|
+
private readonly url;
|
|
136
|
+
private current;
|
|
137
|
+
private etag;
|
|
138
|
+
private stateValue;
|
|
139
|
+
private confirmedAt;
|
|
140
|
+
private authorityGeneration;
|
|
141
|
+
private inFlight;
|
|
142
|
+
private flushInFlight;
|
|
143
|
+
private flushRequested;
|
|
144
|
+
private retryTimer;
|
|
145
|
+
private started;
|
|
146
|
+
/** Consecutive failed authority attempts — drives the revalidate backoff. */
|
|
147
|
+
private authorityFailures;
|
|
148
|
+
/** Epoch ms before which `ensureAuthority` must not issue another request. */
|
|
149
|
+
private nextAuthorityAttemptAt;
|
|
150
|
+
private readonly conversionQueue;
|
|
151
|
+
private readonly automaticQueue;
|
|
152
|
+
private readonly pageQueue;
|
|
153
|
+
private readonly listeners;
|
|
154
|
+
constructor(ref: TrackingConfigReference, fetchImpl?: typeof fetch);
|
|
155
|
+
/** The URL this runtime actually fetches (composed or explicit). */
|
|
156
|
+
configUrl(): string;
|
|
157
|
+
/**
|
|
158
|
+
* Explicitly start authority resolution and Google-tag bootstrap.
|
|
159
|
+
*
|
|
160
|
+
* Idempotent so framework effects can call it after hydration without
|
|
161
|
+
* depending on constructor timing.
|
|
162
|
+
*/
|
|
163
|
+
start(): void;
|
|
164
|
+
state(): RuntimeState;
|
|
165
|
+
config(): ConversionConfig | null;
|
|
166
|
+
__unsafeExpireAuthorityForTests(): void;
|
|
167
|
+
/** Queue depths — asserted by tests to pin the bound. */
|
|
168
|
+
__queueDepthsForTests(): {
|
|
169
|
+
conversions: number;
|
|
170
|
+
automatic: number;
|
|
171
|
+
pages: number;
|
|
172
|
+
};
|
|
173
|
+
subscribe(listener: () => void): () => void;
|
|
174
|
+
ensureAuthority(): Promise<boolean>;
|
|
175
|
+
revalidate(): Promise<void>;
|
|
176
|
+
private revalidateAuthority;
|
|
177
|
+
queuePageView(snapshot?: QueuedPageView | null): void;
|
|
178
|
+
fireConversion(key: string, options?: TrackingConfigConversionOptions): void;
|
|
179
|
+
queueAutomaticEvent(eventType: string, metadata: Record<string, unknown>, transactionPath: string, transactionScope: string): void;
|
|
180
|
+
listGoals(): ConversionGoal[];
|
|
181
|
+
private revalidateNow;
|
|
182
|
+
private expireAuthority;
|
|
183
|
+
private confirm;
|
|
184
|
+
private flush;
|
|
185
|
+
private scheduleRetry;
|
|
186
|
+
private flushNow;
|
|
187
|
+
}
|
|
188
|
+
declare function getTrackingConfigRuntime(ref: TrackingConfigReference, fetchImpl?: typeof fetch): TrackingConfigRuntime;
|
|
189
|
+
|
|
190
|
+
export { type ConversionConfig as C, type TrackingConfigReference as T, type ConversionConfigStore as a, resolveTrackingConfigUrl as b, TrackingConfigRuntime as c, getTrackingConfigRuntime as g, resolveConversionConfig as r };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aranova/tracking-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "React tracking and consent utilities for Aranova client sites",
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"module": "./dist/index.mjs",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"typesVersions": {
|
|
15
|
+
"*": {
|
|
16
|
+
"client": [
|
|
17
|
+
"./dist/client.d.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
14
21
|
"sideEffects": false,
|
|
15
22
|
"repository": {
|
|
16
23
|
"type": "git",
|
|
@@ -29,6 +36,16 @@
|
|
|
29
36
|
"default": "./dist/index.js"
|
|
30
37
|
}
|
|
31
38
|
},
|
|
39
|
+
"./client": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/client.d.mts",
|
|
42
|
+
"default": "./dist/client.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/client.d.ts",
|
|
46
|
+
"default": "./dist/client.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
32
49
|
"./sales": {
|
|
33
50
|
"import": {
|
|
34
51
|
"types": "./dist/sales.d.mts",
|