@aranova/tracking-react 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 +35 -46
- package/dist/index.d.mts +99 -101
- package/dist/index.d.ts +99 -101
- package/dist/index.js +223 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +217 -82
- package/dist/index.mjs.map +1 -1
- package/dist/{phone-utils-Dyk0F14_.d.mts → phone-utils-DlAQK-gU.d.mts} +127 -6
- package/dist/{phone-utils-Dyk0F14_.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/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,8 +223,10 @@ export const { TrackingProvider, useTracking } = createTracking({
|
|
|
223
223
|
|
|
224
224
|
```ts
|
|
225
225
|
import { createSalesClient, resolveConversionConfig, toMinor } from "@aranova/tracking-react";
|
|
226
|
+
import type { AranovaService, AranovaConversion } from "./aranova-services"; // generated by `gen`
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
// Bind the generated unions so `service` and `trackConversion` keys are type-checked.
|
|
229
|
+
const sales = createSalesClient<AranovaService, AranovaConversion>({
|
|
228
230
|
apiKey,
|
|
229
231
|
endpoint,
|
|
230
232
|
firing: resolveConversionConfig({ cdnUrl: ARANOVA_CONFIG_URL }),
|
|
@@ -235,74 +237,61 @@ await sales.recordSale({
|
|
|
235
237
|
amount_total_cents: toMinor(250, "CAD"),
|
|
236
238
|
service: "tires",
|
|
237
239
|
}); // records + fires
|
|
238
|
-
sales.trackConversion("phone_click"); // fires a manual event-goal only (no sale recorded)
|
|
239
240
|
```
|
|
240
241
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
## Consent UI
|
|
242
|
+
**Manual conversions (multiple forms):** register the trigger once, then call `trackConversion(key)` in each form's submit handler. Keys come from the dashboard Goals tab (event-goals with a `form_submit`/`phone_click`/`cta_click` trigger mapped to a WEBPAGE action) and are emitted as the `AranovaConversion` union by `gen` — so they autocomplete and reject typos:
|
|
244
243
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
```tsx
|
|
248
|
-
import { ConsentBanner } from "@aranova/tracking-react";
|
|
244
|
+
```ts
|
|
245
|
+
// createTracking({ …, triggers: { manual: { form_submit: {} } } }) // register once
|
|
249
246
|
|
|
250
|
-
//
|
|
251
|
-
|
|
247
|
+
// in the contact form's onSubmit:
|
|
248
|
+
sales.trackConversion("contact_form"); // ✅ typed by AranovaConversion
|
|
249
|
+
// in the demo form's onSubmit:
|
|
250
|
+
sales.trackConversion("demo_request");
|
|
251
|
+
sales.trackConversion("typo"); // ❌ compile error — not a known goal key
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
Each call fires **only** the WEBPAGE conversion for that goal (no `/sales` write); the SDK no-ops if the goal isn't mapped. 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).
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
<ConsentBanner
|
|
258
|
-
title="Cookies"
|
|
259
|
-
message="We use cookies to track ad performance."
|
|
260
|
-
acceptLabel="Sure"
|
|
261
|
-
declineLabel="No thanks"
|
|
262
|
-
policyHref="/privacy"
|
|
263
|
-
policyLabel="Privacy policy" // default: "Learn more"
|
|
264
|
-
onAccept={() => track("consent_accepted")}
|
|
265
|
-
onDecline={() => track("consent_declined")}
|
|
266
|
-
position="bottom" // or "top"
|
|
267
|
-
theme="light" // "light" | "dark" | "auto"
|
|
268
|
-
className="my-extra-classes"
|
|
269
|
-
style={{ background: "#fafafa" }} // wins over the theme defaults
|
|
270
|
-
/>
|
|
271
|
-
```
|
|
256
|
+
> **Before any manual goal exists,** `gen` emits an empty `ARANOVA_CONVERSIONS`, so `AranovaConversion` resolves to `never` — binding it (`createSalesClient<AranovaService, AranovaConversion>`) then makes **every** `trackConversion` call a compile error. Until you've mapped at least one manual goal and re-run `gen`, bind only the service generic (`createSalesClient<AranovaService>(…)`); the conversion key defaults back to `string`.
|
|
272
257
|
|
|
273
|
-
|
|
258
|
+
## Consent (v2 — opt-out model)
|
|
274
259
|
|
|
275
|
-
|
|
260
|
+
Tracking is **on by default**: gtag, the Meta Pixel, and on-site conversion firing all run from first paint unless the visitor has stored an explicit, unexpired decline. A decline is honored for **90 days** (then the visitor reverts to default-granted); an explicit grant never expires. There is no `pending` state and the packages ship **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).
|
|
261
|
+
|
|
262
|
+
### Footer control — `useCookiePreferences()`
|
|
276
263
|
|
|
277
264
|
```tsx
|
|
278
|
-
import {
|
|
265
|
+
import { useCookiePreferences } from "@aranova/tracking-react";
|
|
279
266
|
|
|
280
|
-
function
|
|
281
|
-
const {
|
|
267
|
+
function CookiePreferences() {
|
|
268
|
+
const { isDenied, isDefault, optOut, optIn } = useCookiePreferences();
|
|
282
269
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return (
|
|
288
|
-
<MyBespokeBanner>
|
|
289
|
-
<button onClick={decline}>No thanks</button>
|
|
290
|
-
<button onClick={accept}>Sure</button>
|
|
291
|
-
</MyBespokeBanner>
|
|
270
|
+
return isDenied ? (
|
|
271
|
+
<button onClick={optIn}>Enable ad measurement</button>
|
|
272
|
+
) : (
|
|
273
|
+
<button onClick={optOut}>Opt out of ad measurement</button>
|
|
292
274
|
);
|
|
293
275
|
}
|
|
294
276
|
```
|
|
295
277
|
|
|
296
|
-
The hook
|
|
278
|
+
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). `optOut` accepts a custom TTL via the hook's `{ declineTtlDays }` option.
|
|
279
|
+
|
|
280
|
+
For non-component contexts the same primitives are exported as plain functions: `optOut()`, `optIn()`, `resetConsent()`, `getConsentChoice()`, and `onConsentChange()`.
|
|
281
|
+
|
|
282
|
+
### Deprecated opt-in flow
|
|
283
|
+
|
|
284
|
+
`<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 — so leaving it mounted is harmless but pointless. `useConsent()` still works as a shim (`isPending` is always `false`; `accept`/`decline` map to `optIn`/`optOut`).
|
|
285
|
+
|
|
286
|
+
**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.
|
|
297
287
|
|
|
298
288
|
## Exports
|
|
299
289
|
|
|
300
290
|
- `createTracking()`
|
|
301
291
|
- `TrackingProvider` and scoped `useTracking`
|
|
302
292
|
- `GoogleAdsTracking`
|
|
303
|
-
- `
|
|
304
|
-
-
|
|
305
|
-
- Standalone consent helpers: `getConsentState()`, `setConsentState()`, `resetConsent()`
|
|
293
|
+
- Consent (v2): `useCookiePreferences()` + `UseCookiePreferencesResult`; standalone `optIn()`, `optOut()`, `resetConsent()`, `getConsentChoice()`, `onConsentChange()`, `getConsentState()`, `setConsentState()`
|
|
294
|
+
- Deprecated consent shims: `ConsentBanner` + `ConsentBannerProps`, `useConsent()` + `UseConsentResult`, `useConsentState()`
|
|
306
295
|
- Attribution hooks: `useTrackingParams()`, `useGclid()`
|
|
307
296
|
- `createSalesClient()` (isomorphic — public key writes; secret key reads/CRUD, `summary`, `customers.*`, `business.config`) + money/date helpers (`toMinor`/`fromMinor`/`formatMoney`/`formatDateInTz`). Also available React-free at **`@aranova/tracking-react/sales`** (with all sale/customer/config types) — the recommended import for server/serverless code.
|
|
308
297
|
- Phone: `parsePhone`/`toE164`/`formatPhone`/`formatPhoneAsTyped`/`phoneField`, `usePhoneField`, `PhoneField` (utils also at `/phone`)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, CSSProperties, InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export { D as DEFAULT_PHONE_COUNTRY, J as JsonValue,
|
|
5
|
-
import { C as ConversionConfig } from './sales-
|
|
6
|
-
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-
|
|
3
|
+
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, G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, C as ConsentState, g as ConsentChoiceState, h as ConsentSource, P as PhoneConfig, i as ParsedPhone, j as PhoneDisplayFormat } from './phone-utils-DlAQK-gU.mjs';
|
|
4
|
+
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';
|
|
5
|
+
import { C as ConversionConfig } from './sales-Bq7H-Vym.mjs';
|
|
6
|
+
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';
|
|
7
7
|
import * as src from 'src';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { CountryCode } from 'libphonenumber-js';
|
|
10
10
|
export { CountryCode } from 'libphonenumber-js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Legacy opt-in-era consent banner.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* didn't configure their content array to scan
|
|
22
|
-
* `node_modules/@aranova/tracking-react/dist/**`; this version sidesteps that
|
|
23
|
-
* class of bug entirely.
|
|
24
|
-
*
|
|
25
|
-
* For a fully bespoke banner, skip this component and use {@link useConsent}
|
|
26
|
-
* directly to drive your own UI.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* // Drop-in default
|
|
30
|
-
* <ConsentBanner />
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* // Customized
|
|
34
|
-
* <ConsentBanner
|
|
35
|
-
* message="We use cookies to learn which ads drive bookings."
|
|
36
|
-
* acceptLabel="Sounds good"
|
|
37
|
-
* declineLabel="No thanks"
|
|
38
|
-
* policyHref="/privacy"
|
|
39
|
-
* policyLabel="Privacy policy"
|
|
40
|
-
* theme="dark"
|
|
41
|
-
* onAccept={() => track('consent_accepted')}
|
|
42
|
-
* onDecline={() => track('consent_declined')}
|
|
43
|
-
* />
|
|
15
|
+
* @deprecated PERMANENTLY INERT since consent v2 (opt-out model): it renders
|
|
16
|
+
* only while consent is `pending`, and the effective state is never `pending`
|
|
17
|
+
* anymore, so this component always returns `null`. Tracking is on by default;
|
|
18
|
+
* replace the banner with a footer "cookie preferences" control built on
|
|
19
|
+
* {@link useCookiePreferences} (see the package README). Kept exported so
|
|
20
|
+
* existing integrations keep compiling; scheduled for removal.
|
|
44
21
|
*/
|
|
45
22
|
interface ConsentBannerProps {
|
|
46
23
|
/** Body text. Defaults to the standard cookies-for-ad-performance message. */
|
|
@@ -72,40 +49,26 @@ interface ConsentBannerProps {
|
|
|
72
49
|
/** Inline style overrides applied to the outer wrapper after the defaults. */
|
|
73
50
|
style?: CSSProperties;
|
|
74
51
|
}
|
|
75
|
-
declare function ConsentBanner({ message, title, acceptLabel, declineLabel, policyHref, policyLabel, onAccept, onDecline, position, theme, className, style, }?: ConsentBannerProps): ReactNode;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Google Consent Mode value sent to `gtag('consent', 'update', ...)`.
|
|
79
|
-
*/
|
|
80
|
-
type GtagConsentValue = "granted" | "denied";
|
|
81
52
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
53
|
+
* @deprecated Permanently inert since consent v2 — always renders `null`
|
|
54
|
+
* because the effective consent state is never `pending`. Use a footer
|
|
55
|
+
* control built on {@link useCookiePreferences} instead. See
|
|
56
|
+
* {@link ConsentBannerProps} for details.
|
|
86
57
|
*/
|
|
87
|
-
declare function
|
|
58
|
+
declare function ConsentBanner({ message, title, acceptLabel, declineLabel, policyHref, policyLabel, onAccept, onDecline, position, theme, className, style, }?: ConsentBannerProps): ReactNode;
|
|
59
|
+
|
|
88
60
|
/**
|
|
89
|
-
*
|
|
90
|
-
* loaded.
|
|
61
|
+
* Attribution query/cookie keys captured by the SDK.
|
|
91
62
|
*/
|
|
92
|
-
declare
|
|
63
|
+
declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
64
|
+
type TrackingParamKey = (typeof TRACKING_PARAM_KEYS)[number];
|
|
93
65
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* Power a "Cookie preferences" link in a footer so visitors can change their
|
|
97
|
-
* mind without losing access to your site:
|
|
98
|
-
*
|
|
99
|
-
* ```tsx
|
|
100
|
-
* const { reset } = useConsent();
|
|
101
|
-
* <button onClick={reset}>Cookie preferences</button>
|
|
102
|
-
* ```
|
|
66
|
+
* Capture tracking params from a URL, persist them to first-party cookies, and
|
|
67
|
+
* return the current cookie-backed attribution state.
|
|
103
68
|
*
|
|
104
|
-
*
|
|
105
|
-
* visitor hasn't chosen anything yet. The next `setConsentState()` call will
|
|
106
|
-
* sync gtag once they re-choose.
|
|
69
|
+
* Defaults to `window.location.href` in the browser.
|
|
107
70
|
*/
|
|
108
|
-
declare function
|
|
71
|
+
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
109
72
|
|
|
110
73
|
interface TrackingContextInput {
|
|
111
74
|
packageName?: string | null;
|
|
@@ -127,6 +90,12 @@ interface TrackingSessionInput {
|
|
|
127
90
|
firstPage?: string | null;
|
|
128
91
|
sessionId: string;
|
|
129
92
|
visitorId?: string | null;
|
|
93
|
+
/**
|
|
94
|
+
* Landing attribution override (ADR-016). When omitted, the session's
|
|
95
|
+
* persisted landing record is used (captured from the current URL if the
|
|
96
|
+
* session has none yet).
|
|
97
|
+
*/
|
|
98
|
+
landingParams?: Partial<Record<TrackingParamKey, string>>;
|
|
130
99
|
}
|
|
131
100
|
/**
|
|
132
101
|
* Build runtime context attached to tracking sessions and events.
|
|
@@ -1173,18 +1142,6 @@ interface TrackingClient {
|
|
|
1173
1142
|
destroy: () => void;
|
|
1174
1143
|
}
|
|
1175
1144
|
|
|
1176
|
-
/**
|
|
1177
|
-
* Attribution query/cookie keys captured by the SDK.
|
|
1178
|
-
*/
|
|
1179
|
-
declare const TRACKING_PARAM_KEYS: readonly ["gclid", "fbclid", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
1180
|
-
/**
|
|
1181
|
-
* Capture tracking params from a URL, persist them to first-party cookies, and
|
|
1182
|
-
* return the current cookie-backed attribution state.
|
|
1183
|
-
*
|
|
1184
|
-
* Defaults to `window.location.href` in the browser.
|
|
1185
|
-
*/
|
|
1186
|
-
declare function captureTrackingParamsFromLocation(url?: string, maxAgeSeconds?: number): TrackingParams;
|
|
1187
|
-
|
|
1188
1145
|
interface TypedTrackEventOptions {
|
|
1189
1146
|
/**
|
|
1190
1147
|
* Override the page URL associated with this event.
|
|
@@ -1248,9 +1205,9 @@ interface AdPlatformTrackingProps {
|
|
|
1248
1205
|
}
|
|
1249
1206
|
/**
|
|
1250
1207
|
* Client component that loads the configured ad-platform tags — the Google tag
|
|
1251
|
-
* (`gtag`) and/or the Meta Pixel (`fbq`) — each with
|
|
1252
|
-
*
|
|
1253
|
-
* skip it. Renders nothing.
|
|
1208
|
+
* (`gtag`) and/or the Meta Pixel (`fbq`) — each with the visitor's effective
|
|
1209
|
+
* consent applied as the default (opt-out model). One mount handles both
|
|
1210
|
+
* platforms; omit a platform's props to skip it. Renders nothing.
|
|
1254
1211
|
*
|
|
1255
1212
|
* On React you usually don't need this at all — `<TrackingProvider>` already
|
|
1256
1213
|
* accepts the same `gtagId/gtagIds` + `metaPixelId/metaPixelIds` props. Use this
|
|
@@ -1272,7 +1229,9 @@ type GoogleAdsTrackingProps = {
|
|
|
1272
1229
|
gtagIds: GtagEnvironmentMap;
|
|
1273
1230
|
};
|
|
1274
1231
|
/**
|
|
1275
|
-
* Client component that loads Google Ads gtag
|
|
1232
|
+
* Client component that loads Google Ads gtag with the visitor's effective
|
|
1233
|
+
* consent applied as the Consent Mode default (opt-out model — granted unless
|
|
1234
|
+
* an unexpired stored decline exists).
|
|
1276
1235
|
*
|
|
1277
1236
|
* Render once near the application root when the client site runs paid Google
|
|
1278
1237
|
* Ads. The component renders nothing.
|
|
@@ -1291,38 +1250,69 @@ declare function useGclid(): string | null;
|
|
|
1291
1250
|
* Values are loaded after mount, so the initial render returns all `null`s.
|
|
1292
1251
|
*/
|
|
1293
1252
|
declare function useTrackingParams(): TrackingParams;
|
|
1253
|
+
/** Options for {@link useCookiePreferences}. */
|
|
1254
|
+
interface UseCookiePreferencesOptions {
|
|
1255
|
+
/** Days an explicit decline is honored. Defaults to 90. */
|
|
1256
|
+
declineTtlDays?: number;
|
|
1257
|
+
}
|
|
1294
1258
|
/**
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
* Prefer {@link useConsent} for new code — it returns the same state plus
|
|
1299
|
-
* the `accept` / `decline` / `reset` actions a custom consent UI needs.
|
|
1300
|
-
* `useConsentState` is kept as a convenience for callers that only need to
|
|
1301
|
-
* read.
|
|
1259
|
+
* The headless cookie-preferences surface returned by
|
|
1260
|
+
* {@link useCookiePreferences}.
|
|
1302
1261
|
*/
|
|
1303
|
-
|
|
1262
|
+
interface UseCookiePreferencesResult {
|
|
1263
|
+
/** Effective consent — `granted` unless an unexpired explicit decline exists. */
|
|
1264
|
+
state: ConsentChoiceState;
|
|
1265
|
+
/** `default` = no valid explicit choice stored; `explicit` = visitor chose. */
|
|
1266
|
+
source: ConsentSource;
|
|
1267
|
+
/** True when the visitor has made no (valid, unexpired) explicit choice. */
|
|
1268
|
+
isDefault: boolean;
|
|
1269
|
+
isGranted: boolean;
|
|
1270
|
+
isDenied: boolean;
|
|
1271
|
+
/** ISO timestamp of the explicit choice; null for the default state. */
|
|
1272
|
+
updatedAt: string | null;
|
|
1273
|
+
/** ISO expiry of an unexpired decline; null otherwise. */
|
|
1274
|
+
expiresAt: string | null;
|
|
1275
|
+
/** Explicitly opt out of ad tracking (honored for 90 days by default). */
|
|
1276
|
+
optOut: () => void;
|
|
1277
|
+
/** Explicitly opt in (never expires). */
|
|
1278
|
+
optIn: () => void;
|
|
1279
|
+
/** Clear the explicit choice — back to default-granted. */
|
|
1280
|
+
reset: () => void;
|
|
1281
|
+
}
|
|
1304
1282
|
/**
|
|
1305
|
-
*
|
|
1283
|
+
* Headless cookie-preferences hook for the opt-out consent model (consent v2).
|
|
1306
1284
|
*
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1285
|
+
* Tracking is ON by default; this hook is how each client site wires its own
|
|
1286
|
+
* footer "Cookie preferences" control (button, dialog, toggle — the packages
|
|
1287
|
+
* ship no consent UI). State stays in sync with actions from other components
|
|
1288
|
+
* in the same tab (via `onConsentChange`) and other tabs (via `storage`
|
|
1289
|
+
* events).
|
|
1309
1290
|
*
|
|
1310
1291
|
* ```tsx
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1292
|
+
* function CookiePreferences() {
|
|
1293
|
+
* const { isDenied, optOut, optIn } = useCookiePreferences();
|
|
1294
|
+
* return isDenied ? (
|
|
1295
|
+
* <button onClick={optIn}>Enable ad measurement</button>
|
|
1296
|
+
* ) : (
|
|
1297
|
+
* <button onClick={optOut}>Opt out of ad measurement</button>
|
|
1298
|
+
* );
|
|
1315
1299
|
* }
|
|
1316
|
-
* return (
|
|
1317
|
-
* <MyBannerStyling>
|
|
1318
|
-
* <button onClick={decline}>No thanks</button>
|
|
1319
|
-
* <button onClick={accept}>Sure</button>
|
|
1320
|
-
* </MyBannerStyling>
|
|
1321
|
-
* );
|
|
1322
1300
|
* ```
|
|
1301
|
+
*/
|
|
1302
|
+
declare function useCookiePreferences(options?: UseCookiePreferencesOptions): UseCookiePreferencesResult;
|
|
1303
|
+
/**
|
|
1304
|
+
* Read the current visitor consent state.
|
|
1323
1305
|
*
|
|
1324
|
-
*
|
|
1325
|
-
*
|
|
1306
|
+
* @deprecated Since consent v2 (opt-out model) the state is never `pending`.
|
|
1307
|
+
* Use {@link useCookiePreferences} — it exposes the effective state plus
|
|
1308
|
+
* `source` so you can tell a default grant from an explicit one.
|
|
1309
|
+
*/
|
|
1310
|
+
declare function useConsentState(): ConsentState;
|
|
1311
|
+
/**
|
|
1312
|
+
* Result shape of the deprecated {@link useConsent} hook.
|
|
1313
|
+
*
|
|
1314
|
+
* @deprecated Use {@link UseCookiePreferencesResult} via
|
|
1315
|
+
* {@link useCookiePreferences}. `isPending` is always `false` since consent v2.
|
|
1326
1316
|
*/
|
|
1327
1317
|
interface UseConsentResult {
|
|
1328
1318
|
state: ConsentState;
|
|
@@ -1333,6 +1323,14 @@ interface UseConsentResult {
|
|
|
1333
1323
|
decline: () => void;
|
|
1334
1324
|
reset: () => void;
|
|
1335
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Legacy opt-in-era consent hook.
|
|
1328
|
+
*
|
|
1329
|
+
* @deprecated Since consent v2 tracking defaults ON (opt-out model): the state
|
|
1330
|
+
* is never `pending`, so banner UIs gated on `isPending` never render. Use
|
|
1331
|
+
* {@link useCookiePreferences} for footer "cookie preferences" controls.
|
|
1332
|
+
* `accept` / `decline` still work and map to `optIn` / `optOut`.
|
|
1333
|
+
*/
|
|
1336
1334
|
declare function useConsent(): UseConsentResult;
|
|
1337
1335
|
|
|
1338
1336
|
interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
|
|
@@ -1484,4 +1482,4 @@ interface PhoneFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "t
|
|
|
1484
1482
|
*/
|
|
1485
1483
|
declare const PhoneField: react.ForwardRefExoticComponent<PhoneFieldProps & react.RefAttributes<HTMLInputElement>>;
|
|
1486
1484
|
|
|
1487
|
-
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,
|
|
1485
|
+
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 };
|