@aranova/tracking-next 0.14.1 → 0.15.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 +24 -50
- package/dist/index.d.mts +93 -97
- package/dist/index.d.ts +93 -97
- package/dist/index.js +239 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -93
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +0 -73
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +0 -73
- package/dist/middleware.mjs.map +1 -1
- package/dist/{phone-utils-CcU5mwzc.d.mts → phone-utils-DlAQK-gU.d.mts} +127 -6
- package/dist/{phone-utils-CcU5mwzc.d.ts → phone-utils-DlAQK-gU.d.ts} +127 -6
- package/dist/phone.d.mts +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/phone.js +0 -73
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs +0 -73
- package/dist/phone.mjs.map +1 -1
- package/dist/{sales-7w7-Ud60.d.mts → sales-Bq7H-Vym.d.mts} +6 -5
- package/dist/{sales-7w7-Ud60.d.ts → sales-Bq7H-Vym.d.ts} +6 -5
- package/dist/sales.d.mts +1 -1
- package/dist/sales.d.ts +1 -1
- package/dist/sales.js +33 -29
- package/dist/sales.js.map +1 -1
- package/dist/sales.mjs +33 -29
- package/dist/sales.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +0 -73
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +0 -73
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Wrap the root layout.
|
|
|
56
56
|
|
|
57
57
|
```tsx
|
|
58
58
|
// app/layout.tsx
|
|
59
|
-
import {
|
|
59
|
+
import { GoogleAdsTracking } from "@aranova/tracking-next";
|
|
60
60
|
import { TrackingProvider } from "@/lib/tracking";
|
|
61
61
|
|
|
62
62
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
@@ -68,16 +68,17 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
68
68
|
)}
|
|
69
69
|
</head>
|
|
70
70
|
<body>
|
|
71
|
-
<TrackingProvider>
|
|
72
|
-
{children}
|
|
73
|
-
<ConsentBanner />
|
|
74
|
-
</TrackingProvider>
|
|
71
|
+
<TrackingProvider>{children}</TrackingProvider>
|
|
75
72
|
</body>
|
|
76
73
|
</html>
|
|
77
74
|
);
|
|
78
75
|
}
|
|
79
76
|
```
|
|
80
77
|
|
|
78
|
+
Tracking is on by default (consent v2, opt-out model) — no banner. Add a footer
|
|
79
|
+
"cookie preferences" control built on `useCookiePreferences()` (see **Consent** below)
|
|
80
|
+
and disclose the tracking + opt-out in the site's privacy policy.
|
|
81
|
+
|
|
81
82
|
### Multiple gtag IDs
|
|
82
83
|
|
|
83
84
|
Pass `gtagIds` (instead of `gtagId`) to install several Google Ads tags at once — e.g. a real
|
|
@@ -266,65 +267,38 @@ sales.trackConversion("phone_click"); // fires a manual event-goal only (no sale
|
|
|
266
267
|
|
|
267
268
|
Firing is consent-gated, de-duped by `transaction_id`, and no-ops server-side. The config bucket needs an R2 CORS policy — see [conversion-config-schema.md](https://github.com/AranovaIO/aranova_internal/blob/master/docs/tracking-package/conversion-config-schema.md).
|
|
268
269
|
|
|
269
|
-
## Consent
|
|
270
|
-
|
|
271
|
-
The bundled `<ConsentBanner />` renders a non-blocking bottom-docked banner while consent is `pending`, persists the visitor's choice to `localStorage`, and propagates it to Google Consent Mode v2 when gtag is loaded. **Inline-styled** — no Tailwind or CSS imports required at the consumer.
|
|
272
|
-
|
|
273
|
-
```tsx
|
|
274
|
-
import { ConsentBanner } from "@aranova/tracking-next";
|
|
275
|
-
|
|
276
|
-
// Drop-in (already wired in the root layout example above)
|
|
277
|
-
<ConsentBanner />;
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
All props are optional:
|
|
270
|
+
## Consent (v2 — opt-out model)
|
|
281
271
|
|
|
282
|
-
|
|
283
|
-
<ConsentBanner
|
|
284
|
-
title="Cookies"
|
|
285
|
-
message="We use cookies to track ad performance."
|
|
286
|
-
acceptLabel="Sure"
|
|
287
|
-
declineLabel="No thanks"
|
|
288
|
-
policyHref="/privacy"
|
|
289
|
-
policyLabel="Privacy policy" // default: "Learn more"
|
|
290
|
-
onAccept={() => track("consent_accepted")}
|
|
291
|
-
onDecline={() => track("consent_declined")}
|
|
292
|
-
position="bottom" // or "top"
|
|
293
|
-
theme="light" // "light" | "dark" | "auto"
|
|
294
|
-
className="my-extra-classes"
|
|
295
|
-
style={{ background: "#fafafa" }} // wins over the theme defaults
|
|
296
|
-
/>
|
|
297
|
-
```
|
|
272
|
+
Tracking is **on by default**: the consent-default `<Script>` injected by `GoogleAdsTracking` / `AdPlatformTracking` resolves the visitor's effective consent synchronously from `localStorage` before gtag.js loads — granted unless an explicit, unexpired decline is stored. A decline is honored for **90 days**; a grant never expires. There is no `pending` state and the package ships **no consent UI** — each site provides its own footer "cookie preferences" control and discloses tracking in its privacy policy (that notice is what makes the opt-out model defensible).
|
|
298
273
|
|
|
299
|
-
###
|
|
300
|
-
|
|
301
|
-
For a bespoke banner, skip the component and drive your own UI with the headless hook:
|
|
274
|
+
### Footer control — `useCookiePreferences()`
|
|
302
275
|
|
|
303
276
|
```tsx
|
|
304
277
|
"use client";
|
|
305
|
-
import {
|
|
278
|
+
import { useCookiePreferences } from "@aranova/tracking-next";
|
|
306
279
|
|
|
307
|
-
function
|
|
308
|
-
const {
|
|
280
|
+
function CookiePreferences() {
|
|
281
|
+
const { isDenied, optOut, optIn } = useCookiePreferences();
|
|
309
282
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return (
|
|
315
|
-
<MyBespokeBanner>
|
|
316
|
-
<button onClick={decline}>No thanks</button>
|
|
317
|
-
<button onClick={accept}>Sure</button>
|
|
318
|
-
</MyBespokeBanner>
|
|
283
|
+
return isDenied ? (
|
|
284
|
+
<button onClick={optIn}>Enable ad measurement</button>
|
|
285
|
+
) : (
|
|
286
|
+
<button onClick={optOut}>Opt out of ad measurement</button>
|
|
319
287
|
);
|
|
320
288
|
}
|
|
321
289
|
```
|
|
322
290
|
|
|
323
|
-
The hook
|
|
291
|
+
The hook returns the effective `state` (`"granted" | "denied"`), its `source` (`"default"` = no explicit choice, `"explicit"`), boolean helpers (`isDefault` / `isGranted` / `isDenied`), the choice's `updatedAt` / `expiresAt`, and the `optOut()` / `optIn()` / `reset()` actions. It stays in sync with other components in the same tab (via `onConsentChange`) and other tabs (via `storage` events). Plain-function equivalents (`optOut`, `optIn`, `resetConsent`, `getConsentChoice`, `onConsentChange`) are exported for non-component contexts.
|
|
292
|
+
|
|
293
|
+
### Deprecated opt-in flow
|
|
294
|
+
|
|
295
|
+
`<ConsentBanner />`, `useConsent()`, and `useConsentState()` are `@deprecated` and scheduled for removal. The banner is **permanently inert** (it rendered only while consent was `pending`, which no longer occurs); `useConsent()` still works as a shim (`isPending` is always `false`; `accept`/`decline` map to `optIn`/`optOut`). The old `consent-restore` scripts are gone — the consent-default script already applies the effective state.
|
|
296
|
+
|
|
297
|
+
**Migrating from the banner flow:** delete `<ConsentBanner />`, add a footer control built on `useCookiePreferences`, and mention the tracking + opt-out in your privacy policy. Existing visitors' stored grants stay granted; stored declines stay denied for 90 days from their first visit after the upgrade.
|
|
324
298
|
|
|
325
299
|
## Exports
|
|
326
300
|
|
|
327
|
-
- Root package: `createTracking`, `TrackingProvider`, `useTracking`, `GoogleAdsTracking`, `
|
|
301
|
+
- Root package: `createTracking`, `TrackingProvider`, `useTracking`, `GoogleAdsTracking`, consent v2 (`useCookiePreferences`, `optIn`, `optOut`, `resetConsent`, `getConsentChoice`, `onConsentChange`) + deprecated shims (`ConsentBanner`, `useConsent`, `useConsentState`), attribution hooks, event types; `createSalesClient()` (isomorphic — public key writes; secret key reads/CRUD, `summary`, `customers.*`, `business.config`) + `toMinor`/`fromMinor`/`formatMoney`/`formatDateInTz`; phone (`parsePhone`/`toE164`/`formatPhone`/`phoneField`, `usePhoneField`, `PhoneField`)
|
|
328
302
|
- `@aranova/tracking-next/sales`: **React-free** server-safe SDK — `createSalesClient`, money/date helpers, and all sale/customer/config types. Use this in Server Components, route handlers, and Node servers; the root entry re-exports the same symbols for back-compat.
|
|
329
303
|
- `@aranova/tracking-next/middleware`: `createTrackingMiddleware()`
|
|
330
304
|
- `@aranova/tracking-next/server`: `getTrackingParamsServer()`
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { D as DEFAULT_PHONE_COUNTRY, J as JsonValue,
|
|
3
|
-
import { C as ConversionConfig } from './sales-
|
|
4
|
-
export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as CurrencyRevenue, f as CustomerCurrencyDelta, g as CustomerCurrencyTotal, h as CustomerGetOptions, i as CustomerGetResult, j as CustomerKpis, k as CustomerKpisDeltas, l as CustomerKpisPrevious, m as CustomerListPage, n as CustomerListQuery, o as CustomerProfile, p as CustomerSegment, q as CustomerSegmentCount, r as CustomerSortField, s as CustomerSummary, t as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, u as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, v as Sale, w as SaleCursorPage, x as SaleFilters, y as SaleInput, z as SaleItem, E as SaleItemInput, F as SaleKeysetSortField, H as SaleListPage, I as SaleListQuery, J as SaleListQueryV2, K as SaleService, L as SaleServiceInput, M as SaleSortField, O as SaleSortOrder, Q as SaleSummary, R as SaleSummaryPrevious, T as SaleSummaryQuery, U as SaleSummaryQueryV2, V as SaleSummaryV2, W as SaleUpdateInput, X as SalesBusinessClient, Y as SalesCategoryBreakdown, Z as SalesClient, _ as SalesClientConfig, $ as SalesCustomersClient, a0 as SalesServiceBreakdown, a1 as SalesTransportConfig, a2 as SalesTrendPoint, a3 as SummaryCurrencyDelta, a4 as SummaryDeltas, a5 as SummaryWindow, a6 as SupportedCurrency, a7 as TRACKING_RANGES, a8 as TrackingOverviewRange, a9 as createSalesClient, aa as fetchServices, ab as formatDateInTz, ac as formatMoney, ad as fromMinor, ae as resolveConversionConfig, af as saleCreateSchema, ag as saleItemSchema, ah as saleServiceSchema, ai as saleUpdateSchema, aj as salesRequest, ak as toMinor } from './sales-
|
|
1
|
+
import { T as TrackingParams, a as TrackingInstallSurface, b as TrackingEnvironment, c as TrackingClientContext, d as TrackingEventCreatePayload, e as TrackingSessionUpsertPayload, F as FormSubmitConfig, f as FormSubmitMetadata, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-DlAQK-gU.mjs';
|
|
2
|
+
export { k as ConsentChoice, D as DEFAULT_DECLINE_TTL_DAYS, l as DEFAULT_PHONE_COUNTRY, J as JsonValue, S as SetConsentOptions, m as TrackedField, n as TrackingInitConfig, o as formSubmitConfigSchema, p as formSubmitMetadataSchema, q as formatPhone, r as formatPhoneAsTyped, s as getConsentChoice, t as getConsentState, u as jsonValueSchema, v as onConsentChange, w as optIn, x as optOut, y as parsePhone, z as phoneField, A as resetConsent, B as setConsentState, E as toE164 } from './phone-utils-DlAQK-gU.mjs';
|
|
3
|
+
import { C as ConversionConfig } from './sales-Bq7H-Vym.mjs';
|
|
4
|
+
export { A as AranovaApiError, B as BusinessConfig, a as BusinessConfigFeatures, b as BusinessConfigService, c as CompareTo, d as ConversionConfigStore, e as CurrencyRevenue, f as CustomerCurrencyDelta, g as CustomerCurrencyTotal, h as CustomerGetOptions, i as CustomerGetResult, j as CustomerKpis, k as CustomerKpisDeltas, l as CustomerKpisPrevious, m as CustomerListPage, n as CustomerListQuery, o as CustomerProfile, p as CustomerSegment, q as CustomerSegmentCount, r as CustomerSortField, s as CustomerSummary, t as CustomerSummaryQuery, D as DistinctCustomersByCurrency, G as Granularity, N as NAMED_RANGES, u as NamedRange, P as PublicServiceItem, S as SUPPORTED_CURRENCIES, v as Sale, w as SaleCursorPage, x as SaleFilters, y as SaleInput, z as SaleItem, E as SaleItemInput, F as SaleKeysetSortField, H as SaleListPage, I as SaleListQuery, J as SaleListQueryV2, K as SaleService, L as SaleServiceInput, M as SaleSortField, O as SaleSortOrder, Q as SaleSummary, R as SaleSummaryPrevious, T as SaleSummaryQuery, U as SaleSummaryQueryV2, V as SaleSummaryV2, W as SaleUpdateInput, X as SalesBusinessClient, Y as SalesCategoryBreakdown, Z as SalesClient, _ as SalesClientConfig, $ as SalesCustomersClient, a0 as SalesServiceBreakdown, a1 as SalesTransportConfig, a2 as SalesTrendPoint, a3 as SummaryCurrencyDelta, a4 as SummaryDeltas, a5 as SummaryWindow, a6 as SupportedCurrency, a7 as TRACKING_RANGES, a8 as TrackingOverviewRange, a9 as createSalesClient, aa as fetchServices, ab as formatDateInTz, ac as formatMoney, ad as fromMinor, ae as resolveConversionConfig, af as saleCreateSchema, ag as saleItemSchema, ah as saleServiceSchema, ai as saleUpdateSchema, aj as salesRequest, ak as toMinor } from './sales-Bq7H-Vym.mjs';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import * as src from 'src';
|
|
7
7
|
import * as react from 'react';
|
|
@@ -11,37 +11,17 @@ import { CountryCode } from 'libphonenumber-js';
|
|
|
11
11
|
export { CountryCode } from 'libphonenumber-js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
type GtagConsentValue = "granted" | "denied";
|
|
17
|
-
/**
|
|
18
|
-
* Read the persisted visitor consent state from localStorage.
|
|
19
|
-
*
|
|
20
|
-
* Returns `pending` when called during SSR or before the visitor has made a
|
|
21
|
-
* choice.
|
|
22
|
-
*/
|
|
23
|
-
declare function getConsentState(): ConsentState;
|
|
24
|
-
/**
|
|
25
|
-
* Persist a visitor consent choice and update Google Consent Mode when gtag is
|
|
26
|
-
* loaded.
|
|
14
|
+
* Attribution query/cookie keys captured by the SDK.
|
|
27
15
|
*/
|
|
28
|
-
declare
|
|
16
|
+
declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
17
|
+
type TrackingParamKey = (typeof TRACKING_PARAM_KEYS)[number];
|
|
29
18
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* Power a "Cookie preferences" link in a footer so visitors can change their
|
|
33
|
-
* mind without losing access to your site:
|
|
34
|
-
*
|
|
35
|
-
* ```tsx
|
|
36
|
-
* const { reset } = useConsent();
|
|
37
|
-
* <button onClick={reset}>Cookie preferences</button>
|
|
38
|
-
* ```
|
|
19
|
+
* Capture tracking params from a URL, persist them to first-party cookies, and
|
|
20
|
+
* return the current cookie-backed attribution state.
|
|
39
21
|
*
|
|
40
|
-
*
|
|
41
|
-
* visitor hasn't chosen anything yet. The next `setConsentState()` call will
|
|
42
|
-
* sync gtag once they re-choose.
|
|
22
|
+
* Defaults to `window.location.href` in the browser.
|
|
43
23
|
*/
|
|
44
|
-
declare function
|
|
24
|
+
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
45
25
|
|
|
46
26
|
interface TrackingContextInput {
|
|
47
27
|
packageName?: string | null;
|
|
@@ -63,6 +43,12 @@ interface TrackingSessionInput {
|
|
|
63
43
|
firstPage?: string | null;
|
|
64
44
|
sessionId: string;
|
|
65
45
|
visitorId?: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Landing attribution override (ADR-016). When omitted, the session's
|
|
48
|
+
* persisted landing record is used (captured from the current URL if the
|
|
49
|
+
* session has none yet).
|
|
50
|
+
*/
|
|
51
|
+
landingParams?: Partial<Record<TrackingParamKey, string>>;
|
|
66
52
|
}
|
|
67
53
|
/**
|
|
68
54
|
* Build runtime context attached to tracking sessions and events.
|
|
@@ -1109,18 +1095,6 @@ interface TrackingClient {
|
|
|
1109
1095
|
destroy: () => void;
|
|
1110
1096
|
}
|
|
1111
1097
|
|
|
1112
|
-
/**
|
|
1113
|
-
* Attribution query/cookie keys captured by the SDK.
|
|
1114
|
-
*/
|
|
1115
|
-
declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
1116
|
-
/**
|
|
1117
|
-
* Capture tracking params from a URL, persist them to first-party cookies, and
|
|
1118
|
-
* return the current cookie-backed attribution state.
|
|
1119
|
-
*
|
|
1120
|
-
* Defaults to `window.location.href` in the browser.
|
|
1121
|
-
*/
|
|
1122
|
-
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
1123
|
-
|
|
1124
1098
|
interface TypedTrackEventOptions {
|
|
1125
1099
|
/**
|
|
1126
1100
|
* Override the page URL associated with this event.
|
|
@@ -1166,37 +1140,14 @@ interface TypedTrackingClient<TRegistry extends TriggerRegistryConfig> {
|
|
|
1166
1140
|
}
|
|
1167
1141
|
|
|
1168
1142
|
/**
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
* Renders only while consent is `pending`; collapses to `null` once the
|
|
1172
|
-
* visitor has chosen.
|
|
1173
|
-
*
|
|
1174
|
-
* **Styling is intentionally self-contained** — inline styles, zero CSS
|
|
1175
|
-
* dependencies, no Tailwind required at the consumer. The Tailwind-based
|
|
1176
|
-
* banner shipped before 0.9.1 rendered as transparent in any consumer that
|
|
1177
|
-
* didn't configure their content array to scan
|
|
1178
|
-
* `node_modules/@aranova/tracking-next/dist/**`; this version sidesteps that
|
|
1179
|
-
* class of bug entirely.
|
|
1180
|
-
*
|
|
1181
|
-
* For a fully bespoke banner, skip this component and use {@link useConsent}
|
|
1182
|
-
* directly to drive your own UI.
|
|
1183
|
-
*
|
|
1184
|
-
* @example
|
|
1185
|
-
* // Drop-in default
|
|
1186
|
-
* <ConsentBanner />
|
|
1143
|
+
* Legacy opt-in-era consent banner.
|
|
1187
1144
|
*
|
|
1188
|
-
* @
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
* policyHref="/privacy"
|
|
1195
|
-
* policyLabel="Privacy policy"
|
|
1196
|
-
* theme="dark"
|
|
1197
|
-
* onAccept={() => track('consent_accepted')}
|
|
1198
|
-
* onDecline={() => track('consent_declined')}
|
|
1199
|
-
* />
|
|
1145
|
+
* @deprecated PERMANENTLY INERT since consent v2 (opt-out model): it renders
|
|
1146
|
+
* only while consent is `pending`, and the effective state is never `pending`
|
|
1147
|
+
* anymore, so this component always returns `null`. Tracking is on by default;
|
|
1148
|
+
* replace the banner with a footer "cookie preferences" control built on
|
|
1149
|
+
* {@link useCookiePreferences} (see the package README). Kept exported so
|
|
1150
|
+
* existing integrations keep compiling; scheduled for removal.
|
|
1200
1151
|
*/
|
|
1201
1152
|
interface ConsentBannerProps {
|
|
1202
1153
|
/** Body text. Defaults to the standard cookies-for-ad-performance message. */
|
|
@@ -1228,6 +1179,12 @@ interface ConsentBannerProps {
|
|
|
1228
1179
|
/** Inline style overrides applied to the outer wrapper after the defaults. */
|
|
1229
1180
|
style?: CSSProperties;
|
|
1230
1181
|
}
|
|
1182
|
+
/**
|
|
1183
|
+
* @deprecated Permanently inert since consent v2 — always renders `null`
|
|
1184
|
+
* because the effective consent state is never `pending`. Use a footer
|
|
1185
|
+
* control built on {@link useCookiePreferences} instead. See
|
|
1186
|
+
* {@link ConsentBannerProps} for details.
|
|
1187
|
+
*/
|
|
1231
1188
|
declare function ConsentBanner({ message, title, acceptLabel, declineLabel, policyHref, policyLabel, onAccept, onDecline, position, theme, className, style, }?: ConsentBannerProps): ReactNode;
|
|
1232
1189
|
|
|
1233
1190
|
/**
|
|
@@ -1242,38 +1199,69 @@ declare function useGclid(): string | null;
|
|
|
1242
1199
|
* Values are loaded after mount, so the initial render returns all `null`s.
|
|
1243
1200
|
*/
|
|
1244
1201
|
declare function useTrackingParams(): TrackingParams;
|
|
1202
|
+
/** Options for {@link useCookiePreferences}. */
|
|
1203
|
+
interface UseCookiePreferencesOptions {
|
|
1204
|
+
/** Days an explicit decline is honored. Defaults to 90. */
|
|
1205
|
+
declineTtlDays?: number;
|
|
1206
|
+
}
|
|
1245
1207
|
/**
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
* Prefer {@link useConsent} for new code — it returns the same state plus
|
|
1250
|
-
* the `accept` / `decline` / `reset` actions a custom consent UI needs.
|
|
1251
|
-
* `useConsentState` is kept as a convenience for callers that only need to
|
|
1252
|
-
* read.
|
|
1208
|
+
* The headless cookie-preferences surface returned by
|
|
1209
|
+
* {@link useCookiePreferences}.
|
|
1253
1210
|
*/
|
|
1254
|
-
|
|
1211
|
+
interface UseCookiePreferencesResult {
|
|
1212
|
+
/** Effective consent — `granted` unless an unexpired explicit decline exists. */
|
|
1213
|
+
state: ConsentChoiceState;
|
|
1214
|
+
/** `default` = no valid explicit choice stored; `explicit` = visitor chose. */
|
|
1215
|
+
source: ConsentSource;
|
|
1216
|
+
/** True when the visitor has made no (valid, unexpired) explicit choice. */
|
|
1217
|
+
isDefault: boolean;
|
|
1218
|
+
isGranted: boolean;
|
|
1219
|
+
isDenied: boolean;
|
|
1220
|
+
/** ISO timestamp of the explicit choice; null for the default state. */
|
|
1221
|
+
updatedAt: string | null;
|
|
1222
|
+
/** ISO expiry of an unexpired decline; null otherwise. */
|
|
1223
|
+
expiresAt: string | null;
|
|
1224
|
+
/** Explicitly opt out of ad tracking (honored for 90 days by default). */
|
|
1225
|
+
optOut: () => void;
|
|
1226
|
+
/** Explicitly opt in (never expires). */
|
|
1227
|
+
optIn: () => void;
|
|
1228
|
+
/** Clear the explicit choice — back to default-granted. */
|
|
1229
|
+
reset: () => void;
|
|
1230
|
+
}
|
|
1255
1231
|
/**
|
|
1256
|
-
*
|
|
1232
|
+
* Headless cookie-preferences hook for the opt-out consent model (consent v2).
|
|
1257
1233
|
*
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1234
|
+
* Tracking is ON by default; this hook is how each client site wires its own
|
|
1235
|
+
* footer "Cookie preferences" control (button, dialog, toggle — the packages
|
|
1236
|
+
* ship no consent UI). State stays in sync with actions from other components
|
|
1237
|
+
* in the same tab (via `onConsentChange`) and other tabs (via `storage`
|
|
1238
|
+
* events).
|
|
1260
1239
|
*
|
|
1261
1240
|
* ```tsx
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1241
|
+
* function CookiePreferences() {
|
|
1242
|
+
* const { isDenied, optOut, optIn } = useCookiePreferences();
|
|
1243
|
+
* return isDenied ? (
|
|
1244
|
+
* <button onClick={optIn}>Enable ad measurement</button>
|
|
1245
|
+
* ) : (
|
|
1246
|
+
* <button onClick={optOut}>Opt out of ad measurement</button>
|
|
1247
|
+
* );
|
|
1266
1248
|
* }
|
|
1267
|
-
* return (
|
|
1268
|
-
* <MyBannerStyling>
|
|
1269
|
-
* <button onClick={decline}>No thanks</button>
|
|
1270
|
-
* <button onClick={accept}>Sure</button>
|
|
1271
|
-
* </MyBannerStyling>
|
|
1272
|
-
* );
|
|
1273
1249
|
* ```
|
|
1250
|
+
*/
|
|
1251
|
+
declare function useCookiePreferences(options?: UseCookiePreferencesOptions): UseCookiePreferencesResult;
|
|
1252
|
+
/**
|
|
1253
|
+
* Read the current visitor consent state.
|
|
1274
1254
|
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1255
|
+
* @deprecated Since consent v2 (opt-out model) the state is never `pending`.
|
|
1256
|
+
* Use {@link useCookiePreferences} — it exposes the effective state plus
|
|
1257
|
+
* `source` so you can tell a default grant from an explicit one.
|
|
1258
|
+
*/
|
|
1259
|
+
declare function useConsentState(): ConsentState;
|
|
1260
|
+
/**
|
|
1261
|
+
* Result shape of the deprecated {@link useConsent} hook.
|
|
1262
|
+
*
|
|
1263
|
+
* @deprecated Use {@link UseCookiePreferencesResult} via
|
|
1264
|
+
* {@link useCookiePreferences}. `isPending` is always `false` since consent v2.
|
|
1277
1265
|
*/
|
|
1278
1266
|
interface UseConsentResult {
|
|
1279
1267
|
state: ConsentState;
|
|
@@ -1284,6 +1272,14 @@ interface UseConsentResult {
|
|
|
1284
1272
|
decline: () => void;
|
|
1285
1273
|
reset: () => void;
|
|
1286
1274
|
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Legacy opt-in-era consent hook.
|
|
1277
|
+
*
|
|
1278
|
+
* @deprecated Since consent v2 tracking defaults ON (opt-out model): the state
|
|
1279
|
+
* is never `pending`, so banner UIs gated on `isPending` never render. Use
|
|
1280
|
+
* {@link useCookiePreferences} for footer "cookie preferences" controls.
|
|
1281
|
+
* `accept` / `decline` still work and map to `optIn` / `optOut`.
|
|
1282
|
+
*/
|
|
1287
1283
|
declare function useConsent(): UseConsentResult;
|
|
1288
1284
|
|
|
1289
1285
|
/**
|
|
@@ -1470,4 +1466,4 @@ interface PhoneFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "t
|
|
|
1470
1466
|
*/
|
|
1471
1467
|
declare const PhoneField: react.ForwardRefExoticComponent<PhoneFieldProps & react.RefAttributes<HTMLInputElement>>;
|
|
1472
1468
|
|
|
1473
|
-
export { ALL_AUTOMATIC_EVENT_NAMES, ALL_MANUAL_EVENT_NAMES, AdPlatformTracking, type AdPlatformTrackingProps, type AutomaticEventName, ConsentBanner, type ConsentBannerProps, ConsentState, ConversionConfig, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, EVENT_REGISTRY, type EventConfig, type EventKind, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, FormSubmitConfig, FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, GtagEnvironmentMap, type ManualEventName, MetaPixelEnvironmentMap, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, ParsedPhone, type PhoneClickConfig, type PhoneClickMetadata, PhoneConfig, PhoneDisplayFormat, PhoneField, type PhoneFieldApi, type PhoneFieldProps, type PhoneInputProps, type RegisteredAutomaticEvents, type RegisteredManualEvents, SPECIFIC_PAGE_NAMES, type ScrollDepthConfig, type ScrollDepthMetadata, type SdkHeartbeatConfig, type SdkHeartbeatMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackableEvent, type TrackingClient, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, type UseConsentResult, type UsePhoneFieldOptions, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, ctaClickConfigSchema, ctaClickMetadataSchema, formStartConfigSchema, formStartMetadataSchema,
|
|
1469
|
+
export { ALL_AUTOMATIC_EVENT_NAMES, ALL_MANUAL_EVENT_NAMES, AdPlatformTracking, type AdPlatformTrackingProps, type AutomaticEventName, ConsentBanner, type ConsentBannerProps, ConsentChoiceState, ConsentSource, ConsentState, ConversionConfig, type CreateTrackingOptions, type CreateTrackingResult, type CtaClickConfig, type CtaClickMetadata, EVENT_REGISTRY, type EventConfig, type EventKind, type EventMetadata, type EventName, type FormStartConfig, type FormStartMetadata, FormSubmitConfig, FormSubmitMetadata, GoogleAdsTracking, type GoogleAdsTrackingProps, GtagEnvironmentMap, type ManualEventName, MetaPixelEnvironmentMap, type MultiPageSessionConfig, type MultiPageSessionMetadata, type PageViewConfig, type PageViewMetadata, ParsedPhone, type PhoneClickConfig, type PhoneClickMetadata, PhoneConfig, PhoneDisplayFormat, PhoneField, type PhoneFieldApi, type PhoneFieldProps, type PhoneInputProps, type RegisteredAutomaticEvents, type RegisteredManualEvents, SPECIFIC_PAGE_NAMES, type ScrollDepthConfig, type ScrollDepthMetadata, type SdkHeartbeatConfig, type SdkHeartbeatMetadata, type SpecificPageName, type SpecificPageVisitConfig, type SpecificPageVisitMetadata, TRACKING_PARAM_KEYS, type TimeOnSiteConfig, type TimeOnSiteMetadata, type TrackableEvent, type TrackingClient, TrackingClientContext, TrackingEventCreatePayload, TrackingInstallSurface, TrackingParams, type TrackingProviderProps, TrackingSessionUpsertPayload, type TriggerRegistryConfig, type TypedTrackEventOptions, type TypedTrackingClient, type UseConsentResult, type UseCookiePreferencesOptions, type UseCookiePreferencesResult, type UsePhoneFieldOptions, captureTrackingParamsFromLocation, createTracking, createTrackingClientContext, createTrackingEventCreatePayload, createTrackingSessionUpsertPayload, ctaClickConfigSchema, ctaClickMetadataSchema, formStartConfigSchema, formStartMetadataSchema, getEventDefinition, multiPageSessionConfigSchema, multiPageSessionMetadataSchema, pageViewConfigSchema, pageViewMetadataSchema, phoneClickConfigSchema, phoneClickMetadataSchema, scrollDepthConfigSchema, scrollDepthMetadataSchema, sdkHeartbeatConfigSchema, sdkHeartbeatMetadataSchema, sdkHeartbeatTriggersSchema, specificPageNameSchema, specificPageVisitConfigSchema, specificPageVisitMetadataSchema, timeOnSiteConfigSchema, timeOnSiteMetadataSchema, useConsent, useConsentState, useCookiePreferences, useGclid, usePhoneConfig, usePhoneField, useTrackingParams };
|