@aranova/tracking-react 0.6.0 → 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/dist/index.d.mts +397 -5
- package/dist/index.d.ts +397 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,34 +3,92 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import * as src from 'src';
|
|
4
4
|
import { z } from 'zod';
|
|
5
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
|
+
*/
|
|
6
12
|
declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
|
|
7
13
|
|
|
8
14
|
interface GoogleAdsTrackingProps {
|
|
15
|
+
/**
|
|
16
|
+
* Google Ads tag id, for example `AW-123456789`.
|
|
17
|
+
*/
|
|
9
18
|
gtagId: string;
|
|
10
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
|
+
*/
|
|
11
26
|
declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): null;
|
|
12
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
|
+
*/
|
|
13
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
|
+
*/
|
|
14
42
|
interface TrackingParams {
|
|
43
|
+
/** Google Ads click id. */
|
|
15
44
|
gclid: string | null;
|
|
45
|
+
/** Meta/Facebook click id. */
|
|
16
46
|
fbclid: string | null;
|
|
47
|
+
/** UTM source, for example `google` or `newsletter`. */
|
|
17
48
|
utm_source: string | null;
|
|
49
|
+
/** UTM medium, for example `cpc` or `email`. */
|
|
18
50
|
utm_medium: string | null;
|
|
51
|
+
/** UTM campaign name. */
|
|
19
52
|
utm_campaign: string | null;
|
|
53
|
+
/** UTM paid-search term. */
|
|
20
54
|
utm_term: string | null;
|
|
55
|
+
/** UTM content/ad creative label. */
|
|
21
56
|
utm_content: string | null;
|
|
22
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
|
+
*/
|
|
23
64
|
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
65
|
+
/**
|
|
66
|
+
* Runtime context attached to tracking sessions and events.
|
|
67
|
+
*/
|
|
24
68
|
interface TrackingClientContext {
|
|
69
|
+
/** Install surface that created the client. */
|
|
25
70
|
surface: TrackingInstallSurface;
|
|
71
|
+
/** Package version, when available. */
|
|
26
72
|
sdk_version: string | null;
|
|
73
|
+
/** Package name, for example `@aranova/tracking-react`. */
|
|
27
74
|
package_name: string | null;
|
|
75
|
+
/** Browser origin of the tracked site. */
|
|
28
76
|
site_origin: string | null;
|
|
77
|
+
/** Current document title at client creation time. */
|
|
29
78
|
page_title: string | null;
|
|
79
|
+
/** Browser document referrer at client creation time. */
|
|
30
80
|
referrer: string | null;
|
|
31
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
|
+
*/
|
|
32
88
|
interface TrackingSessionUpsertPayload {
|
|
89
|
+
/** Rolling 30-minute client-side session id. */
|
|
33
90
|
session_id: string;
|
|
91
|
+
/** Persistent client-side visitor id. */
|
|
34
92
|
visitor_id: string | null;
|
|
35
93
|
gclid: string | null;
|
|
36
94
|
fbclid: string | null;
|
|
@@ -43,22 +101,39 @@ interface TrackingSessionUpsertPayload {
|
|
|
43
101
|
consent_state: Record<string, unknown> | null;
|
|
44
102
|
context: TrackingClientContext;
|
|
45
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Event payload shape before batching into the ingest request.
|
|
106
|
+
*/
|
|
46
107
|
interface TrackingEventCreatePayload {
|
|
108
|
+
/** Session id that logically owns the event. */
|
|
47
109
|
session_id: string;
|
|
110
|
+
/** Registered event name, for example `page_view` or `form_submit`. */
|
|
48
111
|
event_type: string;
|
|
49
112
|
gclid: string | null;
|
|
50
113
|
fbclid: string | null;
|
|
114
|
+
/** Full page URL associated with the event, if known. */
|
|
51
115
|
page_url: string | null;
|
|
116
|
+
/** Event-specific metadata. Runtime shape depends on `event_type`. */
|
|
52
117
|
metadata: Record<string, unknown> | null;
|
|
53
118
|
context: TrackingClientContext;
|
|
54
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Browser-script initialization config passed to `window.AranovaTracking.init()`.
|
|
122
|
+
*/
|
|
55
123
|
interface TrackingInitConfig {
|
|
124
|
+
/** Public tracking API key issued from the Aranova dashboard. */
|
|
56
125
|
apiKey?: string;
|
|
126
|
+
/** Tracking endpoint base URL, usually ending in `/tracking`. */
|
|
57
127
|
endpoint?: string;
|
|
128
|
+
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
58
129
|
gtagId?: string;
|
|
130
|
+
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
59
131
|
autoCaptureTrackingParams?: boolean;
|
|
132
|
+
/** Whether the browser script should inject the default consent banner. */
|
|
60
133
|
renderConsentBanner?: boolean;
|
|
134
|
+
/** Attribution cookie max age in seconds. Defaults to 90 days. */
|
|
61
135
|
cookieMaxAgeSeconds?: number;
|
|
136
|
+
/** Override the install surface reported in payload context. */
|
|
62
137
|
surface?: TrackingInstallSurface;
|
|
63
138
|
}
|
|
64
139
|
declare global {
|
|
@@ -76,8 +151,21 @@ declare global {
|
|
|
76
151
|
}
|
|
77
152
|
}
|
|
78
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
|
|
156
|
+
*/
|
|
79
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
|
+
*/
|
|
80
164
|
declare function getConsentState(): ConsentState;
|
|
165
|
+
/**
|
|
166
|
+
* Persist a visitor consent choice and update Google Consent Mode when gtag is
|
|
167
|
+
* loaded.
|
|
168
|
+
*/
|
|
81
169
|
declare function setConsentState(state: GtagConsentValue): void;
|
|
82
170
|
|
|
83
171
|
interface TrackingContextInput {
|
|
@@ -99,13 +187,37 @@ interface TrackingSessionInput {
|
|
|
99
187
|
sessionId: string;
|
|
100
188
|
visitorId?: string | null;
|
|
101
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Build runtime context attached to tracking sessions and events.
|
|
192
|
+
*/
|
|
102
193
|
declare function createTrackingClientContext(surface: TrackingInstallSurface, input?: TrackingContextInput): TrackingClientContext;
|
|
194
|
+
/**
|
|
195
|
+
* Build the session portion of a tracking ingest request.
|
|
196
|
+
*/
|
|
103
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
|
+
*/
|
|
104
201
|
declare function createTrackingEventCreatePayload(trackingParams: TrackingParams, input: TrackingEventInput, context: TrackingClientContext): TrackingEventCreatePayload;
|
|
105
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Attribution query/cookie keys captured by the SDK.
|
|
205
|
+
*/
|
|
106
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
|
+
*/
|
|
107
213
|
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
108
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
|
+
*/
|
|
109
221
|
declare const ctaClickMetadataSchema: z.ZodObject<{
|
|
110
222
|
cta_name: z.ZodString;
|
|
111
223
|
page: z.ZodObject<{
|
|
@@ -133,9 +245,21 @@ declare const ctaClickMetadataSchema: z.ZodObject<{
|
|
|
133
245
|
destination_url?: string | null | undefined;
|
|
134
246
|
}>;
|
|
135
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
|
+
*/
|
|
136
253
|
declare const ctaClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
137
254
|
type CtaClickConfig = z.infer<typeof ctaClickConfigSchema>;
|
|
138
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
|
+
*/
|
|
139
263
|
declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
140
264
|
sdk_version: z.ZodString;
|
|
141
265
|
package_name: z.ZodNullable<z.ZodString>;
|
|
@@ -171,9 +295,19 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
|
|
|
171
295
|
trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
|
|
172
296
|
}>;
|
|
173
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
|
+
*/
|
|
174
303
|
declare const sdkHeartbeatConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
175
304
|
type SdkHeartbeatConfig = z.infer<typeof sdkHeartbeatConfigSchema>;
|
|
176
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
|
+
*/
|
|
177
311
|
declare const formStartMetadataSchema: z.ZodObject<{
|
|
178
312
|
form: z.ZodObject<{
|
|
179
313
|
id: z.ZodString;
|
|
@@ -210,6 +344,12 @@ declare const formStartMetadataSchema: z.ZodObject<{
|
|
|
210
344
|
};
|
|
211
345
|
}>;
|
|
212
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
|
+
*/
|
|
213
353
|
declare const formStartConfigSchema: z.ZodObject<{
|
|
214
354
|
selector: z.ZodOptional<z.ZodString>;
|
|
215
355
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -219,9 +359,46 @@ declare const formStartConfigSchema: z.ZodObject<{
|
|
|
219
359
|
}>;
|
|
220
360
|
type FormStartConfig = z.infer<typeof formStartConfigSchema>;
|
|
221
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
|
+
*/
|
|
222
369
|
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
223
370
|
[key: string]: JsonValue;
|
|
224
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
|
+
*/
|
|
225
402
|
declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
226
403
|
form: z.ZodObject<{
|
|
227
404
|
id: z.ZodString;
|
|
@@ -298,9 +475,21 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
|
298
475
|
};
|
|
299
476
|
}>;
|
|
300
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
|
+
*/
|
|
301
484
|
declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
302
485
|
type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
|
|
303
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
|
+
*/
|
|
304
493
|
declare const multiPageSessionMetadataSchema: z.ZodObject<{
|
|
305
494
|
page_count: z.ZodNumber;
|
|
306
495
|
page: z.ZodObject<{
|
|
@@ -322,6 +511,9 @@ declare const multiPageSessionMetadataSchema: z.ZodObject<{
|
|
|
322
511
|
page_count: number;
|
|
323
512
|
}>;
|
|
324
513
|
type MultiPageSessionMetadata = z.infer<typeof multiPageSessionMetadataSchema>;
|
|
514
|
+
/**
|
|
515
|
+
* Registration config for automatic `multi_page_session`.
|
|
516
|
+
*/
|
|
325
517
|
declare const multiPageSessionConfigSchema: z.ZodObject<{
|
|
326
518
|
pageThreshold: z.ZodNumber;
|
|
327
519
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -331,6 +523,13 @@ declare const multiPageSessionConfigSchema: z.ZodObject<{
|
|
|
331
523
|
}>;
|
|
332
524
|
type MultiPageSessionConfig = z.infer<typeof multiPageSessionConfigSchema>;
|
|
333
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
|
+
*/
|
|
334
533
|
declare const pageViewMetadataSchema: z.ZodObject<{
|
|
335
534
|
page: z.ZodObject<{
|
|
336
535
|
title: z.ZodNullable<z.ZodString>;
|
|
@@ -385,9 +584,22 @@ declare const pageViewMetadataSchema: z.ZodObject<{
|
|
|
385
584
|
} | null | undefined;
|
|
386
585
|
}>;
|
|
387
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
|
+
*/
|
|
388
593
|
declare const pageViewConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
389
594
|
type PageViewConfig = z.infer<typeof pageViewConfigSchema>;
|
|
390
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
|
+
*/
|
|
391
603
|
declare const phoneClickMetadataSchema: z.ZodObject<{
|
|
392
604
|
phone_number: z.ZodString;
|
|
393
605
|
page: z.ZodObject<{
|
|
@@ -412,9 +624,19 @@ declare const phoneClickMetadataSchema: z.ZodObject<{
|
|
|
412
624
|
section?: string | null | undefined;
|
|
413
625
|
}>;
|
|
414
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
|
+
*/
|
|
415
632
|
declare const phoneClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
416
633
|
type PhoneClickConfig = z.infer<typeof phoneClickConfigSchema>;
|
|
417
634
|
|
|
635
|
+
/**
|
|
636
|
+
* Metadata for the automatic `scroll_depth` event.
|
|
637
|
+
*
|
|
638
|
+
* Fired once per configured threshold per page.
|
|
639
|
+
*/
|
|
418
640
|
declare const scrollDepthMetadataSchema: z.ZodObject<{
|
|
419
641
|
depth_percent: z.ZodNumber;
|
|
420
642
|
page: z.ZodObject<{
|
|
@@ -436,6 +658,11 @@ declare const scrollDepthMetadataSchema: z.ZodObject<{
|
|
|
436
658
|
depth_percent: number;
|
|
437
659
|
}>;
|
|
438
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
|
+
*/
|
|
439
666
|
declare const scrollDepthConfigSchema: z.ZodObject<{
|
|
440
667
|
thresholds: z.ZodArray<z.ZodNumber, "many">;
|
|
441
668
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -445,8 +672,17 @@ declare const scrollDepthConfigSchema: z.ZodObject<{
|
|
|
445
672
|
}>;
|
|
446
673
|
type ScrollDepthConfig = z.infer<typeof scrollDepthConfigSchema>;
|
|
447
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Canonical page intent names supported by `specific_page_visit`.
|
|
677
|
+
*/
|
|
448
678
|
declare const SPECIFIC_PAGE_NAMES: readonly ["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"];
|
|
449
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
|
+
*/
|
|
450
686
|
declare const specificPageVisitMetadataSchema: z.ZodObject<{
|
|
451
687
|
page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
452
688
|
page: z.ZodObject<{
|
|
@@ -468,6 +704,12 @@ declare const specificPageVisitMetadataSchema: z.ZodObject<{
|
|
|
468
704
|
page_name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
|
|
469
705
|
}>;
|
|
470
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
|
+
*/
|
|
471
713
|
declare const specificPageVisitConfigSchema: z.ZodObject<{
|
|
472
714
|
pages: z.ZodArray<z.ZodObject<{
|
|
473
715
|
name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
|
|
@@ -492,6 +734,12 @@ declare const specificPageVisitConfigSchema: z.ZodObject<{
|
|
|
492
734
|
}>;
|
|
493
735
|
type SpecificPageVisitConfig = z.infer<typeof specificPageVisitConfigSchema>;
|
|
494
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
|
+
*/
|
|
495
743
|
declare const timeOnSiteMetadataSchema: z.ZodObject<{
|
|
496
744
|
duration_ms: z.ZodNumber;
|
|
497
745
|
page: z.ZodObject<{
|
|
@@ -513,6 +761,9 @@ declare const timeOnSiteMetadataSchema: z.ZodObject<{
|
|
|
513
761
|
duration_ms: number;
|
|
514
762
|
}>;
|
|
515
763
|
type TimeOnSiteMetadata = z.infer<typeof timeOnSiteMetadataSchema>;
|
|
764
|
+
/**
|
|
765
|
+
* Registration config for automatic `time_on_site`.
|
|
766
|
+
*/
|
|
516
767
|
declare const timeOnSiteConfigSchema: z.ZodObject<{
|
|
517
768
|
thresholdSeconds: z.ZodNumber;
|
|
518
769
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -935,10 +1186,21 @@ declare const EVENT_REGISTRY: {
|
|
|
935
1186
|
readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
936
1187
|
};
|
|
937
1188
|
};
|
|
1189
|
+
/**
|
|
1190
|
+
* Name of any event known to the tracking SDK.
|
|
1191
|
+
*/
|
|
938
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
|
+
*/
|
|
939
1198
|
type AutomaticEventName = {
|
|
940
1199
|
[K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'automatic' ? K : never;
|
|
941
1200
|
}[EventName];
|
|
1201
|
+
/**
|
|
1202
|
+
* Event names that consumer code can fire manually after registering them.
|
|
1203
|
+
*/
|
|
942
1204
|
type ManualEventName = {
|
|
943
1205
|
[K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'manual' ? K : never;
|
|
944
1206
|
}[EventName];
|
|
@@ -966,8 +1228,44 @@ type ConfigByName = {
|
|
|
966
1228
|
phone_click: PhoneClickConfig;
|
|
967
1229
|
cta_click: CtaClickConfig;
|
|
968
1230
|
};
|
|
1231
|
+
/**
|
|
1232
|
+
* Metadata payload type for a specific tracking event.
|
|
1233
|
+
*
|
|
1234
|
+
* @example
|
|
1235
|
+
* ```ts
|
|
1236
|
+
* type SubmitMetadata = EventMetadata<'form_submit'>;
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
969
1239
|
type EventMetadata<K extends EventName> = MetadataByName[K];
|
|
1240
|
+
/**
|
|
1241
|
+
* Trigger registration config type for a specific tracking event.
|
|
1242
|
+
*/
|
|
970
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
|
+
*/
|
|
971
1269
|
type TriggerRegistryConfig = {
|
|
972
1270
|
automatic: {
|
|
973
1271
|
page_view: EventConfig<'page_view'>;
|
|
@@ -984,29 +1282,70 @@ type TriggerRegistryConfig = {
|
|
|
984
1282
|
cta_click: EventConfig<'cta_click'>;
|
|
985
1283
|
}>;
|
|
986
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
|
+
*/
|
|
987
1291
|
type RegisteredManualEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof NonNullable<TRegistry['manual']>, ManualEventName>;
|
|
1292
|
+
/**
|
|
1293
|
+
* Automatic event names registered in a concrete trigger registry.
|
|
1294
|
+
*/
|
|
988
1295
|
type RegisteredAutomaticEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof TRegistry['automatic'], AutomaticEventName>;
|
|
989
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
|
+
*/
|
|
990
1303
|
interface TrackEventInput {
|
|
1304
|
+
/** Event name to enqueue. */
|
|
991
1305
|
eventType: string;
|
|
1306
|
+
/** URL associated with the event. Defaults to the current page URL. */
|
|
992
1307
|
pageUrl?: string | null;
|
|
1308
|
+
/** Event-specific metadata. */
|
|
993
1309
|
metadata?: Record<string, unknown> | null;
|
|
1310
|
+
/** Timestamp override. Defaults to queue time. */
|
|
994
1311
|
occurredAt?: Date | string | null;
|
|
995
1312
|
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Low-level tracking client responsible for queueing and flushing events.
|
|
1315
|
+
*/
|
|
996
1316
|
interface TrackingClient {
|
|
1317
|
+
/** Enqueue an event for batched delivery. */
|
|
997
1318
|
trackEvent: (input: TrackEventInput) => void;
|
|
1319
|
+
/** Flush queued events immediately. */
|
|
998
1320
|
flush: () => Promise<void>;
|
|
1321
|
+
/** Return the current rolling session id. */
|
|
999
1322
|
getSessionId: () => string;
|
|
1323
|
+
/** Return the persistent visitor id. */
|
|
1000
1324
|
getVisitorId: () => string;
|
|
1325
|
+
/** Remove timers/listeners and prevent future flushes. */
|
|
1001
1326
|
destroy: () => void;
|
|
1002
1327
|
}
|
|
1003
1328
|
|
|
1004
1329
|
interface TypedTrackEventOptions {
|
|
1005
|
-
/**
|
|
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
|
+
*/
|
|
1006
1335
|
pageUrl?: string | null;
|
|
1007
|
-
/**
|
|
1336
|
+
/**
|
|
1337
|
+
* Override the event timestamp.
|
|
1338
|
+
*
|
|
1339
|
+
* Defaults to the time the event is queued. Accepts a `Date` or ISO string.
|
|
1340
|
+
*/
|
|
1008
1341
|
occurredAt?: Date | string | null;
|
|
1009
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
|
+
*/
|
|
1010
1349
|
interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
1011
1350
|
/**
|
|
1012
1351
|
* Fire a manually-registered event. The event name must be present in
|
|
@@ -1014,19 +1353,54 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1014
1353
|
* canonical Zod-derived shape.
|
|
1015
1354
|
*/
|
|
1016
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
|
+
*/
|
|
1017
1362
|
flush(): Promise<void>;
|
|
1363
|
+
/**
|
|
1364
|
+
* Return the current rolling session id.
|
|
1365
|
+
*/
|
|
1018
1366
|
getSessionId(): string;
|
|
1367
|
+
/**
|
|
1368
|
+
* Return the persistent visitor id for this browser profile.
|
|
1369
|
+
*/
|
|
1019
1370
|
getVisitorId(): string;
|
|
1020
1371
|
}
|
|
1021
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
|
+
*/
|
|
1022
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
|
+
*/
|
|
1023
1384
|
declare function useTrackingParams(): TrackingParams;
|
|
1385
|
+
/**
|
|
1386
|
+
* Read the current visitor consent state and update when another tab changes
|
|
1387
|
+
* the stored value.
|
|
1388
|
+
*/
|
|
1024
1389
|
declare function useConsentState(): ConsentState;
|
|
1025
1390
|
|
|
1026
1391
|
interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
1027
|
-
/**
|
|
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
|
+
*/
|
|
1028
1398
|
apiKey: string;
|
|
1029
|
-
/**
|
|
1399
|
+
/**
|
|
1400
|
+
* Tracking endpoint base URL, usually ending in `/tracking`.
|
|
1401
|
+
*
|
|
1402
|
+
* The client posts events to `${endpoint}/events`.
|
|
1403
|
+
*/
|
|
1030
1404
|
endpoint: string;
|
|
1031
1405
|
/**
|
|
1032
1406
|
* Trigger registry. Determines which events the SDK fires automatically
|
|
@@ -1042,12 +1416,30 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
|
1042
1416
|
debug?: boolean;
|
|
1043
1417
|
}
|
|
1044
1418
|
interface TrackingProviderProps {
|
|
1045
|
-
/**
|
|
1419
|
+
/**
|
|
1420
|
+
* Optional Google Ads tag id, for example `AW-123456789`.
|
|
1421
|
+
*
|
|
1422
|
+
* If omitted, no gtag script is loaded by the provider.
|
|
1423
|
+
*/
|
|
1046
1424
|
gtagId?: string;
|
|
1425
|
+
/**
|
|
1426
|
+
* Application tree that should have access to the scoped tracking client.
|
|
1427
|
+
*/
|
|
1047
1428
|
children: ReactNode;
|
|
1048
1429
|
}
|
|
1049
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
|
+
*/
|
|
1050
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
|
+
*/
|
|
1051
1443
|
useTracking: () => TypedTrackingClient<TRegistry>;
|
|
1052
1444
|
}
|
|
1053
1445
|
declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
|
package/dist/index.js
CHANGED