43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
import type { AnalyticsConfig } from './types.js';
|
|
declare global {
|
|
interface Window {
|
|
dataLayer?: unknown[];
|
|
}
|
|
}
|
|
export type AnalyticsProps = {
|
|
/**
|
|
* Core Web Vitals mode: hold back every tag's NETWORK load until the first
|
|
* user interaction (scroll, pointer, touch, key) or `deferTimeoutMs` after the
|
|
* window `load` event — whichever comes first. Keeps ~100+ KiB of third-party
|
|
* JS out of the FCP/LCP window.
|
|
*
|
|
* Consent is unaffected: the Consent Mode default is still pushed immediately
|
|
* (a synchronous dataLayer push, no network), and non-Google pixels still
|
|
* require their consent category. Defer changes WHEN a tag loads, never WHETHER.
|
|
*
|
|
* Trade-off: visitors who leave before interacting and before the timeout are
|
|
* not counted (slightly fewer sessions in GA). Default false.
|
|
*/
|
|
defer?: boolean;
|
|
/** Fallback delay after window `load`, in ms. Default 3500. */
|
|
deferTimeoutMs?: number;
|
|
} & AnalyticsConfig;
|
|
/**
|
|
* Loads every configured analytics / marketing tag, each respecting consent:
|
|
*
|
|
* - **Google (GA4 / GTM)** — Consent Mode: the visitor's stored choice is set as
|
|
* the default BEFORE the tag loads (always immediately, even with `defer`),
|
|
* and useConsent pushes an update the moment they decide. GTM wins if both
|
|
* IDs are set.
|
|
* - **Non-Google (Meta Pixel, Clarity, LinkedIn, TikTok)** — no Consent Mode, so
|
|
* each loads ONLY after its category is granted (marketing for
|
|
* Pixel/LinkedIn/TikTok, analytics for Clarity). Reacts live to the banner.
|
|
* - **`defer`** (opt-in) — additionally waits for first interaction / idle
|
|
* after load, for better LCP/INP. See AnalyticsProps.defer.
|
|
*
|
|
* All IDs are public and come from SiteIntegrations (getAnalyticsConfig), passed
|
|
* in as props. Renders nothing. Mount once, high in the tree, INSIDE
|
|
* <ConsentProvider> (required — it reads live consent state).
|
|
*/
|
|
export declare function Analytics(props: AnalyticsProps): null;
|