@aranova/tracking-react 0.5.1 → 0.6.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 +114 -0
- package/dist/index.d.mts +444 -48
- package/dist/index.d.ts +444 -48
- package/dist/index.js +26 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,94 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
+
import * as src from 'src';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Default non-blocking consent banner.
|
|
8
|
+
*
|
|
9
|
+
* Renders only while consent is `pending`. Accept/decline choices are stored
|
|
10
|
+
* in localStorage and propagated to Google Consent Mode when gtag is loaded.
|
|
11
|
+
*/
|
|
5
12
|
declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
|
|
6
13
|
|
|
7
14
|
interface GoogleAdsTrackingProps {
|
|
15
|
+
/**
|
|
16
|
+
* Google Ads tag id, for example `AW-123456789`.
|
|
17
|
+
*/
|
|
8
18
|
gtagId: string;
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Client component that loads Google Ads gtag and restores stored consent.
|
|
22
|
+
*
|
|
23
|
+
* Render once near the application root when the client site runs paid Google
|
|
24
|
+
* Ads. The component renders nothing.
|
|
25
|
+
*/
|
|
10
26
|
declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): null;
|
|
11
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Visitor consent state stored by the SDK.
|
|
30
|
+
*
|
|
31
|
+
* - `pending`: the visitor has not accepted or declined yet.
|
|
32
|
+
* - `granted`: consent was accepted and Google Consent Mode is updated to granted.
|
|
33
|
+
* - `denied`: consent was declined and Google Consent Mode is updated to denied.
|
|
34
|
+
*/
|
|
12
35
|
type ConsentState = 'granted' | 'denied' | 'pending';
|
|
36
|
+
/**
|
|
37
|
+
* Attribution parameters captured from the landing URL and persisted in cookies.
|
|
38
|
+
*
|
|
39
|
+
* Missing params are represented as `null` so payloads can be serialized
|
|
40
|
+
* directly without checking for `undefined`.
|
|
41
|
+
*/
|
|
13
42
|
interface TrackingParams {
|
|
43
|
+
/** Google Ads click id. */
|
|
14
44
|
gclid: string | null;
|
|
45
|
+
/** Meta/Facebook click id. */
|
|
15
46
|
fbclid: string | null;
|
|
47
|
+
/** UTM source, for example `google` or `newsletter`. */
|
|
16
48
|
utm_source: string | null;
|
|
49
|
+
/** UTM medium, for example `cpc` or `email`. */
|
|
17
50
|
utm_medium: string | null;
|
|
51
|
+
/** UTM campaign name. */
|
|
18
52
|
utm_campaign: string | null;
|
|
53
|
+
/** UTM paid-search term. */
|
|
19
54
|
utm_term: string | null;
|
|
55
|
+
/** UTM content/ad creative label. */
|
|
20
56
|
utm_content: string | null;
|
|
21
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Runtime surface that installed the tracking SDK.
|
|
60
|
+
*
|
|
61
|
+
* Included in ingest payloads and heartbeat events so the dashboard can tell
|
|
62
|
+
* whether a site uses the Next, React, or script-tag integration.
|
|
63
|
+
*/
|
|
22
64
|
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
65
|
+
/**
|
|
66
|
+
* Runtime context attached to tracking sessions and events.
|
|
67
|
+
*/
|
|
23
68
|
interface TrackingClientContext {
|
|
69
|
+
/** Install surface that created the client. */
|
|
24
70
|
surface: TrackingInstallSurface;
|
|
71
|
+
/** Package version, when available. */
|
|
25
72
|
sdk_version: string | null;
|
|
73
|
+
/** Package name, for example `@aranova/tracking-react`. */
|
|
26
74
|
package_name: string | null;
|
|
75
|
+
/** Browser origin of the tracked site. */
|
|
27
76
|
site_origin: string | null;
|
|
77
|
+
/** Current document title at client creation time. */
|
|
28
78
|
page_title: string | null;
|
|
79
|
+
/** Browser document referrer at client creation time. */
|
|
29
80
|
referrer: string | null;
|
|
30
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Session payload sent to `POST /tracking/events`.
|
|
84
|
+
*
|
|
85
|
+
* The backend upserts this by `(business_id, session_id)` before inserting
|
|
86
|
+
* individual events.
|
|
87
|
+
*/
|
|
31
88
|
interface TrackingSessionUpsertPayload {
|
|
89
|
+
/** Rolling 30-minute client-side session id. */
|
|
32
90
|
session_id: string;
|
|
91
|
+
/** Persistent client-side visitor id. */
|
|
33
92
|
visitor_id: string | null;
|
|
34
93
|
gclid: string | null;
|
|
35
94
|
fbclid: string | null;
|
|
@@ -42,22 +101,39 @@ interface TrackingSessionUpsertPayload {
|
|
|
42
101
|
consent_state: Record<string, unknown> | null;
|
|
43
102
|
context: TrackingClientContext;
|
|
44
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Event payload shape before batching into the ingest request.
|
|
106
|
+
*/
|
|
45
107
|
interface TrackingEventCreatePayload {
|
|
108
|
+
/** Session id that logically owns the event. */
|
|
46
109
|
session_id: string;
|
|
110
|
+
/** Registered event name, for example `page_view` or `form_submit`. */
|
|
47
111
|
event_type: string;
|
|
48
112
|
gclid: string | null;
|
|
49
113
|
fbclid: string | null;
|
|
114
|
+
/** Full page URL associated with the event, if known. */
|
|
50
115
|
page_url: string | null;
|
|
116
|
+
/** Event-specific metadata. Runtime shape depends on `event_type`. */
|
|
51
117
|
metadata: Record<string, unknown> | null;
|
|
52
118
|
context: TrackingClientContext;
|
|
53
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Browser-script initialization config passed to `window.AranovaTracking.init()`.
|
|
122
|
+
*/
|
|
54
123
|
interface TrackingInitConfig {
|
|
124
|
+
/** Public tracking API key issued from the Aranova dashboard. */
|
|
55
125
|
apiKey?: string;
|
|
126
|
+
/** Tracking endpoint base URL, usually ending in `/tracking`. */
|
|
56
127
|
endpoint?: string;
|
|
128
|
+
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
57
129
|
gtagId?: string;
|
|
130
|
+
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
58
131
|
autoCaptureTrackingParams?: boolean;
|
|
132
|
+
/** Whether the browser script should inject the default consent banner. */
|
|
59
133
|
renderConsentBanner?: boolean;
|
|
134
|
+
/** Attribution cookie max age in seconds. Defaults to 90 days. */
|
|
60
135
|
cookieMaxAgeSeconds?: number;
|
|
136
|
+
/** Override the install surface reported in payload context. */
|
|
61
137
|
surface?: TrackingInstallSurface;
|
|
62
138
|
}
|
|
63
139
|
declare global {
|
|
@@ -75,8 +151,21 @@ declare global {
|
|
|
75
151
|
}
|
|
76
152
|
}
|
|
77
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
|
|
156
|
+
*/
|
|
78
157
|
type GtagConsentValue = 'granted' | 'denied';
|
|
158
|
+
/**
|
|
159
|
+
* Read the persisted visitor consent state from localStorage.
|
|
160
|
+
*
|
|
161
|
+
* Returns `pending` when called during SSR or before the visitor has made a
|
|
162
|
+
* choice.
|
|
163
|
+
*/
|
|
79
164
|
declare function getConsentState(): ConsentState;
|
|
165
|
+
/**
|
|
166
|
+
* Persist a visitor consent choice and update Google Consent Mode when gtag is
|
|
167
|
+
* loaded.
|
|
168
|
+
*/
|
|
80
169
|
declare function setConsentState(state: GtagConsentValue): void;
|
|
81
170
|
|
|
82
171
|
interface TrackingContextInput {
|
|
@@ -98,18 +187,42 @@ interface TrackingSessionInput {
|
|
|
98
187
|
sessionId: string;
|
|
99
188
|
visitorId?: string | null;
|
|
100
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Build runtime context attached to tracking sessions and events.
|
|
192
|
+
*/
|
|
101
193
|
declare function createTrackingClientContext(surface: TrackingInstallSurface, input?: TrackingContextInput): TrackingClientContext;
|
|
194
|
+
/**
|
|
195
|
+
* Build the session portion of a tracking ingest request.
|
|
196
|
+
*/
|
|
102
197
|
declare function createTrackingSessionUpsertPayload(trackingParams: TrackingParams, input: TrackingSessionInput, context: TrackingClientContext): TrackingSessionUpsertPayload;
|
|
198
|
+
/**
|
|
199
|
+
* Build one event payload before it is batched into a tracking ingest request.
|
|
200
|
+
*/
|
|
103
201
|
declare function createTrackingEventCreatePayload(trackingParams: TrackingParams, input: TrackingEventInput, context: TrackingClientContext): TrackingEventCreatePayload;
|
|
104
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Attribution query/cookie keys captured by the SDK.
|
|
205
|
+
*/
|
|
105
206
|
declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
207
|
+
/**
|
|
208
|
+
* Capture tracking params from a URL, persist them to first-party cookies, and
|
|
209
|
+
* return the current cookie-backed attribution state.
|
|
210
|
+
*
|
|
211
|
+
* Defaults to `window.location.href` in the browser.
|
|
212
|
+
*/
|
|
106
213
|
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
107
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Metadata for a manually fired `cta_click` event.
|
|
217
|
+
*
|
|
218
|
+
* Use this for non-phone calls to action such as directions, appointment
|
|
219
|
+
* buttons, downloads, or external booking links.
|
|
220
|
+
*/
|
|
108
221
|
declare const ctaClickMetadataSchema: z.ZodObject<{
|
|
109
222
|
cta_name: z.ZodString;
|
|
110
223
|
page: z.ZodObject<{
|
|
111
224
|
path: z.ZodString;
|
|
112
|
-
}, "
|
|
225
|
+
}, "strict", z.ZodTypeAny, {
|
|
113
226
|
path: string;
|
|
114
227
|
}, {
|
|
115
228
|
path: string;
|
|
@@ -132,9 +245,21 @@ declare const ctaClickMetadataSchema: z.ZodObject<{
|
|
|
132
245
|
destination_url?: string | null | undefined;
|
|
133
246
|
}>;
|
|
134
247
|
type CtaClickMetadata = z.infer<typeof ctaClickMetadataSchema>;
|
|
248
|
+
/**
|
|
249
|
+
* Registration config for `cta_click`.
|
|
250
|
+
*
|
|
251
|
+
* This event is manual-only and currently has no registration options.
|
|
252
|
+
*/
|
|
135
253
|
declare const ctaClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
136
254
|
type CtaClickConfig = z.infer<typeof ctaClickConfigSchema>;
|
|
137
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Metadata for the SDK-internal `sdk_heartbeat` event.
|
|
258
|
+
*
|
|
259
|
+
* The SDK fires this once per new session so the dashboard can show which SDK
|
|
260
|
+
* version, install surface, and trigger registry a client site is running.
|
|
261
|
+
* Consumers do not manually register or fire this event.
|
|
262
|
+
*/
|
|
138
263
|
declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
139
264
|
sdk_version: z.ZodString;
|
|
140
265
|
package_name: z.ZodNullable<z.ZodString>;
|
|
@@ -170,14 +295,24 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
170
295
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
171
296
|
}>;
|
|
172
297
|
type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
|
|
298
|
+
/**
|
|
299
|
+
* Internal registration config for `sdk_heartbeat`.
|
|
300
|
+
*
|
|
301
|
+
* This event has no consumer-facing options.
|
|
302
|
+
*/
|
|
173
303
|
declare const sdkHeartbeatConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
174
304
|
type SdkHeartbeatConfig = z.infer<typeof sdkHeartbeatConfigSchema>;
|
|
175
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Metadata for the automatic `form_start` event.
|
|
308
|
+
*
|
|
309
|
+
* The SDK emits this once per form when the visitor first focuses a field.
|
|
310
|
+
*/
|
|
176
311
|
declare const formStartMetadataSchema: z.ZodObject<{
|
|
177
312
|
form: z.ZodObject<{
|
|
178
313
|
id: z.ZodString;
|
|
179
314
|
action: z.ZodNullable<z.ZodString>;
|
|
180
|
-
}, "
|
|
315
|
+
}, "strict", z.ZodTypeAny, {
|
|
181
316
|
id: string;
|
|
182
317
|
action: string | null;
|
|
183
318
|
}, {
|
|
@@ -186,7 +321,7 @@ declare const formStartMetadataSchema: z.ZodObject<{
|
|
|
186
321
|
}>;
|
|
187
322
|
page: z.ZodObject<{
|
|
188
323
|
path: z.ZodString;
|
|
189
|
-
}, "
|
|
324
|
+
}, "strict", z.ZodTypeAny, {
|
|
190
325
|
path: string;
|
|
191
326
|
}, {
|
|
192
327
|
path: string;
|
|
@@ -209,6 +344,12 @@ declare const formStartMetadataSchema: z.ZodObject<{
|
|
|
209
344
|
};
|
|
210
345
|
}>;
|
|
211
346
|
type FormStartMetadata = z.infer<typeof formStartMetadataSchema>;
|
|
347
|
+
/**
|
|
348
|
+
* Registration config for automatic `form_start`.
|
|
349
|
+
*
|
|
350
|
+
* Use `selector` to narrow which forms can trigger the event. When omitted,
|
|
351
|
+
* the SDK observes all `<form>` elements.
|
|
352
|
+
*/
|
|
212
353
|
declare const formStartConfigSchema: z.ZodObject<{
|
|
213
354
|
selector: z.ZodOptional<z.ZodString>;
|
|
214
355
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -218,6 +359,46 @@ declare const formStartConfigSchema: z.ZodObject<{
|
|
|
218
359
|
}>;
|
|
219
360
|
type FormStartConfig = z.infer<typeof formStartConfigSchema>;
|
|
220
361
|
|
|
362
|
+
/**
|
|
363
|
+
* JSON-serializable value accepted by `form_submit.fields[].value`.
|
|
364
|
+
*
|
|
365
|
+
* This intentionally excludes `undefined`, functions, symbols, `Date`
|
|
366
|
+
* instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
|
|
367
|
+
* consumers should send only data that has a stable JSON representation.
|
|
368
|
+
*/
|
|
369
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
370
|
+
[key: string]: JsonValue;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Metadata for a manually fired `form_submit` event.
|
|
374
|
+
*
|
|
375
|
+
* Register the event with `manual: { form_submit: {} }`, then call
|
|
376
|
+
* `trackEvent('form_submit', metadata)` from the host site's submit handler.
|
|
377
|
+
*
|
|
378
|
+
* `fields` is optional. If present, each field value must be JSON-serializable
|
|
379
|
+
* and should be explicitly allowlisted by the integration. Do not send names,
|
|
380
|
+
* emails, visitor phone numbers, addresses, payment data, medical details,
|
|
381
|
+
* passwords, file contents, or free-text messages.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* tracking.trackEvent('form_submit', {
|
|
386
|
+
* form: {
|
|
387
|
+
* id: 'lead-form',
|
|
388
|
+
* action: '/api/lead',
|
|
389
|
+
* fields: [
|
|
390
|
+
* {
|
|
391
|
+
* name: 'service_interest',
|
|
392
|
+
* type: 'select',
|
|
393
|
+
* label: 'Service interest',
|
|
394
|
+
* value: 'teeth_whitening',
|
|
395
|
+
* },
|
|
396
|
+
* ],
|
|
397
|
+
* },
|
|
398
|
+
* page: { path: window.location.pathname },
|
|
399
|
+
* });
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
221
402
|
declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
222
403
|
form: z.ZodObject<{
|
|
223
404
|
id: z.ZodString;
|
|
@@ -226,40 +407,40 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
|
226
407
|
name: z.ZodString;
|
|
227
408
|
type: z.ZodString;
|
|
228
409
|
label: z.ZodNullable<z.ZodString>;
|
|
229
|
-
|
|
230
|
-
}, "
|
|
410
|
+
value: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
411
|
+
}, "strict", z.ZodTypeAny, {
|
|
231
412
|
label: string | null;
|
|
413
|
+
value: JsonValue;
|
|
232
414
|
type: string;
|
|
233
415
|
name: string;
|
|
234
|
-
has_value: boolean;
|
|
235
416
|
}, {
|
|
236
417
|
label: string | null;
|
|
418
|
+
value: JsonValue;
|
|
237
419
|
type: string;
|
|
238
420
|
name: string;
|
|
239
|
-
has_value: boolean;
|
|
240
421
|
}>, "many">>;
|
|
241
|
-
}, "
|
|
422
|
+
}, "strict", z.ZodTypeAny, {
|
|
242
423
|
id: string;
|
|
243
424
|
action: string | null;
|
|
244
425
|
fields?: {
|
|
245
426
|
label: string | null;
|
|
427
|
+
value: JsonValue;
|
|
246
428
|
type: string;
|
|
247
429
|
name: string;
|
|
248
|
-
has_value: boolean;
|
|
249
430
|
}[] | undefined;
|
|
250
431
|
}, {
|
|
251
432
|
id: string;
|
|
252
433
|
action: string | null;
|
|
253
434
|
fields?: {
|
|
254
435
|
label: string | null;
|
|
436
|
+
value: JsonValue;
|
|
255
437
|
type: string;
|
|
256
438
|
name: string;
|
|
257
|
-
has_value: boolean;
|
|
258
439
|
}[] | undefined;
|
|
259
440
|
}>;
|
|
260
441
|
page: z.ZodObject<{
|
|
261
442
|
path: z.ZodString;
|
|
262
|
-
}, "
|
|
443
|
+
}, "strict", z.ZodTypeAny, {
|
|
263
444
|
path: string;
|
|
264
445
|
}, {
|
|
265
446
|
path: string;
|
|
@@ -270,9 +451,9 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
|
270
451
|
action: string | null;
|
|
271
452
|
fields?: {
|
|
272
453
|
label: string | null;
|
|
454
|
+
value: JsonValue;
|
|
273
455
|
type: string;
|
|
274
456
|
name: string;
|
|
275
|
-
has_value: boolean;
|
|
276
457
|
}[] | undefined;
|
|
277
458
|
};
|
|
278
459
|
page: {
|
|
@@ -284,9 +465,9 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
|
284
465
|
action: string | null;
|
|
285
466
|
fields?: {
|
|
286
467
|
label: string | null;
|
|
468
|
+
value: JsonValue;
|
|
287
469
|
type: string;
|
|
288
470
|
name: string;
|
|
289
|
-
has_value: boolean;
|
|
290
471
|
}[] | undefined;
|
|
291
472
|
};
|
|
292
473
|
page: {
|
|
@@ -294,14 +475,26 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
|
294
475
|
};
|
|
295
476
|
}>;
|
|
296
477
|
type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
|
|
478
|
+
/**
|
|
479
|
+
* Registration config for `form_submit`.
|
|
480
|
+
*
|
|
481
|
+
* This event is manual-only and currently has no registration options. The
|
|
482
|
+
* empty object enables typed `trackEvent('form_submit', ...)` calls.
|
|
483
|
+
*/
|
|
297
484
|
declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
298
485
|
type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
|
|
299
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Metadata for the automatic `multi_page_session` event.
|
|
489
|
+
*
|
|
490
|
+
* Fired when the visitor reaches the configured distinct-page threshold in a
|
|
491
|
+
* single tracking session.
|
|
492
|
+
*/
|
|
300
493
|
declare const multiPageSessionMetadataSchema: z.ZodObject<{
|
|
301
494
|
page_count: z.ZodNumber;
|
|
302
495
|
page: z.ZodObject<{
|
|
303
496
|
path: z.ZodString;
|
|
304
|
-
}, "
|
|
497
|
+
}, "strict", z.ZodTypeAny, {
|
|
305
498
|
path: string;
|
|
306
499
|
}, {
|
|
307
500
|
path: string;
|
|
@@ -318,6 +511,9 @@ declare const multiPageSessionMetadataSchema: z.ZodObject<{
|
|
|
318
511
|
page_count: number;
|
|
319
512
|
}>;
|
|
320
513
|
type MultiPageSessionMetadata = z.infer<typeof multiPageSessionMetadataSchema>;
|
|
514
|
+
/**
|
|
515
|
+
* Registration config for automatic `multi_page_session`.
|
|
516
|
+
*/
|
|
321
517
|
declare const multiPageSessionConfigSchema: z.ZodObject<{
|
|
322
518
|
pageThreshold: z.ZodNumber;
|
|
323
519
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -327,13 +523,20 @@ declare const multiPageSessionConfigSchema: z.ZodObject<{
|
|
|
327
523
|
}>;
|
|
328
524
|
type MultiPageSessionConfig = z.infer<typeof multiPageSessionConfigSchema>;
|
|
329
525
|
|
|
526
|
+
/**
|
|
527
|
+
* Metadata for the automatic `page_view` event.
|
|
528
|
+
*
|
|
529
|
+
* The SDK emits this on initial load, SPA route changes, and bfcache restores.
|
|
530
|
+
* Consumers do not call `trackEvent('page_view', ...)`; registering
|
|
531
|
+
* `automatic: { page_view: {} }` enables the SDK-owned trigger.
|
|
532
|
+
*/
|
|
330
533
|
declare const pageViewMetadataSchema: z.ZodObject<{
|
|
331
534
|
page: z.ZodObject<{
|
|
332
535
|
title: z.ZodNullable<z.ZodString>;
|
|
333
536
|
path: z.ZodString;
|
|
334
537
|
search: z.ZodString;
|
|
335
538
|
hash: z.ZodString;
|
|
336
|
-
}, "
|
|
539
|
+
}, "strict", z.ZodTypeAny, {
|
|
337
540
|
search: string;
|
|
338
541
|
title: string | null;
|
|
339
542
|
path: string;
|
|
@@ -348,7 +551,7 @@ declare const pageViewMetadataSchema: z.ZodObject<{
|
|
|
348
551
|
viewport: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
349
552
|
w: z.ZodNumber;
|
|
350
553
|
h: z.ZodNumber;
|
|
351
|
-
}, "
|
|
554
|
+
}, "strict", z.ZodTypeAny, {
|
|
352
555
|
w: number;
|
|
353
556
|
h: number;
|
|
354
557
|
}, {
|
|
@@ -381,14 +584,27 @@ declare const pageViewMetadataSchema: z.ZodObject<{
|
|
|
381
584
|
} | null | undefined;
|
|
382
585
|
}>;
|
|
383
586
|
type PageViewMetadata = z.infer<typeof pageViewMetadataSchema>;
|
|
587
|
+
/**
|
|
588
|
+
* Registration config for automatic `page_view`.
|
|
589
|
+
*
|
|
590
|
+
* `page_view` is required in every trigger registry and currently has no
|
|
591
|
+
* options. Use `{ page_view: {} }`.
|
|
592
|
+
*/
|
|
384
593
|
declare const pageViewConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
385
594
|
type PageViewConfig = z.infer<typeof pageViewConfigSchema>;
|
|
386
595
|
|
|
596
|
+
/**
|
|
597
|
+
* Metadata for a manually fired `phone_click` event.
|
|
598
|
+
*
|
|
599
|
+
* `phone_number` should be the business phone number from the clicked `tel:`
|
|
600
|
+
* link, not a visitor-entered phone number. `section` can distinguish header,
|
|
601
|
+
* footer, hero, or contact-page links.
|
|
602
|
+
*/
|
|
387
603
|
declare const phoneClickMetadataSchema: z.ZodObject<{
|
|
388
604
|
phone_number: z.ZodString;
|
|
389
605
|
page: z.ZodObject<{
|
|
390
606
|
path: z.ZodString;
|
|
391
|
-
}, "
|
|
607
|
+
}, "strict", z.ZodTypeAny, {
|
|
392
608
|
path: string;
|
|
393
609
|
}, {
|
|
394
610
|
path: string;
|
|
@@ -408,14 +624,24 @@ declare const phoneClickMetadataSchema: z.ZodObject<{
|
|
|
408
624
|
section?: string | null | undefined;
|
|
409
625
|
}>;
|
|
410
626
|
type PhoneClickMetadata = z.infer<typeof phoneClickMetadataSchema>;
|
|
627
|
+
/**
|
|
628
|
+
* Registration config for `phone_click`.
|
|
629
|
+
*
|
|
630
|
+
* This event is manual-only and currently has no registration options.
|
|
631
|
+
*/
|
|
411
632
|
declare const phoneClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
412
633
|
type PhoneClickConfig = z.infer<typeof phoneClickConfigSchema>;
|
|
413
634
|
|
|
635
|
+
/**
|
|
636
|
+
* Metadata for the automatic `scroll_depth` event.
|
|
637
|
+
*
|
|
638
|
+
* Fired once per configured threshold per page.
|
|
639
|
+
*/
|
|
414
640
|
declare const scrollDepthMetadataSchema: z.ZodObject<{
|
|
415
641
|
depth_percent: z.ZodNumber;
|
|
416
642
|
page: z.ZodObject<{
|
|
417
643
|
path: z.ZodString;
|
|
418
|
-
}, "
|
|
644
|
+
}, "strict", z.ZodTypeAny, {
|
|
419
645
|
path: string;
|
|
420
646
|
}, {
|
|
421
647
|
path: string;
|
|
@@ -432,6 +658,11 @@ declare const scrollDepthMetadataSchema: z.ZodObject<{
|
|
|
432
658
|
depth_percent: number;
|
|
433
659
|
}>;
|
|
434
660
|
type ScrollDepthMetadata = z.infer<typeof scrollDepthMetadataSchema>;
|
|
661
|
+
/**
|
|
662
|
+
* Registration config for automatic `scroll_depth`.
|
|
663
|
+
*
|
|
664
|
+
* `thresholds` are integer percentages from 1 to 100.
|
|
665
|
+
*/
|
|
435
666
|
declare const scrollDepthConfigSchema: z.ZodObject<{
|
|
436
667
|
thresholds: z.ZodArray<z.ZodNumber, "many">;
|
|
437
668
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -441,13 +672,22 @@ declare const scrollDepthConfigSchema: z.ZodObject<{
|
|
|
441
672
|
}>;
|
|
442
673
|
type ScrollDepthConfig = z.infer<typeof scrollDepthConfigSchema>;
|
|
443
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Canonical page intent names supported by `specific_page_visit`.
|
|
677
|
+
*/
|
|
444
678
|
declare const SPECIFIC_PAGE_NAMES: readonly ["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"];
|
|
445
679
|
type SpecificPageName = (typeof SPECIFIC_PAGE_NAMES)[number];
|
|
680
|
+
/**
|
|
681
|
+
* Metadata for the automatic `specific_page_visit` event.
|
|
682
|
+
*
|
|
683
|
+
* The SDK emits this when the current pathname matches one of the configured
|
|
684
|
+
* named page patterns.
|
|
685
|
+
*/
|
|
446
686
|
declare const specificPageVisitMetadataSchema: z.ZodObject<{
|
|
447
687
|
page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
448
688
|
page: z.ZodObject<{
|
|
449
689
|
path: z.ZodString;
|
|
450
|
-
}, "
|
|
690
|
+
}, "strict", z.ZodTypeAny, {
|
|
451
691
|
path: string;
|
|
452
692
|
}, {
|
|
453
693
|
path: string;
|
|
@@ -464,11 +704,17 @@ declare const specificPageVisitMetadataSchema: z.ZodObject<{
|
|
|
464
704
|
page_name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
|
|
465
705
|
}>;
|
|
466
706
|
type SpecificPageVisitMetadata = z.infer<typeof specificPageVisitMetadataSchema>;
|
|
707
|
+
/**
|
|
708
|
+
* Registration config for automatic `specific_page_visit`.
|
|
709
|
+
*
|
|
710
|
+
* Each page entry pairs a semantic `name` with a `RegExp` that matches the
|
|
711
|
+
* pathname. Use this instead of hard-coding path regexes downstream.
|
|
712
|
+
*/
|
|
467
713
|
declare const specificPageVisitConfigSchema: z.ZodObject<{
|
|
468
714
|
pages: z.ZodArray<z.ZodObject<{
|
|
469
715
|
name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
470
716
|
pathPattern: z.ZodType<RegExp, z.ZodTypeDef, RegExp>;
|
|
471
|
-
}, "
|
|
717
|
+
}, "strict", z.ZodTypeAny, {
|
|
472
718
|
name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
|
|
473
719
|
pathPattern: RegExp;
|
|
474
720
|
}, {
|
|
@@ -488,11 +734,17 @@ declare const specificPageVisitConfigSchema: z.ZodObject<{
|
|
|
488
734
|
}>;
|
|
489
735
|
type SpecificPageVisitConfig = z.infer<typeof specificPageVisitConfigSchema>;
|
|
490
736
|
|
|
737
|
+
/**
|
|
738
|
+
* Metadata for the automatic `time_on_site` event.
|
|
739
|
+
*
|
|
740
|
+
* The SDK starts a visibility-aware timer and fires once when visible
|
|
741
|
+
* engagement crosses the configured threshold.
|
|
742
|
+
*/
|
|
491
743
|
declare const timeOnSiteMetadataSchema: z.ZodObject<{
|
|
492
744
|
duration_ms: z.ZodNumber;
|
|
493
745
|
page: z.ZodObject<{
|
|
494
746
|
path: z.ZodString;
|
|
495
|
-
}, "
|
|
747
|
+
}, "strict", z.ZodTypeAny, {
|
|
496
748
|
path: string;
|
|
497
749
|
}, {
|
|
498
750
|
path: string;
|
|
@@ -509,6 +761,9 @@ declare const timeOnSiteMetadataSchema: z.ZodObject<{
|
|
|
509
761
|
duration_ms: number;
|
|
510
762
|
}>;
|
|
511
763
|
type TimeOnSiteMetadata = z.infer<typeof timeOnSiteMetadataSchema>;
|
|
764
|
+
/**
|
|
765
|
+
* Registration config for automatic `time_on_site`.
|
|
766
|
+
*/
|
|
512
767
|
declare const timeOnSiteConfigSchema: z.ZodObject<{
|
|
513
768
|
thresholdSeconds: z.ZodNumber;
|
|
514
769
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -527,7 +782,7 @@ declare const EVENT_REGISTRY: {
|
|
|
527
782
|
path: z.ZodString;
|
|
528
783
|
search: z.ZodString;
|
|
529
784
|
hash: z.ZodString;
|
|
530
|
-
}, "
|
|
785
|
+
}, "strict", z.ZodTypeAny, {
|
|
531
786
|
search: string;
|
|
532
787
|
title: string | null;
|
|
533
788
|
path: string;
|
|
@@ -542,7 +797,7 @@ declare const EVENT_REGISTRY: {
|
|
|
542
797
|
viewport: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
543
798
|
w: z.ZodNumber;
|
|
544
799
|
h: z.ZodNumber;
|
|
545
|
-
}, "
|
|
800
|
+
}, "strict", z.ZodTypeAny, {
|
|
546
801
|
w: number;
|
|
547
802
|
h: number;
|
|
548
803
|
}, {
|
|
@@ -582,7 +837,7 @@ declare const EVENT_REGISTRY: {
|
|
|
582
837
|
duration_ms: z.ZodNumber;
|
|
583
838
|
page: z.ZodObject<{
|
|
584
839
|
path: z.ZodString;
|
|
585
|
-
}, "
|
|
840
|
+
}, "strict", z.ZodTypeAny, {
|
|
586
841
|
path: string;
|
|
587
842
|
}, {
|
|
588
843
|
path: string;
|
|
@@ -612,7 +867,7 @@ declare const EVENT_REGISTRY: {
|
|
|
612
867
|
page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
613
868
|
page: z.ZodObject<{
|
|
614
869
|
path: z.ZodString;
|
|
615
|
-
}, "
|
|
870
|
+
}, "strict", z.ZodTypeAny, {
|
|
616
871
|
path: string;
|
|
617
872
|
}, {
|
|
618
873
|
path: string;
|
|
@@ -632,7 +887,7 @@ declare const EVENT_REGISTRY: {
|
|
|
632
887
|
pages: z.ZodArray<z.ZodObject<{
|
|
633
888
|
name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
634
889
|
pathPattern: z.ZodType<RegExp, z.ZodTypeDef, RegExp>;
|
|
635
|
-
}, "
|
|
890
|
+
}, "strict", z.ZodTypeAny, {
|
|
636
891
|
name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
|
|
637
892
|
pathPattern: RegExp;
|
|
638
893
|
}, {
|
|
@@ -657,7 +912,7 @@ declare const EVENT_REGISTRY: {
|
|
|
657
912
|
depth_percent: z.ZodNumber;
|
|
658
913
|
page: z.ZodObject<{
|
|
659
914
|
path: z.ZodString;
|
|
660
|
-
}, "
|
|
915
|
+
}, "strict", z.ZodTypeAny, {
|
|
661
916
|
path: string;
|
|
662
917
|
}, {
|
|
663
918
|
path: string;
|
|
@@ -687,7 +942,7 @@ declare const EVENT_REGISTRY: {
|
|
|
687
942
|
page_count: z.ZodNumber;
|
|
688
943
|
page: z.ZodObject<{
|
|
689
944
|
path: z.ZodString;
|
|
690
|
-
}, "
|
|
945
|
+
}, "strict", z.ZodTypeAny, {
|
|
691
946
|
path: string;
|
|
692
947
|
}, {
|
|
693
948
|
path: string;
|
|
@@ -717,7 +972,7 @@ declare const EVENT_REGISTRY: {
|
|
|
717
972
|
form: z.ZodObject<{
|
|
718
973
|
id: z.ZodString;
|
|
719
974
|
action: z.ZodNullable<z.ZodString>;
|
|
720
|
-
}, "
|
|
975
|
+
}, "strict", z.ZodTypeAny, {
|
|
721
976
|
id: string;
|
|
722
977
|
action: string | null;
|
|
723
978
|
}, {
|
|
@@ -726,7 +981,7 @@ declare const EVENT_REGISTRY: {
|
|
|
726
981
|
}>;
|
|
727
982
|
page: z.ZodObject<{
|
|
728
983
|
path: z.ZodString;
|
|
729
|
-
}, "
|
|
984
|
+
}, "strict", z.ZodTypeAny, {
|
|
730
985
|
path: string;
|
|
731
986
|
}, {
|
|
732
987
|
path: string;
|
|
@@ -804,40 +1059,40 @@ declare const EVENT_REGISTRY: {
|
|
|
804
1059
|
name: z.ZodString;
|
|
805
1060
|
type: z.ZodString;
|
|
806
1061
|
label: z.ZodNullable<z.ZodString>;
|
|
807
|
-
|
|
808
|
-
}, "
|
|
1062
|
+
value: z.ZodType<src.JsonValue, z.ZodTypeDef, src.JsonValue>;
|
|
1063
|
+
}, "strict", z.ZodTypeAny, {
|
|
809
1064
|
label: string | null;
|
|
1065
|
+
value: src.JsonValue;
|
|
810
1066
|
type: string;
|
|
811
1067
|
name: string;
|
|
812
|
-
has_value: boolean;
|
|
813
1068
|
}, {
|
|
814
1069
|
label: string | null;
|
|
1070
|
+
value: src.JsonValue;
|
|
815
1071
|
type: string;
|
|
816
1072
|
name: string;
|
|
817
|
-
has_value: boolean;
|
|
818
1073
|
}>, "many">>;
|
|
819
|
-
}, "
|
|
1074
|
+
}, "strict", z.ZodTypeAny, {
|
|
820
1075
|
id: string;
|
|
821
1076
|
action: string | null;
|
|
822
1077
|
fields?: {
|
|
823
1078
|
label: string | null;
|
|
1079
|
+
value: src.JsonValue;
|
|
824
1080
|
type: string;
|
|
825
1081
|
name: string;
|
|
826
|
-
has_value: boolean;
|
|
827
1082
|
}[] | undefined;
|
|
828
1083
|
}, {
|
|
829
1084
|
id: string;
|
|
830
1085
|
action: string | null;
|
|
831
1086
|
fields?: {
|
|
832
1087
|
label: string | null;
|
|
1088
|
+
value: src.JsonValue;
|
|
833
1089
|
type: string;
|
|
834
1090
|
name: string;
|
|
835
|
-
has_value: boolean;
|
|
836
1091
|
}[] | undefined;
|
|
837
1092
|
}>;
|
|
838
1093
|
page: z.ZodObject<{
|
|
839
1094
|
path: z.ZodString;
|
|
840
|
-
}, "
|
|
1095
|
+
}, "strict", z.ZodTypeAny, {
|
|
841
1096
|
path: string;
|
|
842
1097
|
}, {
|
|
843
1098
|
path: string;
|
|
@@ -848,9 +1103,9 @@ declare const EVENT_REGISTRY: {
|
|
|
848
1103
|
action: string | null;
|
|
849
1104
|
fields?: {
|
|
850
1105
|
label: string | null;
|
|
1106
|
+
value: src.JsonValue;
|
|
851
1107
|
type: string;
|
|
852
1108
|
name: string;
|
|
853
|
-
has_value: boolean;
|
|
854
1109
|
}[] | undefined;
|
|
855
1110
|
};
|
|
856
1111
|
page: {
|
|
@@ -862,9 +1117,9 @@ declare const EVENT_REGISTRY: {
|
|
|
862
1117
|
action: string | null;
|
|
863
1118
|
fields?: {
|
|
864
1119
|
label: string | null;
|
|
1120
|
+
value: src.JsonValue;
|
|
865
1121
|
type: string;
|
|
866
1122
|
name: string;
|
|
867
|
-
has_value: boolean;
|
|
868
1123
|
}[] | undefined;
|
|
869
1124
|
};
|
|
870
1125
|
page: {
|
|
@@ -879,7 +1134,7 @@ declare const EVENT_REGISTRY: {
|
|
|
879
1134
|
phone_number: z.ZodString;
|
|
880
1135
|
page: z.ZodObject<{
|
|
881
1136
|
path: z.ZodString;
|
|
882
|
-
}, "
|
|
1137
|
+
}, "strict", z.ZodTypeAny, {
|
|
883
1138
|
path: string;
|
|
884
1139
|
}, {
|
|
885
1140
|
path: string;
|
|
@@ -906,7 +1161,7 @@ declare const EVENT_REGISTRY: {
|
|
|
906
1161
|
cta_name: z.ZodString;
|
|
907
1162
|
page: z.ZodObject<{
|
|
908
1163
|
path: z.ZodString;
|
|
909
|
-
}, "
|
|
1164
|
+
}, "strict", z.ZodTypeAny, {
|
|
910
1165
|
path: string;
|
|
911
1166
|
}, {
|
|
912
1167
|
path: string;
|
|
@@ -931,10 +1186,21 @@ declare const EVENT_REGISTRY: {
|
|
|
931
1186
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
932
1187
|
};
|
|
933
1188
|
};
|
|
1189
|
+
/**
|
|
1190
|
+
* Name of any event known to the tracking SDK.
|
|
1191
|
+
*/
|
|
934
1192
|
type EventName = keyof typeof EVENT_REGISTRY;
|
|
1193
|
+
/**
|
|
1194
|
+
* Event names that are fired by the SDK when their configured signal occurs.
|
|
1195
|
+
*
|
|
1196
|
+
* Automatic events are not accepted by the typed `trackEvent()` API.
|
|
1197
|
+
*/
|
|
935
1198
|
type AutomaticEventName = {
|
|
936
1199
|
[K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'automatic' ? K : never;
|
|
937
1200
|
}[EventName];
|
|
1201
|
+
/**
|
|
1202
|
+
* Event names that consumer code can fire manually after registering them.
|
|
1203
|
+
*/
|
|
938
1204
|
type ManualEventName = {
|
|
939
1205
|
[K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'manual' ? K : never;
|
|
940
1206
|
}[EventName];
|
|
@@ -962,8 +1228,44 @@ type ConfigByName = {
|
|
|
962
1228
|
phone_click: PhoneClickConfig;
|
|
963
1229
|
cta_click: CtaClickConfig;
|
|
964
1230
|
};
|
|
1231
|
+
/**
|
|
1232
|
+
* Metadata payload type for a specific tracking event.
|
|
1233
|
+
*
|
|
1234
|
+
* @example
|
|
1235
|
+
* ```ts
|
|
1236
|
+
* type SubmitMetadata = EventMetadata<'form_submit'>;
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
965
1239
|
type EventMetadata<K extends EventName> = MetadataByName[K];
|
|
1240
|
+
/**
|
|
1241
|
+
* Trigger registration config type for a specific tracking event.
|
|
1242
|
+
*/
|
|
966
1243
|
type EventConfig<K extends EventName> = ConfigByName[K];
|
|
1244
|
+
/**
|
|
1245
|
+
* Trigger registry passed to `createTracking({ triggers })`.
|
|
1246
|
+
*
|
|
1247
|
+
* `automatic.page_view` is required because every install should capture page
|
|
1248
|
+
* views. Other automatic events are opt-in. Manual events must be registered
|
|
1249
|
+
* here before the typed client accepts `trackEvent()` calls for them.
|
|
1250
|
+
*
|
|
1251
|
+
* @example
|
|
1252
|
+
* ```ts
|
|
1253
|
+
* createTracking({
|
|
1254
|
+
* apiKey,
|
|
1255
|
+
* endpoint,
|
|
1256
|
+
* triggers: {
|
|
1257
|
+
* automatic: {
|
|
1258
|
+
* page_view: {},
|
|
1259
|
+
* time_on_site: { thresholdSeconds: 60 },
|
|
1260
|
+
* },
|
|
1261
|
+
* manual: {
|
|
1262
|
+
* form_submit: {},
|
|
1263
|
+
* phone_click: {},
|
|
1264
|
+
* },
|
|
1265
|
+
* },
|
|
1266
|
+
* });
|
|
1267
|
+
* ```
|
|
1268
|
+
*/
|
|
967
1269
|
type TriggerRegistryConfig = {
|
|
968
1270
|
automatic: {
|
|
969
1271
|
page_view: EventConfig<'page_view'>;
|
|
@@ -980,29 +1282,70 @@ type TriggerRegistryConfig = {
|
|
|
980
1282
|
cta_click: EventConfig<'cta_click'>;
|
|
981
1283
|
}>;
|
|
982
1284
|
};
|
|
1285
|
+
/**
|
|
1286
|
+
* Manual event names registered in a concrete trigger registry.
|
|
1287
|
+
*
|
|
1288
|
+
* Used by `TypedTrackingClient` so `trackEvent()` only accepts events the
|
|
1289
|
+
* consumer explicitly enabled.
|
|
1290
|
+
*/
|
|
983
1291
|
type RegisteredManualEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof NonNullable<TRegistry['manual']>, ManualEventName>;
|
|
1292
|
+
/**
|
|
1293
|
+
* Automatic event names registered in a concrete trigger registry.
|
|
1294
|
+
*/
|
|
984
1295
|
type RegisteredAutomaticEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof TRegistry['automatic'], AutomaticEventName>;
|
|
985
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* Input accepted by the low-level stringly-typed client.
|
|
1299
|
+
*
|
|
1300
|
+
* Prefer the typed `trackEvent(eventName, metadata)` facade exposed by
|
|
1301
|
+
* `useTracking()` in React/Next integrations.
|
|
1302
|
+
*/
|
|
986
1303
|
interface TrackEventInput {
|
|
1304
|
+
/** Event name to enqueue. */
|
|
987
1305
|
eventType: string;
|
|
1306
|
+
/** URL associated with the event. Defaults to the current page URL. */
|
|
988
1307
|
pageUrl?: string | null;
|
|
1308
|
+
/** Event-specific metadata. */
|
|
989
1309
|
metadata?: Record<string, unknown> | null;
|
|
1310
|
+
/** Timestamp override. Defaults to queue time. */
|
|
990
1311
|
occurredAt?: Date | string | null;
|
|
991
1312
|
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Low-level tracking client responsible for queueing and flushing events.
|
|
1315
|
+
*/
|
|
992
1316
|
interface TrackingClient {
|
|
1317
|
+
/** Enqueue an event for batched delivery. */
|
|
993
1318
|
trackEvent: (input: TrackEventInput) => void;
|
|
1319
|
+
/** Flush queued events immediately. */
|
|
994
1320
|
flush: () => Promise<void>;
|
|
1321
|
+
/** Return the current rolling session id. */
|
|
995
1322
|
getSessionId: () => string;
|
|
1323
|
+
/** Return the persistent visitor id. */
|
|
996
1324
|
getVisitorId: () => string;
|
|
1325
|
+
/** Remove timers/listeners and prevent future flushes. */
|
|
997
1326
|
destroy: () => void;
|
|
998
1327
|
}
|
|
999
1328
|
|
|
1000
1329
|
interface TypedTrackEventOptions {
|
|
1001
|
-
/**
|
|
1330
|
+
/**
|
|
1331
|
+
* Override the page URL associated with this event.
|
|
1332
|
+
*
|
|
1333
|
+
* Omit this for normal browser usage; the SDK captures `window.location.href`.
|
|
1334
|
+
*/
|
|
1002
1335
|
pageUrl?: string | null;
|
|
1003
|
-
/**
|
|
1336
|
+
/**
|
|
1337
|
+
* Override the event timestamp.
|
|
1338
|
+
*
|
|
1339
|
+
* Defaults to the time the event is queued. Accepts a `Date` or ISO string.
|
|
1340
|
+
*/
|
|
1004
1341
|
occurredAt?: Date | string | null;
|
|
1005
1342
|
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Typed tracking client returned by `useTracking()`.
|
|
1345
|
+
*
|
|
1346
|
+
* The accepted event names and metadata shapes are narrowed from the concrete
|
|
1347
|
+
* trigger registry supplied to `createTracking()`.
|
|
1348
|
+
*/
|
|
1006
1349
|
interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
1007
1350
|
/**
|
|
1008
1351
|
* Fire a manually-registered event. The event name must be present in
|
|
@@ -1010,19 +1353,54 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1010
1353
|
* canonical Zod-derived shape.
|
|
1011
1354
|
*/
|
|
1012
1355
|
trackEvent<K extends RegisteredManualEvents<TRegistry>>(eventType: K, metadata: EventMetadata<K>, options?: TypedTrackEventOptions): void;
|
|
1356
|
+
/**
|
|
1357
|
+
* Immediately flush queued events to the ingest endpoint.
|
|
1358
|
+
*
|
|
1359
|
+
* Normal consumers rarely need this because the SDK flushes on a debounce,
|
|
1360
|
+
* when the queue reaches the batch threshold, and on `pagehide`.
|
|
1361
|
+
*/
|
|
1013
1362
|
flush(): Promise<void>;
|
|
1363
|
+
/**
|
|
1364
|
+
* Return the current rolling session id.
|
|
1365
|
+
*/
|
|
1014
1366
|
getSessionId(): string;
|
|
1367
|
+
/**
|
|
1368
|
+
* Return the persistent visitor id for this browser profile.
|
|
1369
|
+
*/
|
|
1015
1370
|
getVisitorId(): string;
|
|
1016
1371
|
}
|
|
1017
1372
|
|
|
1373
|
+
/**
|
|
1374
|
+
* Read the captured Google Ads click id from first-party cookies.
|
|
1375
|
+
*
|
|
1376
|
+
* Returns `null` during SSR and before the client has mounted.
|
|
1377
|
+
*/
|
|
1018
1378
|
declare function useGclid(): string | null;
|
|
1379
|
+
/**
|
|
1380
|
+
* Read all captured attribution parameters from first-party cookies.
|
|
1381
|
+
*
|
|
1382
|
+
* Values are loaded after mount, so the initial render returns all `null`s.
|
|
1383
|
+
*/
|
|
1019
1384
|
declare function useTrackingParams(): TrackingParams;
|
|
1385
|
+
/**
|
|
1386
|
+
* Read the current visitor consent state and update when another tab changes
|
|
1387
|
+
* the stored value.
|
|
1388
|
+
*/
|
|
1020
1389
|
declare function useConsentState(): ConsentState;
|
|
1021
1390
|
|
|
1022
1391
|
interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
1023
|
-
/**
|
|
1392
|
+
/**
|
|
1393
|
+
* Public tracking API key issued for this business.
|
|
1394
|
+
*
|
|
1395
|
+
* This key is safe to expose in browser code. Abuse is bounded by the
|
|
1396
|
+
* server-side origin allowlist and rate limits.
|
|
1397
|
+
*/
|
|
1024
1398
|
apiKey: string;
|
|
1025
|
-
/**
|
|
1399
|
+
/**
|
|
1400
|
+
* Tracking endpoint base URL, usually ending in `/tracking`.
|
|
1401
|
+
*
|
|
1402
|
+
* The client posts events to `${endpoint}/events`.
|
|
1403
|
+
*/
|
|
1026
1404
|
endpoint: string;
|
|
1027
1405
|
/**
|
|
1028
1406
|
* Trigger registry. Determines which events the SDK fires automatically
|
|
@@ -1038,14 +1416,32 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1038
1416
|
debug?: boolean;
|
|
1039
1417
|
}
|
|
1040
1418
|
interface TrackingProviderProps {
|
|
1041
|
-
/**
|
|
1419
|
+
/**
|
|
1420
|
+
* Optional Google Ads tag id, for example `AW-123456789`.
|
|
1421
|
+
*
|
|
1422
|
+
* If omitted, no gtag script is loaded by the provider.
|
|
1423
|
+
*/
|
|
1042
1424
|
gtagId?: string;
|
|
1425
|
+
/**
|
|
1426
|
+
* Application tree that should have access to the scoped tracking client.
|
|
1427
|
+
*/
|
|
1043
1428
|
children: ReactNode;
|
|
1044
1429
|
}
|
|
1045
1430
|
interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
|
|
1431
|
+
/**
|
|
1432
|
+
* Provider component that initializes the page-level tracking client.
|
|
1433
|
+
*
|
|
1434
|
+
* Mount this once near the root of the React tree.
|
|
1435
|
+
*/
|
|
1046
1436
|
TrackingProvider: (props: TrackingProviderProps) => ReactNode;
|
|
1437
|
+
/**
|
|
1438
|
+
* Hook that returns the registry-typed tracking client.
|
|
1439
|
+
*
|
|
1440
|
+
* Import this hook from your local tracking module, not directly from the
|
|
1441
|
+
* package root, so TypeScript preserves your trigger registry.
|
|
1442
|
+
*/
|
|
1047
1443
|
useTracking: () => TypedTrackingClient<TRegistry>;
|
|
1048
1444
|
}
|
|
1049
1445
|
declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
|
|
1050
1446
|
|
|
1051
|
-
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 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 };
|
|
1447
|
+
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 };
|