@aranova/tracking-next 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/README.md CHANGED
@@ -78,6 +78,35 @@ export default function RootLayout({ children }: { children: React.ReactNode })
78
78
  }
79
79
  ```
80
80
 
81
+ ### Multiple gtag IDs
82
+
83
+ To install multiple Google Ads tags simultaneously (for example a production MCC and a test MCC for verifying conversion actions before they touch the live account), pass `gtagIds` instead of `gtagId`. Every entry fires `gtag('config', ...)` on every page — gtag natively supports multiple configured tags.
84
+
85
+ ```tsx
86
+ <GoogleAdsTracking
87
+ gtagIds={{
88
+ production: 'AW-111111111', // real client account
89
+ test: 'AW-222222222', // test MCC for development
90
+ }}
91
+ />
92
+ ```
93
+
94
+ The labels are arbitrary and surface in the Aranova dashboard's SDK versions table. Also pass `environment` to the factory so events are tagged with the deployment context for dashboard filtering:
95
+
96
+ ```ts
97
+ // lib/tracking.ts
98
+ createTracking({
99
+ apiKey: process.env.NEXT_PUBLIC_ARANOVA_TRACKING_API_KEY!,
100
+ endpoint: process.env.NEXT_PUBLIC_ARANOVA_TRACKING_ENDPOINT!,
101
+ environment: process.env.NEXT_PUBLIC_TRACKING_ENVIRONMENT, // 'production' | 'development'
102
+ gtagIds: { // optional — reports the configured tags in heartbeat metadata
103
+ production: process.env.NEXT_PUBLIC_GTAG_PROD!,
104
+ test: process.env.NEXT_PUBLIC_GTAG_TEST!,
105
+ },
106
+ triggers: { /* ... */ },
107
+ });
108
+ ```
109
+
81
110
  ## Manual Events
82
111
 
83
112
  Import `useTracking` from your local `lib/tracking` module, not directly from the package.
package/dist/index.d.mts CHANGED
@@ -1,12 +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.mjs';
2
- export { e as TrackingInitConfig } from './types-Gp0ioRiQ.mjs';
1
+ import { C as ConsentState, T as TrackingInstallSurface, a as TrackingEnvironment, b as TrackingClientContext, c as TrackingParams, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, G as GtagEnvironmentMap } from './types-D0Vm9WRC.mjs';
2
+ export { f as TrackingInitConfig } from './types-D0Vm9WRC.mjs';
3
3
  import { z } from 'zod';
4
4
  import * as src from 'src';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ReactNode } from 'react';
7
7
 
8
+ /**
9
+ * Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
10
+ */
8
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
+ */
9
18
  declare function getConsentState(): ConsentState;
19
+ /**
20
+ * Persist a visitor consent choice and update Google Consent Mode when gtag is
21
+ * loaded.
22
+ */
10
23
  declare function setConsentState(state: GtagConsentValue): void;
11
24
 
12
25
  interface TrackingContextInput {
@@ -15,6 +28,8 @@ interface TrackingContextInput {
15
28
  referrer?: string | null;
16
29
  sdkVersion?: string | null;
17
30
  siteOrigin?: string | null;
31
+ environment?: TrackingEnvironment | null;
32
+ activeGtagIds?: Record<string, string> | null;
18
33
  }
19
34
  interface TrackingEventInput {
20
35
  eventType: string;
@@ -28,13 +43,37 @@ interface TrackingSessionInput {
28
43
  sessionId: string;
29
44
  visitorId?: string | null;
30
45
  }
46
+ /**
47
+ * Build runtime context attached to tracking sessions and events.
48
+ */
31
49
  declare function createTrackingClientContext(surface: TrackingInstallSurface, input?: TrackingContextInput): TrackingClientContext;
50
+ /**
51
+ * Build the session portion of a tracking ingest request.
52
+ */
32
53
  declare function createTrackingSessionUpsertPayload(trackingParams: TrackingParams, input: TrackingSessionInput, context: TrackingClientContext): TrackingSessionUpsertPayload;
54
+ /**
55
+ * Build one event payload before it is batched into a tracking ingest request.
56
+ */
33
57
  declare function createTrackingEventCreatePayload(trackingParams: TrackingParams, input: TrackingEventInput, context: TrackingClientContext): TrackingEventCreatePayload;
34
58
 
59
+ /**
60
+ * Attribution query/cookie keys captured by the SDK.
61
+ */
35
62
  declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
63
+ /**
64
+ * Capture tracking params from a URL, persist them to first-party cookies, and
65
+ * return the current cookie-backed attribution state.
66
+ *
67
+ * Defaults to `window.location.href` in the browser.
68
+ */
36
69
  declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
37
70
 
71
+ /**
72
+ * Metadata for a manually fired `cta_click` event.
73
+ *
74
+ * Use this for non-phone calls to action such as directions, appointment
75
+ * buttons, downloads, or external booking links.
76
+ */
38
77
  declare const ctaClickMetadataSchema: z.ZodObject<{
39
78
  cta_name: z.ZodString;
40
79
  page: z.ZodObject<{
@@ -62,9 +101,21 @@ declare const ctaClickMetadataSchema: z.ZodObject<{
62
101
  destination_url?: string | null | undefined;
63
102
  }>;
64
103
  type CtaClickMetadata = z.infer<typeof ctaClickMetadataSchema>;
104
+ /**
105
+ * Registration config for `cta_click`.
106
+ *
107
+ * This event is manual-only and currently has no registration options.
108
+ */
65
109
  declare const ctaClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
66
110
  type CtaClickConfig = z.infer<typeof ctaClickConfigSchema>;
67
111
 
112
+ /**
113
+ * Metadata for the SDK-internal `sdk_heartbeat` event.
114
+ *
115
+ * The SDK fires this once per new session so the dashboard can show which SDK
116
+ * version, install surface, and trigger registry a client site is running.
117
+ * Consumers do not manually register or fire this event.
118
+ */
68
119
  declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
69
120
  sdk_version: z.ZodString;
70
121
  package_name: z.ZodNullable<z.ZodString>;
@@ -80,6 +131,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
80
131
  manual: string[];
81
132
  }>;
82
133
  trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
134
+ configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
83
135
  }, "strict", z.ZodTypeAny, {
84
136
  sdk_version: string;
85
137
  package_name: string | null;
@@ -89,6 +141,7 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
89
141
  manual: string[];
90
142
  };
91
143
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
144
+ configured_gtag_ids?: Record<string, string> | null | undefined;
92
145
  }, {
93
146
  sdk_version: string;
94
147
  package_name: string | null;
@@ -98,11 +151,22 @@ declare const sdkHeartbeatMetadataSchema: z.ZodObject<{
98
151
  manual: string[];
99
152
  };
100
153
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
154
+ configured_gtag_ids?: Record<string, string> | null | undefined;
101
155
  }>;
102
156
  type SdkHeartbeatMetadata = z.infer<typeof sdkHeartbeatMetadataSchema>;
157
+ /**
158
+ * Internal registration config for `sdk_heartbeat`.
159
+ *
160
+ * This event has no consumer-facing options.
161
+ */
103
162
  declare const sdkHeartbeatConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
104
163
  type SdkHeartbeatConfig = z.infer<typeof sdkHeartbeatConfigSchema>;
105
164
 
165
+ /**
166
+ * Metadata for the automatic `form_start` event.
167
+ *
168
+ * The SDK emits this once per form when the visitor first focuses a field.
169
+ */
106
170
  declare const formStartMetadataSchema: z.ZodObject<{
107
171
  form: z.ZodObject<{
108
172
  id: z.ZodString;
@@ -139,6 +203,12 @@ declare const formStartMetadataSchema: z.ZodObject<{
139
203
  };
140
204
  }>;
141
205
  type FormStartMetadata = z.infer<typeof formStartMetadataSchema>;
206
+ /**
207
+ * Registration config for automatic `form_start`.
208
+ *
209
+ * Use `selector` to narrow which forms can trigger the event. When omitted,
210
+ * the SDK observes all `<form>` elements.
211
+ */
142
212
  declare const formStartConfigSchema: z.ZodObject<{
143
213
  selector: z.ZodOptional<z.ZodString>;
144
214
  }, "strict", z.ZodTypeAny, {
@@ -148,9 +218,46 @@ declare const formStartConfigSchema: z.ZodObject<{
148
218
  }>;
149
219
  type FormStartConfig = z.infer<typeof formStartConfigSchema>;
150
220
 
221
+ /**
222
+ * JSON-serializable value accepted by `form_submit.fields[].value`.
223
+ *
224
+ * This intentionally excludes `undefined`, functions, symbols, `Date`
225
+ * instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
226
+ * consumers should send only data that has a stable JSON representation.
227
+ */
151
228
  type JsonValue = string | number | boolean | null | JsonValue[] | {
152
229
  [key: string]: JsonValue;
153
230
  };
231
+ /**
232
+ * Metadata for a manually fired `form_submit` event.
233
+ *
234
+ * Register the event with `manual: { form_submit: {} }`, then call
235
+ * `trackEvent('form_submit', metadata)` from the host site's submit handler.
236
+ *
237
+ * `fields` is optional. If present, each field value must be JSON-serializable
238
+ * and should be explicitly allowlisted by the integration. Do not send names,
239
+ * emails, visitor phone numbers, addresses, payment data, medical details,
240
+ * passwords, file contents, or free-text messages.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * tracking.trackEvent('form_submit', {
245
+ * form: {
246
+ * id: 'lead-form',
247
+ * action: '/api/lead',
248
+ * fields: [
249
+ * {
250
+ * name: 'service_interest',
251
+ * type: 'select',
252
+ * label: 'Service interest',
253
+ * value: 'teeth_whitening',
254
+ * },
255
+ * ],
256
+ * },
257
+ * page: { path: window.location.pathname },
258
+ * });
259
+ * ```
260
+ */
154
261
  declare const formSubmitMetadataSchema: z.ZodObject<{
155
262
  form: z.ZodObject<{
156
263
  id: z.ZodString;
@@ -227,9 +334,21 @@ declare const formSubmitMetadataSchema: z.ZodObject<{
227
334
  };
228
335
  }>;
229
336
  type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
337
+ /**
338
+ * Registration config for `form_submit`.
339
+ *
340
+ * This event is manual-only and currently has no registration options. The
341
+ * empty object enables typed `trackEvent('form_submit', ...)` calls.
342
+ */
230
343
  declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
231
344
  type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
232
345
 
346
+ /**
347
+ * Metadata for the automatic `multi_page_session` event.
348
+ *
349
+ * Fired when the visitor reaches the configured distinct-page threshold in a
350
+ * single tracking session.
351
+ */
233
352
  declare const multiPageSessionMetadataSchema: z.ZodObject<{
234
353
  page_count: z.ZodNumber;
235
354
  page: z.ZodObject<{
@@ -251,6 +370,9 @@ declare const multiPageSessionMetadataSchema: z.ZodObject<{
251
370
  page_count: number;
252
371
  }>;
253
372
  type MultiPageSessionMetadata = z.infer<typeof multiPageSessionMetadataSchema>;
373
+ /**
374
+ * Registration config for automatic `multi_page_session`.
375
+ */
254
376
  declare const multiPageSessionConfigSchema: z.ZodObject<{
255
377
  pageThreshold: z.ZodNumber;
256
378
  }, "strict", z.ZodTypeAny, {
@@ -260,6 +382,13 @@ declare const multiPageSessionConfigSchema: z.ZodObject<{
260
382
  }>;
261
383
  type MultiPageSessionConfig = z.infer<typeof multiPageSessionConfigSchema>;
262
384
 
385
+ /**
386
+ * Metadata for the automatic `page_view` event.
387
+ *
388
+ * The SDK emits this on initial load, SPA route changes, and bfcache restores.
389
+ * Consumers do not call `trackEvent('page_view', ...)`; registering
390
+ * `automatic: { page_view: {} }` enables the SDK-owned trigger.
391
+ */
263
392
  declare const pageViewMetadataSchema: z.ZodObject<{
264
393
  page: z.ZodObject<{
265
394
  title: z.ZodNullable<z.ZodString>;
@@ -314,9 +443,22 @@ declare const pageViewMetadataSchema: z.ZodObject<{
314
443
  } | null | undefined;
315
444
  }>;
316
445
  type PageViewMetadata = z.infer<typeof pageViewMetadataSchema>;
446
+ /**
447
+ * Registration config for automatic `page_view`.
448
+ *
449
+ * `page_view` is required in every trigger registry and currently has no
450
+ * options. Use `{ page_view: {} }`.
451
+ */
317
452
  declare const pageViewConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
318
453
  type PageViewConfig = z.infer<typeof pageViewConfigSchema>;
319
454
 
455
+ /**
456
+ * Metadata for a manually fired `phone_click` event.
457
+ *
458
+ * `phone_number` should be the business phone number from the clicked `tel:`
459
+ * link, not a visitor-entered phone number. `section` can distinguish header,
460
+ * footer, hero, or contact-page links.
461
+ */
320
462
  declare const phoneClickMetadataSchema: z.ZodObject<{
321
463
  phone_number: z.ZodString;
322
464
  page: z.ZodObject<{
@@ -341,9 +483,19 @@ declare const phoneClickMetadataSchema: z.ZodObject<{
341
483
  section?: string | null | undefined;
342
484
  }>;
343
485
  type PhoneClickMetadata = z.infer<typeof phoneClickMetadataSchema>;
486
+ /**
487
+ * Registration config for `phone_click`.
488
+ *
489
+ * This event is manual-only and currently has no registration options.
490
+ */
344
491
  declare const phoneClickConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
345
492
  type PhoneClickConfig = z.infer<typeof phoneClickConfigSchema>;
346
493
 
494
+ /**
495
+ * Metadata for the automatic `scroll_depth` event.
496
+ *
497
+ * Fired once per configured threshold per page.
498
+ */
347
499
  declare const scrollDepthMetadataSchema: z.ZodObject<{
348
500
  depth_percent: z.ZodNumber;
349
501
  page: z.ZodObject<{
@@ -365,6 +517,11 @@ declare const scrollDepthMetadataSchema: z.ZodObject<{
365
517
  depth_percent: number;
366
518
  }>;
367
519
  type ScrollDepthMetadata = z.infer<typeof scrollDepthMetadataSchema>;
520
+ /**
521
+ * Registration config for automatic `scroll_depth`.
522
+ *
523
+ * `thresholds` are integer percentages from 1 to 100.
524
+ */
368
525
  declare const scrollDepthConfigSchema: z.ZodObject<{
369
526
  thresholds: z.ZodArray<z.ZodNumber, "many">;
370
527
  }, "strict", z.ZodTypeAny, {
@@ -374,8 +531,17 @@ declare const scrollDepthConfigSchema: z.ZodObject<{
374
531
  }>;
375
532
  type ScrollDepthConfig = z.infer<typeof scrollDepthConfigSchema>;
376
533
 
534
+ /**
535
+ * Canonical page intent names supported by `specific_page_visit`.
536
+ */
377
537
  declare const SPECIFIC_PAGE_NAMES: readonly ["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"];
378
538
  type SpecificPageName = (typeof SPECIFIC_PAGE_NAMES)[number];
539
+ /**
540
+ * Metadata for the automatic `specific_page_visit` event.
541
+ *
542
+ * The SDK emits this when the current pathname matches one of the configured
543
+ * named page patterns.
544
+ */
379
545
  declare const specificPageVisitMetadataSchema: z.ZodObject<{
380
546
  page_name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
381
547
  page: z.ZodObject<{
@@ -397,6 +563,12 @@ declare const specificPageVisitMetadataSchema: z.ZodObject<{
397
563
  page_name: "contact_page" | "about_page" | "services_page" | "booking_page" | "location_page" | "pricing_page" | "faq_page" | "testimonials_page";
398
564
  }>;
399
565
  type SpecificPageVisitMetadata = z.infer<typeof specificPageVisitMetadataSchema>;
566
+ /**
567
+ * Registration config for automatic `specific_page_visit`.
568
+ *
569
+ * Each page entry pairs a semantic `name` with a `RegExp` that matches the
570
+ * pathname. Use this instead of hard-coding path regexes downstream.
571
+ */
400
572
  declare const specificPageVisitConfigSchema: z.ZodObject<{
401
573
  pages: z.ZodArray<z.ZodObject<{
402
574
  name: z.ZodEnum<["contact_page", "about_page", "services_page", "booking_page", "location_page", "pricing_page", "faq_page", "testimonials_page"]>;
@@ -421,6 +593,12 @@ declare const specificPageVisitConfigSchema: z.ZodObject<{
421
593
  }>;
422
594
  type SpecificPageVisitConfig = z.infer<typeof specificPageVisitConfigSchema>;
423
595
 
596
+ /**
597
+ * Metadata for the automatic `time_on_site` event.
598
+ *
599
+ * The SDK starts a visibility-aware timer and fires once when visible
600
+ * engagement crosses the configured threshold.
601
+ */
424
602
  declare const timeOnSiteMetadataSchema: z.ZodObject<{
425
603
  duration_ms: z.ZodNumber;
426
604
  page: z.ZodObject<{
@@ -442,6 +620,9 @@ declare const timeOnSiteMetadataSchema: z.ZodObject<{
442
620
  duration_ms: number;
443
621
  }>;
444
622
  type TimeOnSiteMetadata = z.infer<typeof timeOnSiteMetadataSchema>;
623
+ /**
624
+ * Registration config for automatic `time_on_site`.
625
+ */
445
626
  declare const timeOnSiteConfigSchema: z.ZodObject<{
446
627
  thresholdSeconds: z.ZodNumber;
447
628
  }, "strict", z.ZodTypeAny, {
@@ -706,6 +887,7 @@ declare const EVENT_REGISTRY: {
706
887
  manual: string[];
707
888
  }>;
708
889
  trigger_config: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
890
+ configured_gtag_ids: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>>;
709
891
  }, "strict", z.ZodTypeAny, {
710
892
  sdk_version: string;
711
893
  package_name: string | null;
@@ -715,6 +897,7 @@ declare const EVENT_REGISTRY: {
715
897
  manual: string[];
716
898
  };
717
899
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
900
+ configured_gtag_ids?: Record<string, string> | null | undefined;
718
901
  }, {
719
902
  sdk_version: string;
720
903
  package_name: string | null;
@@ -724,6 +907,7 @@ declare const EVENT_REGISTRY: {
724
907
  manual: string[];
725
908
  };
726
909
  trigger_config?: Record<string, Record<string, unknown>> | null | undefined;
910
+ configured_gtag_ids?: Record<string, string> | null | undefined;
727
911
  }>;
728
912
  readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
729
913
  };
@@ -864,10 +1048,21 @@ declare const EVENT_REGISTRY: {
864
1048
  readonly configSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
865
1049
  };
866
1050
  };
1051
+ /**
1052
+ * Name of any event known to the tracking SDK.
1053
+ */
867
1054
  type EventName = keyof typeof EVENT_REGISTRY;
1055
+ /**
1056
+ * Event names that are fired by the SDK when their configured signal occurs.
1057
+ *
1058
+ * Automatic events are not accepted by the typed `trackEvent()` API.
1059
+ */
868
1060
  type AutomaticEventName = {
869
1061
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'automatic' ? K : never;
870
1062
  }[EventName];
1063
+ /**
1064
+ * Event names that consumer code can fire manually after registering them.
1065
+ */
871
1066
  type ManualEventName = {
872
1067
  [K in EventName]: (typeof EVENT_REGISTRY)[K]['kind'] extends 'manual' ? K : never;
873
1068
  }[EventName];
@@ -895,8 +1090,44 @@ type ConfigByName = {
895
1090
  phone_click: PhoneClickConfig;
896
1091
  cta_click: CtaClickConfig;
897
1092
  };
1093
+ /**
1094
+ * Metadata payload type for a specific tracking event.
1095
+ *
1096
+ * @example
1097
+ * ```ts
1098
+ * type SubmitMetadata = EventMetadata<'form_submit'>;
1099
+ * ```
1100
+ */
898
1101
  type EventMetadata<K extends EventName> = MetadataByName[K];
1102
+ /**
1103
+ * Trigger registration config type for a specific tracking event.
1104
+ */
899
1105
  type EventConfig<K extends EventName> = ConfigByName[K];
1106
+ /**
1107
+ * Trigger registry passed to `createTracking({ triggers })`.
1108
+ *
1109
+ * `automatic.page_view` is required because every install should capture page
1110
+ * views. Other automatic events are opt-in. Manual events must be registered
1111
+ * here before the typed client accepts `trackEvent()` calls for them.
1112
+ *
1113
+ * @example
1114
+ * ```ts
1115
+ * createTracking({
1116
+ * apiKey,
1117
+ * endpoint,
1118
+ * triggers: {
1119
+ * automatic: {
1120
+ * page_view: {},
1121
+ * time_on_site: { thresholdSeconds: 60 },
1122
+ * },
1123
+ * manual: {
1124
+ * form_submit: {},
1125
+ * phone_click: {},
1126
+ * },
1127
+ * },
1128
+ * });
1129
+ * ```
1130
+ */
900
1131
  type TriggerRegistryConfig = {
901
1132
  automatic: {
902
1133
  page_view: EventConfig<'page_view'>;
@@ -913,29 +1144,70 @@ type TriggerRegistryConfig = {
913
1144
  cta_click: EventConfig<'cta_click'>;
914
1145
  }>;
915
1146
  };
1147
+ /**
1148
+ * Manual event names registered in a concrete trigger registry.
1149
+ *
1150
+ * Used by `TypedTrackingClient` so `trackEvent()` only accepts events the
1151
+ * consumer explicitly enabled.
1152
+ */
916
1153
  type RegisteredManualEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof NonNullable<TRegistry['manual']>, ManualEventName>;
1154
+ /**
1155
+ * Automatic event names registered in a concrete trigger registry.
1156
+ */
917
1157
  type RegisteredAutomaticEvents<TRegistry extends TriggerRegistryConfig> = Extract<keyof TRegistry['automatic'], AutomaticEventName>;
918
1158
 
1159
+ /**
1160
+ * Input accepted by the low-level stringly-typed client.
1161
+ *
1162
+ * Prefer the typed `trackEvent(eventName, metadata)` facade exposed by
1163
+ * `useTracking()` in React/Next integrations.
1164
+ */
919
1165
  interface TrackEventInput {
1166
+ /** Event name to enqueue. */
920
1167
  eventType: string;
1168
+ /** URL associated with the event. Defaults to the current page URL. */
921
1169
  pageUrl?: string | null;
1170
+ /** Event-specific metadata. */
922
1171
  metadata?: Record<string, unknown> | null;
1172
+ /** Timestamp override. Defaults to queue time. */
923
1173
  occurredAt?: Date | string | null;
924
1174
  }
1175
+ /**
1176
+ * Low-level tracking client responsible for queueing and flushing events.
1177
+ */
925
1178
  interface TrackingClient {
1179
+ /** Enqueue an event for batched delivery. */
926
1180
  trackEvent: (input: TrackEventInput) => void;
1181
+ /** Flush queued events immediately. */
927
1182
  flush: () => Promise<void>;
1183
+ /** Return the current rolling session id. */
928
1184
  getSessionId: () => string;
1185
+ /** Return the persistent visitor id. */
929
1186
  getVisitorId: () => string;
1187
+ /** Remove timers/listeners and prevent future flushes. */
930
1188
  destroy: () => void;
931
1189
  }
932
1190
 
933
1191
  interface TypedTrackEventOptions {
934
- /** Override the page URL captured automatically. Rarely needed. */
1192
+ /**
1193
+ * Override the page URL associated with this event.
1194
+ *
1195
+ * Omit this for normal browser usage; the SDK captures `window.location.href`.
1196
+ */
935
1197
  pageUrl?: string | null;
936
- /** Event timestamp override. Defaults to "now" at queue time. */
1198
+ /**
1199
+ * Override the event timestamp.
1200
+ *
1201
+ * Defaults to the time the event is queued. Accepts a `Date` or ISO string.
1202
+ */
937
1203
  occurredAt?: Date | string | null;
938
1204
  }
1205
+ /**
1206
+ * Typed tracking client returned by `useTracking()`.
1207
+ *
1208
+ * The accepted event names and metadata shapes are narrowed from the concrete
1209
+ * trigger registry supplied to `createTracking()`.
1210
+ */
939
1211
  interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
940
1212
  /**
941
1213
  * Fire a manually-registered event. The event name must be present in
@@ -943,37 +1215,124 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
943
1215
  * canonical Zod-derived shape.
944
1216
  */
945
1217
  trackEvent<K extends RegisteredManualEvents<TRegistry>>(eventType: K, metadata: EventMetadata<K>, options?: TypedTrackEventOptions): void;
1218
+ /**
1219
+ * Immediately flush queued events to the ingest endpoint.
1220
+ *
1221
+ * Normal consumers rarely need this because the SDK flushes on a debounce,
1222
+ * when the queue reaches the batch threshold, and on `pagehide`.
1223
+ */
946
1224
  flush(): Promise<void>;
1225
+ /**
1226
+ * Return the current rolling session id.
1227
+ */
947
1228
  getSessionId(): string;
1229
+ /**
1230
+ * Return the persistent visitor id for this browser profile.
1231
+ */
948
1232
  getVisitorId(): string;
949
1233
  }
950
1234
 
1235
+ /**
1236
+ * Default non-blocking consent banner for Next.js installs.
1237
+ *
1238
+ * Renders only while consent is `pending`. Accept/decline choices are stored
1239
+ * in localStorage and propagated to Google Consent Mode when gtag is loaded.
1240
+ */
951
1241
  declare function ConsentBanner(): react_jsx_runtime.JSX.Element | null;
952
1242
 
1243
+ /**
1244
+ * Read the captured Google Ads click id from first-party cookies.
1245
+ *
1246
+ * Returns `null` during SSR and before the client has mounted.
1247
+ */
953
1248
  declare function useGclid(): string | null;
1249
+ /**
1250
+ * Read all captured attribution parameters from first-party cookies.
1251
+ *
1252
+ * Values are loaded after mount, so the initial render returns all `null`s.
1253
+ */
954
1254
  declare function useTrackingParams(): TrackingParams;
1255
+ /**
1256
+ * Read the current visitor consent state and update when another tab changes
1257
+ * the stored value.
1258
+ */
955
1259
  declare function useConsentState(): ConsentState;
956
1260
 
957
- interface GoogleAdsTrackingProps {
1261
+ /**
1262
+ * Props for the Next.js Google Ads tracking component.
1263
+ *
1264
+ * Accepts either a single `gtagId` (legacy) or a labelled `gtagIds` map
1265
+ * where ALL entries are loaded simultaneously via `gtag('config', ...)`.
1266
+ */
1267
+ type GoogleAdsTrackingProps = {
958
1268
  gtagId: string;
959
- }
960
- declare function GoogleAdsTracking({ gtagId }: GoogleAdsTrackingProps): react_jsx_runtime.JSX.Element;
1269
+ gtagIds?: undefined;
1270
+ } | {
1271
+ gtagId?: undefined;
1272
+ gtagIds: GtagEnvironmentMap;
1273
+ };
1274
+ /**
1275
+ * Next.js client component that loads Google Ads gtag with Consent Mode.
1276
+ *
1277
+ * Render in the root layout `<head>` when the client site runs paid Google
1278
+ * Ads. The component injects Next `<Script>` tags and renders no visible UI.
1279
+ */
1280
+ declare function GoogleAdsTracking(props: GoogleAdsTrackingProps): react_jsx_runtime.JSX.Element | null;
961
1281
 
962
1282
  interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
1283
+ /**
1284
+ * Public tracking API key issued for this business.
1285
+ *
1286
+ * This key is safe to expose via `NEXT_PUBLIC_*` env vars.
1287
+ */
963
1288
  apiKey: string;
1289
+ /**
1290
+ * Tracking endpoint base URL, usually ending in `/tracking`.
1291
+ */
964
1292
  endpoint: string;
1293
+ /**
1294
+ * Trigger registry that controls automatic events and typed manual events.
1295
+ */
965
1296
  triggers: TRegistry;
1297
+ /**
1298
+ * Deployment environment label reported in session context.
1299
+ */
1300
+ environment?: TrackingEnvironment;
1301
+ /**
1302
+ * Labelled map of Google Ads tag IDs. Included in session context and
1303
+ * heartbeat metadata so the dashboard can show what's configured.
1304
+ *
1305
+ * This does NOT load the gtag scripts — use `<GoogleAdsTracking gtagIds={...} />`
1306
+ * in the root layout for that. This option only controls what's reported
1307
+ * in the tracking payload context.
1308
+ */
1309
+ gtagIds?: Record<string, string>;
1310
+ /**
1311
+ * Validate manual event metadata at runtime before queueing.
1312
+ *
1313
+ * Enable in development to catch shape bugs. Leave disabled in production so
1314
+ * analytics can never throw into the host app.
1315
+ */
966
1316
  debug?: boolean;
967
1317
  }
968
1318
  interface TrackingProviderProps {
1319
+ /**
1320
+ * Application subtree that should have access to the tracking client.
1321
+ */
969
1322
  children: ReactNode;
970
1323
  }
971
1324
  interface CreateTrackingResult<TRegistry extends TriggerRegistryConfig> {
1325
+ /**
1326
+ * Client component provider for the Next.js App Router integration.
1327
+ */
972
1328
  TrackingProvider: (props: TrackingProviderProps) => ReactNode;
1329
+ /**
1330
+ * Hook that returns the registry-typed tracking client.
1331
+ */
973
1332
  useTracking: () => TypedTrackingClient<TRegistry>;
974
1333
  }
975
1334
  /**
976
- * Next.js App Router version of the createTracking factory. Uses
1335
+ * Next.js App Router version of the `createTracking()` factory. Uses
977
1336
  * `usePathname` + `useSearchParams` from `next/navigation` for SPA route
978
1337
  * detection rather than patching `history.pushState`, because Next's
979
1338
  * router does not always go through the History API for transitions.