@aranova/tracking-react 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,34 +3,99 @@ 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
- interface GoogleAdsTrackingProps {
9
- gtagId: string;
10
- }
11
- declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): null;
12
-
14
+ /**
15
+ * Visitor consent state stored by the SDK.
16
+ *
17
+ * - `pending`: the visitor has not accepted or declined yet.
18
+ * - `granted`: consent was accepted and Google Consent Mode is updated to granted.
19
+ * - `denied`: consent was declined and Google Consent Mode is updated to denied.
20
+ */
13
21
  type ConsentState = 'granted' | 'denied' | 'pending';
22
+ /**
23
+ * Attribution parameters captured from the landing URL and persisted in cookies.
24
+ *
25
+ * Missing params are represented as `null` so payloads can be serialized
26
+ * directly without checking for `undefined`.
27
+ */
14
28
  interface TrackingParams {
29
+ /** Google Ads click id. */
15
30
  gclid: string | null;
31
+ /** Meta/Facebook click id. */
16
32
  fbclid: string | null;
33
+ /** UTM source, for example `google` or `newsletter`. */
17
34
  utm_source: string | null;
35
+ /** UTM medium, for example `cpc` or `email`. */
18
36
  utm_medium: string | null;
37
+ /** UTM campaign name. */
19
38
  utm_campaign: string | null;
39
+ /** UTM paid-search term. */
20
40
  utm_term: string | null;
41
+ /** UTM content/ad creative label. */
21
42
  utm_content: string | null;
22
43
  }
44
+ /**
45
+ * Runtime surface that installed the tracking SDK.
46
+ *
47
+ * Included in ingest payloads and heartbeat events so the dashboard can tell
48
+ * whether a site uses the Next, React, or script-tag integration.
49
+ */
23
50
  type TrackingInstallSurface = 'next' | 'react' | 'script';
51
+ /**
52
+ * Deployment environment label for event tagging.
53
+ *
54
+ * Used to stamp tracking events with the deployment context so the dashboard
55
+ * can distinguish production traffic from dev test traffic. The backend
56
+ * enforces this via a Postgres enum, so values are strictly one of
57
+ * `'production'` or `'development'`.
58
+ */
59
+ type TrackingEnvironment = 'production' | 'development';
60
+ /**
61
+ * Labelled map of Google Ads tag IDs.
62
+ *
63
+ * ALL entries are loaded simultaneously via `gtag('config', ...)` — the keys
64
+ * are human-readable labels (e.g. `production`, `test`) and the values are
65
+ * Google Ads tag IDs (e.g. `AW-123456789`).
66
+ */
67
+ type GtagEnvironmentMap = Record<string, string>;
68
+ /**
69
+ * Runtime context attached to tracking sessions and events.
70
+ */
24
71
  interface TrackingClientContext {
72
+ /** Install surface that created the client. */
25
73
  surface: TrackingInstallSurface;
74
+ /** Package version, when available. */
26
75
  sdk_version: string | null;
76
+ /** Package name, for example `@aranova/tracking-react`. */
27
77
  package_name: string | null;
78
+ /** Browser origin of the tracked site. */
28
79
  site_origin: string | null;
80
+ /** Current document title at client creation time. */
29
81
  page_title: string | null;
82
+ /** Browser document referrer at client creation time. */
30
83
  referrer: string | null;
84
+ /** Deployment environment label, e.g. `'production'`, `'development'`. */
85
+ environment: TrackingEnvironment | null;
86
+ /** All active gtag IDs loaded on this page, keyed by label. */
87
+ active_gtag_ids: Record<string, string> | null;
31
88
  }
89
+ /**
90
+ * Session payload sent to `POST /tracking/events`.
91
+ *
92
+ * The backend upserts this by `(business_id, session_id)` before inserting
93
+ * individual events.
94
+ */
32
95
  interface TrackingSessionUpsertPayload {
96
+ /** Rolling 30-minute client-side session id. */
33
97
  session_id: string;
98
+ /** Persistent client-side visitor id. */
34
99
  visitor_id: string | null;
35
100
  gclid: string | null;
36
101
  fbclid: string | null;
@@ -43,22 +108,46 @@ interface TrackingSessionUpsertPayload {
43
108
  consent_state: Record<string, unknown> | null;
44
109
  context: TrackingClientContext;
45
110
  }
111
+ /**
112
+ * Event payload shape before batching into the ingest request.
113
+ */
46
114
  interface TrackingEventCreatePayload {
115
+ /** Session id that logically owns the event. */
47
116
  session_id: string;
117
+ /** Registered event name, for example `page_view` or `form_submit`. */
48
118
  event_type: string;
49
119
  gclid: string | null;
50
120
  fbclid: string | null;
121
+ /** Full page URL associated with the event, if known. */
51
122
  page_url: string | null;
123
+ /** Event-specific metadata. Runtime shape depends on `event_type`. */
52
124
  metadata: Record<string, unknown> | null;
53
125
  context: TrackingClientContext;
54
126
  }
127
+ /**
128
+ * Browser-script initialization config passed to `window.AranovaTracking.init()`.
129
+ */
55
130
  interface TrackingInitConfig {
131
+ /** Public tracking API key issued from the Aranova dashboard. */
56
132
  apiKey?: string;
133
+ /** Tracking endpoint base URL, usually ending in `/tracking`. */
57
134
  endpoint?: string;
135
+ /** Optional Google Ads tag id, for example `AW-123456789`. */
58
136
  gtagId?: string;
137
+ /**
138
+ * Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
139
+ * When provided, `gtagId` is ignored.
140
+ */
141
+ gtagIds?: GtagEnvironmentMap;
142
+ /** Deployment environment label reported in session context. */
143
+ environment?: TrackingEnvironment;
144
+ /** Whether to capture attribution params from `window.location`. Defaults to true. */
59
145
  autoCaptureTrackingParams?: boolean;
146
+ /** Whether the browser script should inject the default consent banner. */
60
147
  renderConsentBanner?: boolean;
148
+ /** Attribution cookie max age in seconds. Defaults to 90 days. */
61
149
  cookieMaxAgeSeconds?: number;
150
+ /** Override the install surface reported in payload context. */
62
151
  surface?: TrackingInstallSurface;
63
152
  }
64
153
  declare global {
@@ -76,8 +165,21 @@ declare global {
76
165
  }
77
166
  }
78
167
 
168
+ /**
169
+ * Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
170
+ */
79
171
  type GtagConsentValue = 'granted' | 'denied';
172
+ /**
173
+ * Read the persisted visitor consent state from localStorage.
174
+ *
175
+ * Returns `pending` when called during SSR or before the visitor has made a
176
+ * choice.
177
+ */
80
178
  declare function getConsentState(): ConsentState;
179
+ /**
180
+ * Persist a visitor consent choice and update Google Consent Mode when gtag is
181
+ * loaded.
182
+ */
81
183
  declare function setConsentState(state: GtagConsentValue): void;
82
184
 
83
185
  interface TrackingContextInput {
@@ -86,6 +188,8 @@ interface TrackingContextInput {
86
188
  referrer?: string | null;
87
189
  sdkVersion?: string | null;
88
190
  siteOrigin?: string | null;
191
+ environment?: TrackingEnvironment | null;
192
+ activeGtagIds?: Record<string, string> | null;
89
193
  }
90
194
  interface TrackingEventInput {
91
195
  eventType: string;
@@ -99,13 +203,37 @@ interface TrackingSessionInput {
99
203
  sessionId: string;
100
204
  visitorId?: string | null;
101
205
  }
206
+ /**
207
+ * Build runtime context attached to tracking sessions and events.
208
+ */
102
209
  declare function createTrackingClientContext(surface: TrackingInstallSurface, input?: TrackingContextInput): TrackingClientContext;
210
+ /**
211
+ * Build the session portion of a tracking ingest request.
212
+ */
103
213
  declare function createTrackingSessionUpsertPayload(trackingParams: TrackingParams, input: TrackingSessionInput, context: TrackingClientContext): TrackingSessionUpsertPayload;
214
+ /**
215
+ * Build one event payload before it is batched into a tracking ingest request.
216
+ */
104
217
  declare function createTrackingEventCreatePayload(trackingParams: TrackingParams, input: TrackingEventInput, context: TrackingClientContext): TrackingEventCreatePayload;
105
218
 
219
+ /**
220
+ * Attribution query/cookie keys captured by the SDK.
221
+ */
106
222
  declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
223
+ /**
224
+ * Capture tracking params from a URL, persist them to first-party cookies, and
225
+ * return the current cookie-backed attribution state.
226
+ *
227
+ * Defaults to `window.location.href` in the browser.
228
+ */
107
229
  declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
108
230
 
231
+ /**
232
+ * Metadata for a manually fired `cta_click` event.
233
+ *
234
+ * Use this for non-phone calls to action such as directions, appointment
235
+ * buttons, downloads, or external booking links.
236
+ */
109
237
  declare const ctaClickMetadataSchema: z.ZodObject<{
110
238
  cta_name: z.ZodString;
111
239
  page: z.ZodObject<{
@@ -133,9 +261,21 @@ declare const ctaClickMetadataSchema: z.ZodObject<{
133
261
  destination_url?: string | null | undefined;
134
262
  }>;
135
263
  type CtaClickMetadata = z.infer<typeof ctaClickMetadataSchema>;
264
+ /**
265
+ * Registration config for `cta_click`.
266
+ *
267
+ * This event is manual-only and currently has no registration options.
268
+ */
136
269
  declare const ctaClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
137
270
  type CtaClickConfig = z.infer<typeof ctaClickConfigSchema>;
138
271
 
272
+ /**
273
+ * Metadata for the SDK-internal `sdk_heartbeat` event.
274
+ *
275
+ * The SDK fires this once per new session so the dashboard can show which SDK
276
+ * version, install surface, and trigger registry a client site is running.
277
+ * Consumers do not manually register or fire this event.
278
+ */
139
279
  declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
140
280
  sdk_version: z.ZodString;
141
281
  package_name: z.ZodNullable<z.ZodString>;
@@ -151,6 +291,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
151
291
  manual: string[];
152
292
  }>;
153
293
  trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
294
+ configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
154
295
  }, "strict", z.ZodTypeAny, {
155
296
  sdk_version: string;
156
297
  package_name: string | null;
@@ -160,6 +301,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
160
301
  manual: string[];
161
302
  };
162
303
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
304
+ configured_gtag_ids?: Record<string, string> | null | undefined;
163
305
  }, {
164
306
  sdk_version: string;
165
307
  package_name: string | null;
@@ -169,11 +311,22 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
169
311
  manual: string[];
170
312
  };
171
313
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
314
+ configured_gtag_ids?: Record<string, string> | null | undefined;
172
315
  }>;
173
316
  type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
317
+ /**
318
+ * Internal registration config for `sdk_heartbeat`.
319
+ *
320
+ * This event has no consumer-facing options.
321
+ */
174
322
  declare const sdkHeartbeatConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
175
323
  type SdkHeartbeatConfig = z.infer<typeof sdkHeartbeatConfigSchema>;
176
324
 
325
+ /**
326
+ * Metadata for the automatic `form_start` event.
327
+ *
328
+ * The SDK emits this once per form when the visitor first focuses a field.
329
+ */
177
330
  declare const formStartMetadataSchema: z.ZodObject<{
178
331
  form: z.ZodObject<{
179
332
  id: z.ZodString;
@@ -210,6 +363,12 @@ declare const formStartMetadataSchema: z.ZodObject<{
210
363
  };
211
364
  }>;
212
365
  type FormStartMetadata = z.infer<typeof formStartMetadataSchema>;
366
+ /**
367
+ * Registration config for automatic `form_start`.
368
+ *
369
+ * Use `selector` to narrow which forms can trigger the event. When omitted,
370
+ * the SDK observes all `<form>` elements.
371
+ */
213
372
  declare const formStartConfigSchema: z.ZodObject<{
214
373
  selector: z.ZodOptional<z.ZodString>;
215
374
  }, "strict", z.ZodTypeAny, {
@@ -219,9 +378,46 @@ declare const formStartConfigSchema: z.ZodObject<{
219
378
  }>;
220
379
  type FormStartConfig = z.infer<typeof formStartConfigSchema>;
221
380
 
381
+ /**
382
+ * JSON-serializable value accepted by `form_submit.fields[].value`.
383
+ *
384
+ * This intentionally excludes `undefined`, functions, symbols, `Date`
385
+ * instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
386
+ * consumers should send only data that has a stable JSON representation.
387
+ */
222
388
  type JsonValue = string | number | boolean | null | JsonValue[] | {
223
389
  [key: string]: JsonValue;
224
390
  };
391
+ /**
392
+ * Metadata for a manually fired `form_submit` event.
393
+ *
394
+ * Register the event with `manual: { form_submit: {} }`, then call
395
+ * `trackEvent('form_submit', metadata)` from the host site's submit handler.
396
+ *
397
+ * `fields` is optional. If present, each field value must be JSON-serializable
398
+ * and should be explicitly allowlisted by the integration. Do not send names,
399
+ * emails, visitor phone numbers, addresses, payment data, medical details,
400
+ * passwords, file contents, or free-text messages.
401
+ *
402
+ * @example
403
+ * ```ts
404
+ * tracking.trackEvent('form_submit', {
405
+ * form: {
406
+ * id: 'lead-form',
407
+ * action: '/api/lead',
408
+ * fields: [
409
+ * {
410
+ * name: 'service_interest',
411
+ * type: 'select',
412
+ * label: 'Service interest',
413
+ * value: 'teeth_whitening',
414
+ * },
415
+ * ],
416
+ * },
417
+ * page: { path: window.location.pathname },
418
+ * });
419
+ * ```
420
+ */
225
421
  declare const formSubmitMetadataSchema: z.ZodObject<{
226
422
  form: z.ZodObject<{
227
423
  id: z.ZodString;
@@ -298,9 +494,21 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
298
494
  };
299
495
  }>;
300
496
  type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
497
+ /**
498
+ * Registration config for `form_submit`.
499
+ *
500
+ * This event is manual-only and currently has no registration options. The
501
+ * empty object enables typed `trackEvent('form_submit', ...)` calls.
502
+ */
301
503
  declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
302
504
  type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
303
505
 
506
+ /**
507
+ * Metadata for the automatic `multi_page_session` event.
508
+ *
509
+ * Fired when the visitor reaches the configured distinct-page threshold in a
510
+ * single tracking session.
511
+ */
304
512
  declare const multiPageSessionMetadataSchema: z.ZodObject<{
305
513
  page_count: z.ZodNumber;
306
514
  page: z.ZodObject<{
@@ -322,6 +530,9 @@ declare const multiPageSessionMetadataSchema: z.ZodObject<{
322
530
  page_count: number;
323
531
  }>;
324
532
  type MultiPageSessionMetadata = z.infer<typeof multiPageSessionMetadataSchema>;
533
+ /**
534
+ * Registration config for automatic `multi_page_session`.
535
+ */
325
536
  declare const multiPageSessionConfigSchema: z.ZodObject<{
326
537
  pageThreshold: z.ZodNumber;
327
538
  }, "strict", z.ZodTypeAny, {
@@ -331,6 +542,13 @@ declare const multiPageSessionConfigSchema: z.ZodObject<{
331
542
  }>;
332
543
  type MultiPageSessionConfig = z.infer<typeof multiPageSessionConfigSchema>;
333
544
 
545
+ /**
546
+ * Metadata for the automatic `page_view` event.
547
+ *
548
+ * The SDK emits this on initial load, SPA route changes, and bfcache restores.
549
+ * Consumers do not call `trackEvent('page_view', ...)`; registering
550
+ * `automatic: { page_view: {} }` enables the SDK-owned trigger.
551
+ */
334
552
  declare const pageViewMetadataSchema: z.ZodObject<{
335
553
  page: z.ZodObject<{
336
554
  title: z.ZodNullable<z.ZodString>;
@@ -385,9 +603,22 @@ declare const pageViewMetadataSchema: z.ZodObject<{
385
603
  } | null | undefined;
386
604
  }>;
387
605
  type PageViewMetadata = z.infer<typeof pageViewMetadataSchema>;
606
+ /**
607
+ * Registration config for automatic `page_view`.
608
+ *
609
+ * `page_view` is required in every trigger registry and currently has no
610
+ * options. Use `{ page_view: {} }`.
611
+ */
388
612
  declare const pageViewConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
389
613
  type PageViewConfig = z.infer<typeof pageViewConfigSchema>;
390
614
 
615
+ /**
616
+ * Metadata for a manually fired `phone_click` event.
617
+ *
618
+ * `phone_number` should be the business phone number from the clicked `tel:`
619
+ * link, not a visitor-entered phone number. `section` can distinguish header,
620
+ * footer, hero, or contact-page links.
621
+ */
391
622
  declare const phoneClickMetadataSchema: z.ZodObject<{
392
623
  phone_number: z.ZodString;
393
624
  page: z.ZodObject<{
@@ -412,9 +643,19 @@ declare const phoneClickMetadataSchema: z.ZodObject<{
412
643
  section?: string | null | undefined;
413
644
  }>;
414
645
  type PhoneClickMetadata = z.infer<typeof phoneClickMetadataSchema>;
646
+ /**
647
+ * Registration config for `phone_click`.
648
+ *
649
+ * This event is manual-only and currently has no registration options.
650
+ */
415
651
  declare const phoneClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
416
652
  type PhoneClickConfig = z.infer<typeof phoneClickConfigSchema>;
417
653
 
654
+ /**
655
+ * Metadata for the automatic `scroll_depth` event.
656
+ *
657
+ * Fired once per configured threshold per page.
658
+ */
418
659
  declare const scrollDepthMetadataSchema: z.ZodObject<{
419
660
  depth_percent: z.ZodNumber;
420
661
  page: z.ZodObject<{
@@ -436,6 +677,11 @@ declare const scrollDepthMetadataSchema: z.ZodObject<{
436
677
  depth_percent: number;
437
678
  }>;
438
679
  type ScrollDepthMetadata = z.infer<typeof scrollDepthMetadataSchema>;
680
+ /**
681
+ * Registration config for automatic `scroll_depth`.
682
+ *
683
+ * `thresholds` are integer percentages from 1 to 100.
684
+ */
439
685
  declare const scrollDepthConfigSchema: z.ZodObject<{
440
686
  thresholds: z.ZodArray<z.ZodNumber, "many">;
441
687
  }, "strict", z.ZodTypeAny, {
@@ -445,8 +691,17 @@ declare const scrollDepthConfigSchema: z.ZodObject<{
445
691
  }>;
446
692
  type ScrollDepthConfig = z.infer<typeof scrollDepthConfigSchema>;
447
693
 
694
+ /**
695
+ * Canonical page intent names supported by `specific_page_visit`.
696
+ */
448
697
  declare const SPECIFIC_PAGE_NAMES: readonly ["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"];
449
698
  type SpecificPageName = (typeof SPECIFIC_PAGE_NAMES)[number];
699
+ /**
700
+ * Metadata for the automatic `specific_page_visit` event.
701
+ *
702
+ * The SDK emits this when the current pathname matches one of the configured
703
+ * named page patterns.
704
+ */
450
705
  declare const specificPageVisitMetadataSchema: z.ZodObject<{
451
706
  page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
452
707
  page: z.ZodObject<{
@@ -468,6 +723,12 @@ declare const specificPageVisitMetadataSchema: z.ZodObject<{
468
723
  page_name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
469
724
  }>;
470
725
  type SpecificPageVisitMetadata = z.infer<typeof specificPageVisitMetadataSchema>;
726
+ /**
727
+ * Registration config for automatic `specific_page_visit`.
728
+ *
729
+ * Each page entry pairs a semantic `name` with a `RegExp` that matches the
730
+ * pathname. Use this instead of hard-coding path regexes downstream.
731
+ */
471
732
  declare const specificPageVisitConfigSchema: z.ZodObject<{
472
733
  pages: z.ZodArray<z.ZodObject<{
473
734
  name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
@@ -492,6 +753,12 @@ declare const specificPageVisitConfigSchema: z.ZodObject<{
492
753
  }>;
493
754
  type SpecificPageVisitConfig = z.infer<typeof specificPageVisitConfigSchema>;
494
755
 
756
+ /**
757
+ * Metadata for the automatic `time_on_site` event.
758
+ *
759
+ * The SDK starts a visibility-aware timer and fires once when visible
760
+ * engagement crosses the configured threshold.
761
+ */
495
762
  declare const timeOnSiteMetadataSchema: z.ZodObject<{
496
763
  duration_ms: z.ZodNumber;
497
764
  page: z.ZodObject<{
@@ -513,6 +780,9 @@ declare const timeOnSiteMetadataSchema: z.ZodObject<{
513
780
  duration_ms: number;
514
781
  }>;
515
782
  type TimeOnSiteMetadata = z.infer<typeof timeOnSiteMetadataSchema>;
783
+ /**
784
+ * Registration config for automatic `time_on_site`.
785
+ */
516
786
  declare const timeOnSiteConfigSchema: z.ZodObject<{
517
787
  thresholdSeconds: z.ZodNumber;
518
788
  }, "strict", z.ZodTypeAny, {
@@ -777,6 +1047,7 @@ declare const EVENT_REGISTRY: {
777
1047
  manual: string[];
778
1048
  }>;
779
1049
  trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
1050
+ configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
780
1051
  }, "strict", z.ZodTypeAny, {
781
1052
  sdk_version: string;
782
1053
  package_name: string | null;
@@ -786,6 +1057,7 @@ declare const EVENT_REGISTRY: {
786
1057
  manual: string[];
787
1058
  };
788
1059
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
1060
+ configured_gtag_ids?: Record<string, string> | null | undefined;
789
1061
  }, {
790
1062
  sdk_version: string;
791
1063
  package_name: string | null;
@@ -795,6 +1067,7 @@ declare const EVENT_REGISTRY: {
795
1067
  manual: string[];
796
1068
  };
797
1069
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
1070
+ configured_gtag_ids?: Record<string, string> | null | undefined;
798
1071
  }>;
799
1072
  readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
800
1073
  };
@@ -935,10 +1208,21 @@ declare const EVENT_REGISTRY: {
935
1208
  readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
936
1209
  };
937
1210
  };
1211
+ /**
1212
+ * Name of any event known to the tracking SDK.
1213
+ */
938
1214
  type EventName = keyof typeof EVENT_REGISTRY;
1215
+ /**
1216
+ * Event names that are fired by the SDK when their configured signal occurs.
1217
+ *
1218
+ * Automatic events are not accepted by the typed `trackEvent()` API.
1219
+ */
939
1220
  type AutomaticEventName = {
940
1221
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'automatic' ? K : never;
941
1222
  }[EventName];
1223
+ /**
1224
+ * Event names that consumer code can fire manually after registering them.
1225
+ */
942
1226
  type ManualEventName = {
943
1227
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'manual' ? K : never;
944
1228
  }[EventName];
@@ -966,8 +1250,44 @@ type ConfigByName = {
966
1250
  phone_click: PhoneClickConfig;
967
1251
  cta_click: CtaClickConfig;
968
1252
  };
1253
+ /**
1254
+ * Metadata payload type for a specific tracking event.
1255
+ *
1256
+ * @example
1257
+ * ```ts
1258
+ * type SubmitMetadata = EventMetadata<'form_submit'>;
1259
+ * ```
1260
+ */
969
1261
  type EventMetadata<K extends EventName> = MetadataByName[K];
1262
+ /**
1263
+ * Trigger registration config type for a specific tracking event.
1264
+ */
970
1265
  type EventConfig<K extends EventName> = ConfigByName[K];
1266
+ /**
1267
+ * Trigger registry passed to `createTracking({ triggers })`.
1268
+ *
1269
+ * `automatic.page_view` is required because every install should capture page
1270
+ * views. Other automatic events are opt-in. Manual events must be registered
1271
+ * here before the typed client accepts `trackEvent()` calls for them.
1272
+ *
1273
+ * @example
1274
+ * ```ts
1275
+ * createTracking({
1276
+ * apiKey,
1277
+ * endpoint,
1278
+ * triggers: {
1279
+ * automatic: {
1280
+ * page_view: {},
1281
+ * time_on_site: { thresholdSeconds: 60 },
1282
+ * },
1283
+ * manual: {
1284
+ * form_submit: {},
1285
+ * phone_click: {},
1286
+ * },
1287
+ * },
1288
+ * });
1289
+ * ```
1290
+ */
971
1291
  type TriggerRegistryConfig = {
972
1292
  automatic: {
973
1293
  page_view: EventConfig<'page_view'>;
@@ -984,29 +1304,70 @@ type TriggerRegistryConfig = {
984
1304
  cta_click: EventConfig<'cta_click'>;
985
1305
  }>;
986
1306
  };
1307
+ /**
1308
+ * Manual event names registered in a concrete trigger registry.
1309
+ *
1310
+ * Used by `TypedTrackingClient` so `trackEvent()` only accepts events the
1311
+ * consumer explicitly enabled.
1312
+ */
987
1313
  type RegisteredManualEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof NonNullable<TRegistry['manual']>, ManualEventName>;
1314
+ /**
1315
+ * Automatic event names registered in a concrete trigger registry.
1316
+ */
988
1317
  type RegisteredAutomaticEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof TRegistry['automatic'], AutomaticEventName>;
989
1318
 
1319
+ /**
1320
+ * Input accepted by the low-level stringly-typed client.
1321
+ *
1322
+ * Prefer the typed `trackEvent(eventName, metadata)` facade exposed by
1323
+ * `useTracking()` in React/Next integrations.
1324
+ */
990
1325
  interface TrackEventInput {
1326
+ /** Event name to enqueue. */
991
1327
  eventType: string;
1328
+ /** URL associated with the event. Defaults to the current page URL. */
992
1329
  pageUrl?: string | null;
1330
+ /** Event-specific metadata. */
993
1331
  metadata?: Record<string, unknown> | null;
1332
+ /** Timestamp override. Defaults to queue time. */
994
1333
  occurredAt?: Date | string | null;
995
1334
  }
1335
+ /**
1336
+ * Low-level tracking client responsible for queueing and flushing events.
1337
+ */
996
1338
  interface TrackingClient {
1339
+ /** Enqueue an event for batched delivery. */
997
1340
  trackEvent: (input: TrackEventInput) => void;
1341
+ /** Flush queued events immediately. */
998
1342
  flush: () => Promise<void>;
1343
+ /** Return the current rolling session id. */
999
1344
  getSessionId: () => string;
1345
+ /** Return the persistent visitor id. */
1000
1346
  getVisitorId: () => string;
1347
+ /** Remove timers/listeners and prevent future flushes. */
1001
1348
  destroy: () => void;
1002
1349
  }
1003
1350
 
1004
1351
  interface TypedTrackEventOptions {
1005
- /** Override the page URL captured automatically. Rarely needed. */
1352
+ /**
1353
+ * Override the page URL associated with this event.
1354
+ *
1355
+ * Omit this for normal browser usage; the SDK captures `window.location.href`.
1356
+ */
1006
1357
  pageUrl?: string | null;
1007
- /** Event timestamp override. Defaults to "now" at queue time. */
1358
+ /**
1359
+ * Override the event timestamp.
1360
+ *
1361
+ * Defaults to the time the event is queued. Accepts a `Date` or ISO string.
1362
+ */
1008
1363
  occurredAt?: Date | string | null;
1009
1364
  }
1365
+ /**
1366
+ * Typed tracking client returned by `useTracking()`.
1367
+ *
1368
+ * The accepted event names and metadata shapes are narrowed from the concrete
1369
+ * trigger registry supplied to `createTracking()`.
1370
+ */
1010
1371
  interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
1011
1372
  /**
1012
1373
  * Fire a manually-registered event. The event name must be present in
@@ -1014,19 +1375,75 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
1014
1375
  * canonical Zod-derived shape.
1015
1376
  */
1016
1377
  trackEvent<K extends RegisteredManualEvents<TRegistry>>(eventType: K, metadata: EventMetadata<K>, options?: TypedTrackEventOptions): void;
1378
+ /**
1379
+ * Immediately flush queued events to the ingest endpoint.
1380
+ *
1381
+ * Normal consumers rarely need this because the SDK flushes on a debounce,
1382
+ * when the queue reaches the batch threshold, and on `pagehide`.
1383
+ */
1017
1384
  flush(): Promise<void>;
1385
+ /**
1386
+ * Return the current rolling session id.
1387
+ */
1018
1388
  getSessionId(): string;
1389
+ /**
1390
+ * Return the persistent visitor id for this browser profile.
1391
+ */
1019
1392
  getVisitorId(): string;
1020
1393
  }
1021
1394
 
1395
+ /**
1396
+ * Props for the Google Ads tracking component.
1397
+ *
1398
+ * Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
1399
+ * where ALL entries are loaded simultaneously via `gtag('config', ...)`.
1400
+ */
1401
+ type GoogleAdsTrackingProps = {
1402
+ gtagId: string;
1403
+ gtagIds?: undefined;
1404
+ } | {
1405
+ gtagId?: undefined;
1406
+ gtagIds: GtagEnvironmentMap;
1407
+ };
1408
+ /**
1409
+ * Client component that loads Google Ads gtag and restores stored consent.
1410
+ *
1411
+ * Render once near the application root when the client site runs paid Google
1412
+ * Ads. The component renders nothing.
1413
+ */
1414
+ declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): null;
1415
+
1416
+ /**
1417
+ * Read the captured Google Ads click id from first-party cookies.
1418
+ *
1419
+ * Returns `null` during SSR and before the client has mounted.
1420
+ */
1022
1421
  declare function useGclid(): string | null;
1422
+ /**
1423
+ * Read all captured attribution parameters from first-party cookies.
1424
+ *
1425
+ * Values are loaded after mount, so the initial render returns all `null`s.
1426
+ */
1023
1427
  declare function useTrackingParams(): TrackingParams;
1428
+ /**
1429
+ * Read the current visitor consent state and update when another tab changes
1430
+ * the stored value.
1431
+ */
1024
1432
  declare function useConsentState(): ConsentState;
1025
1433
 
1026
1434
  interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
1027
- /** Public tracking API key issued for this business. Required. */
1435
+ /**
1436
+ * Public tracking API key issued for this business.
1437
+ *
1438
+ * This key is safe to expose in browser code. Abuse is bounded by the
1439
+ * server-side origin allowlist and rate limits.
1440
+ */
1028
1441
  apiKey: string;
1029
- /** Full ingest endpoint base URL, e.g. https://api.aranova.io/tracking. Required. */
1442
+ /**
1443
+ * Tracking endpoint base URL, usually ending in `/tracking`.
1444
+ *
1445
+ * The client posts events to `${endpoint}/events`.
1446
+ */
1030
1447
  endpoint: string;
1031
1448
  /**
1032
1449
  * Trigger registry. Determines which events the SDK fires automatically
@@ -1034,6 +1451,14 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
1034
1451
  * `automatic.page_view` is required — every tracking install needs it.
1035
1452
  */
1036
1453
  triggers: TRegistry;
1454
+ /**
1455
+ * Deployment environment label reported in session context.
1456
+ *
1457
+ * Does not affect which gtag IDs are loaded — all configured IDs are
1458
+ * loaded simultaneously. This value is purely for event tagging so the
1459
+ * dashboard can filter by environment.
1460
+ */
1461
+ environment?: TrackingEnvironment;
1037
1462
  /**
1038
1463
  * When true, the typed client validates every `trackEvent()` metadata
1039
1464
  * payload through the Zod schema before forwarding. Errors are thrown
@@ -1042,12 +1467,35 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
1042
1467
  debug?: boolean;
1043
1468
  }
1044
1469
  interface TrackingProviderProps {
1045
- /** Optional Google Ads gtag id. If omitted, no gtag script is loaded. */
1470
+ /**
1471
+ * Optional Google Ads tag id, for example `AW-123456789`.
1472
+ *
1473
+ * If omitted and `gtagIds` is also omitted, no gtag script is loaded.
1474
+ */
1046
1475
  gtagId?: string;
1476
+ /**
1477
+ * Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
1478
+ * When provided, `gtagId` is ignored.
1479
+ */
1480
+ gtagIds?: GtagEnvironmentMap;
1481
+ /**
1482
+ * Application tree that should have access to the scoped tracking client.
1483
+ */
1047
1484
  children: ReactNode;
1048
1485
  }
1049
1486
  interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
1487
+ /**
1488
+ * Provider component that initializes the page-level tracking client.
1489
+ *
1490
+ * Mount this once near the root of the React tree.
1491
+ */
1050
1492
  TrackingProvider: (props: TrackingProviderProps) => ReactNode;
1493
+ /**
1494
+ * Hook that returns the registry-typed tracking client.
1495
+ *
1496
+ * Import this hook from your local tracking module, not directly from the
1497
+ * package root, so TypeScript preserves your trigger registry.
1498
+ */
1051
1499
  useTracking: () => TypedTrackingClient<TRegistry>;
1052
1500
  }
1053
1501
  declare function createTracking<TRegistry extends TriggerRegistryConfig>(options: CreateTrackingOptions<TRegistry>): CreateTrackingResult<TRegistry>;