@aranova/tracking-next 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/dist/index.d.ts CHANGED
@@ -1,11 +1,25 @@
1
- import { C as ConsentState, T as TrackingInstallSurface, a as TrackingClientContext, b as TrackingParams, c as TrackingEventCreatePayload, d as TrackingSessionUpsertPayload } from './types-Gp0ioRiQ.js';
2
- export { e as TrackingInitConfig } from './types-Gp0ioRiQ.js';
1
+ import { C as ConsentState, T as TrackingInstallSurface, a as TrackingClientContext, b as TrackingParams, c as TrackingEventCreatePayload, d as TrackingSessionUpsertPayload } from './types-B4VZHWnc.js';
2
+ export { e as TrackingInitConfig } from './types-B4VZHWnc.js';
3
3
  import { z } from 'zod';
4
+ import * as src from 'src';
4
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
  import { ReactNode } from 'react';
6
7
 
8
+ /**
9
+ * Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
10
+ */
7
11
  type GtagConsentValue = 'granted' | 'denied';
12
+ /**
13
+ * Read the persisted visitor consent state from localStorage.
14
+ *
15
+ * Returns `pending` when called during SSR or before the visitor has made a
16
+ * choice.
17
+ */
8
18
  declare function getConsentState(): ConsentState;
19
+ /**
20
+ * Persist a visitor consent choice and update Google Consent Mode when gtag is
21
+ * loaded.
22
+ */
9
23
  declare function setConsentState(state: GtagConsentValue): void;
10
24
 
11
25
  interface TrackingContextInput {
@@ -27,18 +41,42 @@ interface TrackingSessionInput {
27
41
  sessionId: string;
28
42
  visitorId?: string | null;
29
43
  }
44
+ /**
45
+ * Build runtime context attached to tracking sessions and events.
46
+ */
30
47
  declare function createTrackingClientContext(surface: TrackingInstallSurface, input?: TrackingContextInput): TrackingClientContext;
48
+ /**
49
+ * Build the session portion of a tracking ingest request.
50
+ */
31
51
  declare function createTrackingSessionUpsertPayload(trackingParams: TrackingParams, input: TrackingSessionInput, context: TrackingClientContext): TrackingSessionUpsertPayload;
52
+ /**
53
+ * Build one event payload before it is batched into a tracking ingest request.
54
+ */
32
55
  declare function createTrackingEventCreatePayload(trackingParams: TrackingParams, input: TrackingEventInput, context: TrackingClientContext): TrackingEventCreatePayload;
33
56
 
57
+ /**
58
+ * Attribution query/cookie keys captured by the SDK.
59
+ */
34
60
  declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
61
+ /**
62
+ * Capture tracking params from a URL, persist them to first-party cookies, and
63
+ * return the current cookie-backed attribution state.
64
+ *
65
+ * Defaults to `window.location.href` in the browser.
66
+ */
35
67
  declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
36
68
 
69
+ /**
70
+ * Metadata for a manually fired `cta_click` event.
71
+ *
72
+ * Use this for non-phone calls to action such as directions, appointment
73
+ * buttons, downloads, or external booking links.
74
+ */
37
75
  declare const ctaClickMetadataSchema: z.ZodObject<{
38
76
  cta_name: z.ZodString;
39
77
  page: z.ZodObject<{
40
78
  path: z.ZodString;
41
- }, "strip", z.ZodTypeAny, {
79
+ }, "strict", z.ZodTypeAny, {
42
80
  path: string;
43
81
  }, {
44
82
  path: string;
@@ -61,9 +99,21 @@ declare const ctaClickMetadataSchema: z.ZodObject<{
61
99
  destination_url?: string | null | undefined;
62
100
  }>;
63
101
  type CtaClickMetadata = z.infer<typeof ctaClickMetadataSchema>;
102
+ /**
103
+ * Registration config for `cta_click`.
104
+ *
105
+ * This event is manual-only and currently has no registration options.
106
+ */
64
107
  declare const ctaClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
65
108
  type CtaClickConfig = z.infer<typeof ctaClickConfigSchema>;
66
109
 
110
+ /**
111
+ * Metadata for the SDK-internal `sdk_heartbeat` event.
112
+ *
113
+ * The SDK fires this once per new session so the dashboard can show which SDK
114
+ * version, install surface, and trigger registry a client site is running.
115
+ * Consumers do not manually register or fire this event.
116
+ */
67
117
  declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
68
118
  sdk_version: z.ZodString;
69
119
  package_name: z.ZodNullable<z.ZodString>;
@@ -99,14 +149,24 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
99
149
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
100
150
  }>;
101
151
  type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
152
+ /**
153
+ * Internal registration config for `sdk_heartbeat`.
154
+ *
155
+ * This event has no consumer-facing options.
156
+ */
102
157
  declare const sdkHeartbeatConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
103
158
  type SdkHeartbeatConfig = z.infer<typeof sdkHeartbeatConfigSchema>;
104
159
 
160
+ /**
161
+ * Metadata for the automatic `form_start` event.
162
+ *
163
+ * The SDK emits this once per form when the visitor first focuses a field.
164
+ */
105
165
  declare const formStartMetadataSchema: z.ZodObject<{
106
166
  form: z.ZodObject<{
107
167
  id: z.ZodString;
108
168
  action: z.ZodNullable<z.ZodString>;
109
- }, "strip", z.ZodTypeAny, {
169
+ }, "strict", z.ZodTypeAny, {
110
170
  id: string;
111
171
  action: string | null;
112
172
  }, {
@@ -115,7 +175,7 @@ declare const formStartMetadataSchema: z.ZodObject<{
115
175
  }>;
116
176
  page: z.ZodObject<{
117
177
  path: z.ZodString;
118
- }, "strip", z.ZodTypeAny, {
178
+ }, "strict", z.ZodTypeAny, {
119
179
  path: string;
120
180
  }, {
121
181
  path: string;
@@ -138,6 +198,12 @@ declare const formStartMetadataSchema: z.ZodObject<{
138
198
  };
139
199
  }>;
140
200
  type FormStartMetadata = z.infer<typeof formStartMetadataSchema>;
201
+ /**
202
+ * Registration config for automatic `form_start`.
203
+ *
204
+ * Use `selector` to narrow which forms can trigger the event. When omitted,
205
+ * the SDK observes all `<form>` elements.
206
+ */
141
207
  declare const formStartConfigSchema: z.ZodObject<{
142
208
  selector: z.ZodOptional<z.ZodString>;
143
209
  }, "strict", z.ZodTypeAny, {
@@ -147,6 +213,46 @@ declare const formStartConfigSchema: z.ZodObject<{
147
213
  }>;
148
214
  type FormStartConfig = z.infer<typeof formStartConfigSchema>;
149
215
 
216
+ /**
217
+ * JSON-serializable value accepted by `form_submit.fields[].value`.
218
+ *
219
+ * This intentionally excludes `undefined`, functions, symbols, `Date`
220
+ * instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
221
+ * consumers should send only data that has a stable JSON representation.
222
+ */
223
+ type JsonValue = string | number | boolean | null | JsonValue[] | {
224
+ [key: string]: JsonValue;
225
+ };
226
+ /**
227
+ * Metadata for a manually fired `form_submit` event.
228
+ *
229
+ * Register the event with `manual: { form_submit: {} }`, then call
230
+ * `trackEvent('form_submit', metadata)` from the host site's submit handler.
231
+ *
232
+ * `fields` is optional. If present, each field value must be JSON-serializable
233
+ * and should be explicitly allowlisted by the integration. Do not send names,
234
+ * emails, visitor phone numbers, addresses, payment data, medical details,
235
+ * passwords, file contents, or free-text messages.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * tracking.trackEvent('form_submit', {
240
+ * form: {
241
+ * id: 'lead-form',
242
+ * action: '/api/lead',
243
+ * fields: [
244
+ * {
245
+ * name: 'service_interest',
246
+ * type: 'select',
247
+ * label: 'Service interest',
248
+ * value: 'teeth_whitening',
249
+ * },
250
+ * ],
251
+ * },
252
+ * page: { path: window.location.pathname },
253
+ * });
254
+ * ```
255
+ */
150
256
  declare const formSubmitMetadataSchema: z.ZodObject<{
151
257
  form: z.ZodObject<{
152
258
  id: z.ZodString;
@@ -155,40 +261,40 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
155
261
  name: z.ZodString;
156
262
  type: z.ZodString;
157
263
  label: z.ZodNullable<z.ZodString>;
158
- has_value: z.ZodBoolean;
159
- }, "strip", z.ZodTypeAny, {
264
+ value: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
265
+ }, "strict", z.ZodTypeAny, {
160
266
  label: string | null;
267
+ value: JsonValue;
161
268
  type: string;
162
269
  name: string;
163
- has_value: boolean;
164
270
  }, {
165
271
  label: string | null;
272
+ value: JsonValue;
166
273
  type: string;
167
274
  name: string;
168
- has_value: boolean;
169
275
  }>, "many">>;
170
- }, "strip", z.ZodTypeAny, {
276
+ }, "strict", z.ZodTypeAny, {
171
277
  id: string;
172
278
  action: string | null;
173
279
  fields?: {
174
280
  label: string | null;
281
+ value: JsonValue;
175
282
  type: string;
176
283
  name: string;
177
- has_value: boolean;
178
284
  }[] | undefined;
179
285
  }, {
180
286
  id: string;
181
287
  action: string | null;
182
288
  fields?: {
183
289
  label: string | null;
290
+ value: JsonValue;
184
291
  type: string;
185
292
  name: string;
186
- has_value: boolean;
187
293
  }[] | undefined;
188
294
  }>;
189
295
  page: z.ZodObject<{
190
296
  path: z.ZodString;
191
- }, "strip", z.ZodTypeAny, {
297
+ }, "strict", z.ZodTypeAny, {
192
298
  path: string;
193
299
  }, {
194
300
  path: string;
@@ -199,9 +305,9 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
199
305
  action: string | null;
200
306
  fields?: {
201
307
  label: string | null;
308
+ value: JsonValue;
202
309
  type: string;
203
310
  name: string;
204
- has_value: boolean;
205
311
  }[] | undefined;
206
312
  };
207
313
  page: {
@@ -213,9 +319,9 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
213
319
  action: string | null;
214
320
  fields?: {
215
321
  label: string | null;
322
+ value: JsonValue;
216
323
  type: string;
217
324
  name: string;
218
- has_value: boolean;
219
325
  }[] | undefined;
220
326
  };
221
327
  page: {
@@ -223,14 +329,26 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
223
329
  };
224
330
  }>;
225
331
  type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
332
+ /**
333
+ * Registration config for `form_submit`.
334
+ *
335
+ * This event is manual-only and currently has no registration options. The
336
+ * empty object enables typed `trackEvent('form_submit', ...)` calls.
337
+ */
226
338
  declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
227
339
  type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
228
340
 
341
+ /**
342
+ * Metadata for the automatic `multi_page_session` event.
343
+ *
344
+ * Fired when the visitor reaches the configured distinct-page threshold in a
345
+ * single tracking session.
346
+ */
229
347
  declare const multiPageSessionMetadataSchema: z.ZodObject<{
230
348
  page_count: z.ZodNumber;
231
349
  page: z.ZodObject<{
232
350
  path: z.ZodString;
233
- }, "strip", z.ZodTypeAny, {
351
+ }, "strict", z.ZodTypeAny, {
234
352
  path: string;
235
353
  }, {
236
354
  path: string;
@@ -247,6 +365,9 @@ declare const multiPageSessionMetadataSchema: z.ZodObject<{
247
365
  page_count: number;
248
366
  }>;
249
367
  type MultiPageSessionMetadata = z.infer<typeof multiPageSessionMetadataSchema>;
368
+ /**
369
+ * Registration config for automatic `multi_page_session`.
370
+ */
250
371
  declare const multiPageSessionConfigSchema: z.ZodObject<{
251
372
  pageThreshold: z.ZodNumber;
252
373
  }, "strict", z.ZodTypeAny, {
@@ -256,13 +377,20 @@ declare const multiPageSessionConfigSchema: z.ZodObject<{
256
377
  }>;
257
378
  type MultiPageSessionConfig = z.infer<typeof multiPageSessionConfigSchema>;
258
379
 
380
+ /**
381
+ * Metadata for the automatic `page_view` event.
382
+ *
383
+ * The SDK emits this on initial load, SPA route changes, and bfcache restores.
384
+ * Consumers do not call `trackEvent('page_view', ...)`; registering
385
+ * `automatic: { page_view: {} }` enables the SDK-owned trigger.
386
+ */
259
387
  declare const pageViewMetadataSchema: z.ZodObject<{
260
388
  page: z.ZodObject<{
261
389
  title: z.ZodNullable<z.ZodString>;
262
390
  path: z.ZodString;
263
391
  search: z.ZodString;
264
392
  hash: z.ZodString;
265
- }, "strip", z.ZodTypeAny, {
393
+ }, "strict", z.ZodTypeAny, {
266
394
  search: string;
267
395
  title: string | null;
268
396
  path: string;
@@ -277,7 +405,7 @@ declare const pageViewMetadataSchema: z.ZodObject<{
277
405
  viewport: z.ZodOptional<z.ZodNullable<z.ZodObject<{
278
406
  w: z.ZodNumber;
279
407
  h: z.ZodNumber;
280
- }, "strip", z.ZodTypeAny, {
408
+ }, "strict", z.ZodTypeAny, {
281
409
  w: number;
282
410
  h: number;
283
411
  }, {
@@ -310,14 +438,27 @@ declare const pageViewMetadataSchema: z.ZodObject<{
310
438
  } | null | undefined;
311
439
  }>;
312
440
  type PageViewMetadata = z.infer<typeof pageViewMetadataSchema>;
441
+ /**
442
+ * Registration config for automatic `page_view`.
443
+ *
444
+ * `page_view` is required in every trigger registry and currently has no
445
+ * options. Use `{ page_view: {} }`.
446
+ */
313
447
  declare const pageViewConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
314
448
  type PageViewConfig = z.infer<typeof pageViewConfigSchema>;
315
449
 
450
+ /**
451
+ * Metadata for a manually fired `phone_click` event.
452
+ *
453
+ * `phone_number` should be the business phone number from the clicked `tel:`
454
+ * link, not a visitor-entered phone number. `section` can distinguish header,
455
+ * footer, hero, or contact-page links.
456
+ */
316
457
  declare const phoneClickMetadataSchema: z.ZodObject<{
317
458
  phone_number: z.ZodString;
318
459
  page: z.ZodObject<{
319
460
  path: z.ZodString;
320
- }, "strip", z.ZodTypeAny, {
461
+ }, "strict", z.ZodTypeAny, {
321
462
  path: string;
322
463
  }, {
323
464
  path: string;
@@ -337,14 +478,24 @@ declare const phoneClickMetadataSchema: z.ZodObject<{
337
478
  section?: string | null | undefined;
338
479
  }>;
339
480
  type PhoneClickMetadata = z.infer<typeof phoneClickMetadataSchema>;
481
+ /**
482
+ * Registration config for `phone_click`.
483
+ *
484
+ * This event is manual-only and currently has no registration options.
485
+ */
340
486
  declare const phoneClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
341
487
  type PhoneClickConfig = z.infer<typeof phoneClickConfigSchema>;
342
488
 
489
+ /**
490
+ * Metadata for the automatic `scroll_depth` event.
491
+ *
492
+ * Fired once per configured threshold per page.
493
+ */
343
494
  declare const scrollDepthMetadataSchema: z.ZodObject<{
344
495
  depth_percent: z.ZodNumber;
345
496
  page: z.ZodObject<{
346
497
  path: z.ZodString;
347
- }, "strip", z.ZodTypeAny, {
498
+ }, "strict", z.ZodTypeAny, {
348
499
  path: string;
349
500
  }, {
350
501
  path: string;
@@ -361,6 +512,11 @@ declare const scrollDepthMetadataSchema: z.ZodObject<{
361
512
  depth_percent: number;
362
513
  }>;
363
514
  type ScrollDepthMetadata = z.infer<typeof scrollDepthMetadataSchema>;
515
+ /**
516
+ * Registration config for automatic `scroll_depth`.
517
+ *
518
+ * `thresholds` are integer percentages from 1 to 100.
519
+ */
364
520
  declare const scrollDepthConfigSchema: z.ZodObject<{
365
521
  thresholds: z.ZodArray<z.ZodNumber, "many">;
366
522
  }, "strict", z.ZodTypeAny, {
@@ -370,13 +526,22 @@ declare const scrollDepthConfigSchema: z.ZodObject<{
370
526
  }>;
371
527
  type ScrollDepthConfig = z.infer<typeof scrollDepthConfigSchema>;
372
528
 
529
+ /**
530
+ * Canonical page intent names supported by `specific_page_visit`.
531
+ */
373
532
  declare const SPECIFIC_PAGE_NAMES: readonly ["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"];
374
533
  type SpecificPageName = (typeof SPECIFIC_PAGE_NAMES)[number];
534
+ /**
535
+ * Metadata for the automatic `specific_page_visit` event.
536
+ *
537
+ * The SDK emits this when the current pathname matches one of the configured
538
+ * named page patterns.
539
+ */
375
540
  declare const specificPageVisitMetadataSchema: z.ZodObject<{
376
541
  page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
377
542
  page: z.ZodObject<{
378
543
  path: z.ZodString;
379
- }, "strip", z.ZodTypeAny, {
544
+ }, "strict", z.ZodTypeAny, {
380
545
  path: string;
381
546
  }, {
382
547
  path: string;
@@ -393,11 +558,17 @@ declare const specificPageVisitMetadataSchema: z.ZodObject<{
393
558
  page_name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
394
559
  }>;
395
560
  type SpecificPageVisitMetadata = z.infer<typeof specificPageVisitMetadataSchema>;
561
+ /**
562
+ * Registration config for automatic `specific_page_visit`.
563
+ *
564
+ * Each page entry pairs a semantic `name` with a `RegExp` that matches the
565
+ * pathname. Use this instead of hard-coding path regexes downstream.
566
+ */
396
567
  declare const specificPageVisitConfigSchema: z.ZodObject<{
397
568
  pages: z.ZodArray<z.ZodObject<{
398
569
  name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
399
570
  pathPattern: z.ZodType<RegExp, z.ZodTypeDef, RegExp>;
400
- }, "strip", z.ZodTypeAny, {
571
+ }, "strict", z.ZodTypeAny, {
401
572
  name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
402
573
  pathPattern: RegExp;
403
574
  }, {
@@ -417,11 +588,17 @@ declare const specificPageVisitConfigSchema: z.ZodObject<{
417
588
  }>;
418
589
  type SpecificPageVisitConfig = z.infer<typeof specificPageVisitConfigSchema>;
419
590
 
591
+ /**
592
+ * Metadata for the automatic `time_on_site` event.
593
+ *
594
+ * The SDK starts a visibility-aware timer and fires once when visible
595
+ * engagement crosses the configured threshold.
596
+ */
420
597
  declare const timeOnSiteMetadataSchema: z.ZodObject<{
421
598
  duration_ms: z.ZodNumber;
422
599
  page: z.ZodObject<{
423
600
  path: z.ZodString;
424
- }, "strip", z.ZodTypeAny, {
601
+ }, "strict", z.ZodTypeAny, {
425
602
  path: string;
426
603
  }, {
427
604
  path: string;
@@ -438,6 +615,9 @@ declare const timeOnSiteMetadataSchema: z.ZodObject<{
438
615
  duration_ms: number;
439
616
  }>;
440
617
  type TimeOnSiteMetadata = z.infer<typeof timeOnSiteMetadataSchema>;
618
+ /**
619
+ * Registration config for automatic `time_on_site`.
620
+ */
441
621
  declare const timeOnSiteConfigSchema: z.ZodObject<{
442
622
  thresholdSeconds: z.ZodNumber;
443
623
  }, "strict", z.ZodTypeAny, {
@@ -456,7 +636,7 @@ declare const EVENT_REGISTRY: {
456
636
  path: z.ZodString;
457
637
  search: z.ZodString;
458
638
  hash: z.ZodString;
459
- }, "strip", z.ZodTypeAny, {
639
+ }, "strict", z.ZodTypeAny, {
460
640
  search: string;
461
641
  title: string | null;
462
642
  path: string;
@@ -471,7 +651,7 @@ declare const EVENT_REGISTRY: {
471
651
  viewport: z.ZodOptional<z.ZodNullable<z.ZodObject<{
472
652
  w: z.ZodNumber;
473
653
  h: z.ZodNumber;
474
- }, "strip", z.ZodTypeAny, {
654
+ }, "strict", z.ZodTypeAny, {
475
655
  w: number;
476
656
  h: number;
477
657
  }, {
@@ -511,7 +691,7 @@ declare const EVENT_REGISTRY: {
511
691
  duration_ms: z.ZodNumber;
512
692
  page: z.ZodObject<{
513
693
  path: z.ZodString;
514
- }, "strip", z.ZodTypeAny, {
694
+ }, "strict", z.ZodTypeAny, {
515
695
  path: string;
516
696
  }, {
517
697
  path: string;
@@ -541,7 +721,7 @@ declare const EVENT_REGISTRY: {
541
721
  page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
542
722
  page: z.ZodObject<{
543
723
  path: z.ZodString;
544
- }, "strip", z.ZodTypeAny, {
724
+ }, "strict", z.ZodTypeAny, {
545
725
  path: string;
546
726
  }, {
547
727
  path: string;
@@ -561,7 +741,7 @@ declare const EVENT_REGISTRY: {
561
741
  pages: z.ZodArray<z.ZodObject<{
562
742
  name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
563
743
  pathPattern: z.ZodType<RegExp, z.ZodTypeDef, RegExp>;
564
- }, "strip", z.ZodTypeAny, {
744
+ }, "strict", z.ZodTypeAny, {
565
745
  name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
566
746
  pathPattern: RegExp;
567
747
  }, {
@@ -586,7 +766,7 @@ declare const EVENT_REGISTRY: {
586
766
  depth_percent: z.ZodNumber;
587
767
  page: z.ZodObject<{
588
768
  path: z.ZodString;
589
- }, "strip", z.ZodTypeAny, {
769
+ }, "strict", z.ZodTypeAny, {
590
770
  path: string;
591
771
  }, {
592
772
  path: string;
@@ -616,7 +796,7 @@ declare const EVENT_REGISTRY: {
616
796
  page_count: z.ZodNumber;
617
797
  page: z.ZodObject<{
618
798
  path: z.ZodString;
619
- }, "strip", z.ZodTypeAny, {
799
+ }, "strict", z.ZodTypeAny, {
620
800
  path: string;
621
801
  }, {
622
802
  path: string;
@@ -646,7 +826,7 @@ declare const EVENT_REGISTRY: {
646
826
  form: z.ZodObject<{
647
827
  id: z.ZodString;
648
828
  action: z.ZodNullable<z.ZodString>;
649
- }, "strip", z.ZodTypeAny, {
829
+ }, "strict", z.ZodTypeAny, {
650
830
  id: string;
651
831
  action: string | null;
652
832
  }, {
@@ -655,7 +835,7 @@ declare const EVENT_REGISTRY: {
655
835
  }>;
656
836
  page: z.ZodObject<{
657
837
  path: z.ZodString;
658
- }, "strip", z.ZodTypeAny, {
838
+ }, "strict", z.ZodTypeAny, {
659
839
  path: string;
660
840
  }, {
661
841
  path: string;
@@ -733,40 +913,40 @@ declare const EVENT_REGISTRY: {
733
913
  name: z.ZodString;
734
914
  type: z.ZodString;
735
915
  label: z.ZodNullable<z.ZodString>;
736
- has_value: z.ZodBoolean;
737
- }, "strip", z.ZodTypeAny, {
916
+ value: z.ZodType<src.JsonValue, z.ZodTypeDef, src.JsonValue>;
917
+ }, "strict", z.ZodTypeAny, {
738
918
  label: string | null;
919
+ value: src.JsonValue;
739
920
  type: string;
740
921
  name: string;
741
- has_value: boolean;
742
922
  }, {
743
923
  label: string | null;
924
+ value: src.JsonValue;
744
925
  type: string;
745
926
  name: string;
746
- has_value: boolean;
747
927
  }>, "many">>;
748
- }, "strip", z.ZodTypeAny, {
928
+ }, "strict", z.ZodTypeAny, {
749
929
  id: string;
750
930
  action: string | null;
751
931
  fields?: {
752
932
  label: string | null;
933
+ value: src.JsonValue;
753
934
  type: string;
754
935
  name: string;
755
- has_value: boolean;
756
936
  }[] | undefined;
757
937
  }, {
758
938
  id: string;
759
939
  action: string | null;
760
940
  fields?: {
761
941
  label: string | null;
942
+ value: src.JsonValue;
762
943
  type: string;
763
944
  name: string;
764
- has_value: boolean;
765
945
  }[] | undefined;
766
946
  }>;
767
947
  page: z.ZodObject<{
768
948
  path: z.ZodString;
769
- }, "strip", z.ZodTypeAny, {
949
+ }, "strict", z.ZodTypeAny, {
770
950
  path: string;
771
951
  }, {
772
952
  path: string;
@@ -777,9 +957,9 @@ declare const EVENT_REGISTRY: {
777
957
  action: string | null;
778
958
  fields?: {
779
959
  label: string | null;
960
+ value: src.JsonValue;
780
961
  type: string;
781
962
  name: string;
782
- has_value: boolean;
783
963
  }[] | undefined;
784
964
  };
785
965
  page: {
@@ -791,9 +971,9 @@ declare const EVENT_REGISTRY: {
791
971
  action: string | null;
792
972
  fields?: {
793
973
  label: string | null;
974
+ value: src.JsonValue;
794
975
  type: string;
795
976
  name: string;
796
- has_value: boolean;
797
977
  }[] | undefined;
798
978
  };
799
979
  page: {
@@ -808,7 +988,7 @@ declare const EVENT_REGISTRY: {
808
988
  phone_number: z.ZodString;
809
989
  page: z.ZodObject<{
810
990
  path: z.ZodString;
811
- }, "strip", z.ZodTypeAny, {
991
+ }, "strict", z.ZodTypeAny, {
812
992
  path: string;
813
993
  }, {
814
994
  path: string;
@@ -835,7 +1015,7 @@ declare const EVENT_REGISTRY: {
835
1015
  cta_name: z.ZodString;
836
1016
  page: z.ZodObject<{
837
1017
  path: z.ZodString;
838
- }, "strip", z.ZodTypeAny, {
1018
+ }, "strict", z.ZodTypeAny, {
839
1019
  path: string;
840
1020
  }, {
841
1021
  path: string;
@@ -860,10 +1040,21 @@ declare const EVENT_REGISTRY: {
860
1040
  readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
861
1041
  };
862
1042
  };
1043
+ /**
1044
+ * Name of any event known to the tracking SDK.
1045
+ */
863
1046
  type EventName = keyof typeof EVENT_REGISTRY;
1047
+ /**
1048
+ * Event names that are fired by the SDK when their configured signal occurs.
1049
+ *
1050
+ * Automatic events are not accepted by the typed `trackEvent()` API.
1051
+ */
864
1052
  type AutomaticEventName = {
865
1053
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'automatic' ? K : never;
866
1054
  }[EventName];
1055
+ /**
1056
+ * Event names that consumer code can fire manually after registering them.
1057
+ */
867
1058
  type ManualEventName = {
868
1059
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'manual' ? K : never;
869
1060
  }[EventName];
@@ -891,8 +1082,44 @@ type ConfigByName = {
891
1082
  phone_click: PhoneClickConfig;
892
1083
  cta_click: CtaClickConfig;
893
1084
  };
1085
+ /**
1086
+ * Metadata payload type for a specific tracking event.
1087
+ *
1088
+ * @example
1089
+ * ```ts
1090
+ * type SubmitMetadata = EventMetadata<'form_submit'>;
1091
+ * ```
1092
+ */
894
1093
  type EventMetadata<K extends EventName> = MetadataByName[K];
1094
+ /**
1095
+ * Trigger registration config type for a specific tracking event.
1096
+ */
895
1097
  type EventConfig<K extends EventName> = ConfigByName[K];
1098
+ /**
1099
+ * Trigger registry passed to `createTracking({ triggers })`.
1100
+ *
1101
+ * `automatic.page_view` is required because every install should capture page
1102
+ * views. Other automatic events are opt-in. Manual events must be registered
1103
+ * here before the typed client accepts `trackEvent()` calls for them.
1104
+ *
1105
+ * @example
1106
+ * ```ts
1107
+ * createTracking({
1108
+ * apiKey,
1109
+ * endpoint,
1110
+ * triggers: {
1111
+ * automatic: {
1112
+ * page_view: {},
1113
+ * time_on_site: { thresholdSeconds: 60 },
1114
+ * },
1115
+ * manual: {
1116
+ * form_submit: {},
1117
+ * phone_click: {},
1118
+ * },
1119
+ * },
1120
+ * });
1121
+ * ```
1122
+ */
896
1123
  type TriggerRegistryConfig = {
897
1124
  automatic: {
898
1125
  page_view: EventConfig<'page_view'>;
@@ -909,29 +1136,70 @@ type TriggerRegistryConfig = {
909
1136
  cta_click: EventConfig<'cta_click'>;
910
1137
  }>;
911
1138
  };
1139
+ /**
1140
+ * Manual event names registered in a concrete trigger registry.
1141
+ *
1142
+ * Used by `TypedTrackingClient` so `trackEvent()` only accepts events the
1143
+ * consumer explicitly enabled.
1144
+ */
912
1145
  type RegisteredManualEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof NonNullable<TRegistry['manual']>, ManualEventName>;
1146
+ /**
1147
+ * Automatic event names registered in a concrete trigger registry.
1148
+ */
913
1149
  type RegisteredAutomaticEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof TRegistry['automatic'], AutomaticEventName>;
914
1150
 
1151
+ /**
1152
+ * Input accepted by the low-level stringly-typed client.
1153
+ *
1154
+ * Prefer the typed `trackEvent(eventName, metadata)` facade exposed by
1155
+ * `useTracking()` in React/Next integrations.
1156
+ */
915
1157
  interface TrackEventInput {
1158
+ /** Event name to enqueue. */
916
1159
  eventType: string;
1160
+ /** URL associated with the event. Defaults to the current page URL. */
917
1161
  pageUrl?: string | null;
1162
+ /** Event-specific metadata. */
918
1163
  metadata?: Record<string, unknown> | null;
1164
+ /** Timestamp override. Defaults to queue time. */
919
1165
  occurredAt?: Date | string | null;
920
1166
  }
1167
+ /**
1168
+ * Low-level tracking client responsible for queueing and flushing events.
1169
+ */
921
1170
  interface TrackingClient {
1171
+ /** Enqueue an event for batched delivery. */
922
1172
  trackEvent: (input: TrackEventInput) => void;
1173
+ /** Flush queued events immediately. */
923
1174
  flush: () => Promise<void>;
1175
+ /** Return the current rolling session id. */
924
1176
  getSessionId: () => string;
1177
+ /** Return the persistent visitor id. */
925
1178
  getVisitorId: () => string;
1179
+ /** Remove timers/listeners and prevent future flushes. */
926
1180
  destroy: () => void;
927
1181
  }
928
1182
 
929
1183
  interface TypedTrackEventOptions {
930
- /** Override the page URL captured automatically. Rarely needed. */
1184
+ /**
1185
+ * Override the page URL associated with this event.
1186
+ *
1187
+ * Omit this for normal browser usage; the SDK captures `window.location.href`.
1188
+ */
931
1189
  pageUrl?: string | null;
932
- /** Event timestamp override. Defaults to "now" at queue time. */
1190
+ /**
1191
+ * Override the event timestamp.
1192
+ *
1193
+ * Defaults to the time the event is queued. Accepts a `Date` or ISO string.
1194
+ */
933
1195
  occurredAt?: Date | string | null;
934
1196
  }
1197
+ /**
1198
+ * Typed tracking client returned by `useTracking()`.
1199
+ *
1200
+ * The accepted event names and metadata shapes are narrowed from the concrete
1201
+ * trigger registry supplied to `createTracking()`.
1202
+ */
935
1203
  interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
936
1204
  /**
937
1205
  * Fire a manually-registered event. The event name must be present in
@@ -939,37 +1207,104 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
939
1207
  * canonical Zod-derived shape.
940
1208
  */
941
1209
  trackEvent<K extends RegisteredManualEvents<TRegistry>>(eventType: K, metadata: EventMetadata<K>, options?: TypedTrackEventOptions): void;
1210
+ /**
1211
+ * Immediately flush queued events to the ingest endpoint.
1212
+ *
1213
+ * Normal consumers rarely need this because the SDK flushes on a debounce,
1214
+ * when the queue reaches the batch threshold, and on `pagehide`.
1215
+ */
942
1216
  flush(): Promise<void>;
1217
+ /**
1218
+ * Return the current rolling session id.
1219
+ */
943
1220
  getSessionId(): string;
1221
+ /**
1222
+ * Return the persistent visitor id for this browser profile.
1223
+ */
944
1224
  getVisitorId(): string;
945
1225
  }
946
1226
 
1227
+ /**
1228
+ * Default non-blocking consent banner for Next.js installs.
1229
+ *
1230
+ * Renders only while consent is `pending`. Accept/decline choices are stored
1231
+ * in localStorage and propagated to Google Consent Mode when gtag is loaded.
1232
+ */
947
1233
  declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
948
1234
 
1235
+ /**
1236
+ * Read the captured Google Ads click id from first-party cookies.
1237
+ *
1238
+ * Returns `null` during SSR and before the client has mounted.
1239
+ */
949
1240
  declare function useGclid(): string | null;
1241
+ /**
1242
+ * Read all captured attribution parameters from first-party cookies.
1243
+ *
1244
+ * Values are loaded after mount, so the initial render returns all `null`s.
1245
+ */
950
1246
  declare function useTrackingParams(): TrackingParams;
1247
+ /**
1248
+ * Read the current visitor consent state and update when another tab changes
1249
+ * the stored value.
1250
+ */
951
1251
  declare function useConsentState(): ConsentState;
952
1252
 
953
1253
  interface GoogleAdsTrackingProps {
1254
+ /**
1255
+ * Google Ads tag id, for example `AW-123456789`.
1256
+ */
954
1257
  gtagId: string;
955
1258
  }
1259
+ /**
1260
+ * Next.js client component that loads Google Ads gtag with Consent Mode.
1261
+ *
1262
+ * Render in the root layout `<head>` when the client site runs paid Google
1263
+ * Ads. The component injects Next `<Script>` tags and renders no visible UI.
1264
+ */
956
1265
  declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): react_jsx_runtime.JSX.Element;
957
1266
 
958
1267
  interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
1268
+ /**
1269
+ * Public tracking API key issued for this business.
1270
+ *
1271
+ * This key is safe to expose via `NEXT_PUBLIC_*` env vars.
1272
+ */
959
1273
  apiKey: string;
1274
+ /**
1275
+ * Tracking endpoint base URL, usually ending in `/tracking`.
1276
+ */
960
1277
  endpoint: string;
1278
+ /**
1279
+ * Trigger registry that controls automatic events and typed manual events.
1280
+ */
961
1281
  triggers: TRegistry;
1282
+ /**
1283
+ * Validate manual event metadata at runtime before queueing.
1284
+ *
1285
+ * Enable in development to catch shape bugs. Leave disabled in production so
1286
+ * analytics can never throw into the host app.
1287
+ */
962
1288
  debug?: boolean;
963
1289
  }
964
1290
  interface TrackingProviderProps {
1291
+ /**
1292
+ * Application subtree that should have access to the tracking client.
1293
+ */
965
1294
  children: ReactNode;
966
1295
  }
967
1296
  interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
1297
+ /**
1298
+ * Client component provider for the Next.js App Router integration.
1299
+ */
968
1300
  TrackingProvider: (props: TrackingProviderProps) => ReactNode;
1301
+ /**
1302
+ * Hook that returns the registry-typed tracking client.
1303
+ */
969
1304
  useTracking: () => TypedTrackingClient<TRegistry>;
970
1305
  }
971
1306
  /**
972
- * Next.js App Router version of the createTracking factory. Uses
1307
+ * Next.js App Router version of the `createTracking()` factory. Uses
973
1308
  * `usePathname` + `useSearchParams` from `next/navigation` for SPA route
974
1309
  * detection rather than patching `history.pushState`, because Next's
975
1310
  * router does not always go through the History API for transitions.
@@ -982,4 +1317,4 @@ interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
982
1317
  */
983
1318
  declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;
984
1319
 
985
- export { type AutomaticEventName, ConsentBanner, 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, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, getConsentState, setConsentState, useConsentState, useGclid, useTrackingParams };
1320
+ export { type AutomaticEventName, ConsentBanner, 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, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, getConsentState, setConsentState, useConsentState, useGclid, useTrackingParams };