type UrlScrubber = (rawUrl: string) => string; /** Wire DTO sent to the backend. Keys are FROZEN — the Go ingestor depends on this shape. */ interface Payload { n: string; d: string; u: string; r: string; w: number; p?: Record; $?: { a: string; c: string; }; } interface EventTransport { send(payload: Payload): void; } interface ConsentStore { isOptedOut(): boolean; optOut(): void; optIn(): void; } interface DoNotTrackProvider { isEnabled(): boolean; } interface EnvironmentProvider { hostname(): string; path(): string; url(): string; referrer(): string; width(): number; } interface NavigationProvider { /** Register a navigation callback. Returns a disposer function. */ onNavigate(cb: () => void): () => void; } interface ClickSource { /** Register a handler called with the resolved anchor element and original event. * Returns a disposer function. */ onAnchorClick(cb: (a: HTMLAnchorElement, e: Event) => void): () => void; /** Register a handler called with the clicked element and original event. * Returns a disposer function. */ onElementClick(cb: (target: Element, e: Event) => void): () => void; } interface TrackOptions { props?: Record; revenue?: { amount: string; currency: string; }; } interface AnalyticsConfig { domain: string; endpoint: string; respectDnt: boolean; excludeLocalhost: boolean; exclude: string[]; enabled: boolean; debug: boolean; sampleRate: number; scrubUrl: UrlScrubber; } declare class Analytics { private readonly config; private readonly transport; private readonly consent; private readonly envProvider; private readonly navProvider; private readonly clickSource; private readonly policy; constructor(config: AnalyticsConfig, transport: EventTransport, consent: ConsentStore, dnt: DoNotTrackProvider, envProvider: EnvironmentProvider, navProvider: NavigationProvider, clickSource: ClickSource); track(name: string, opts?: TrackOptions): void; pageview(): void; optOut(): void; optIn(): void; enableSpa(): () => void; enableOutbound(): () => void; enableFiles(extensions?: string[]): () => void; enable404(): () => void; enableTagged(): () => void; private _emit; } /** Configuration for {@link createTakt} — the core SDK without the autocapture toggles. */ interface Config { domain?: string; endpoint?: string; scriptOrigin?: string; respectDnt?: boolean; excludeLocalhost?: boolean; exclude?: string[]; enabled?: boolean; debug?: boolean; sampleRate?: number; trackQuery?: boolean; queryParams?: string[]; scrubUrl?: UrlScrubber; } /** * Create a standalone instance the caller owns — privacy defaults on, but no * autocapture and no module singleton (unlike {@link init}). */ declare function createTakt(config?: Config): Analytics; type BadgeVariant = 'a' | 'b' | 'd'; type BadgeGlyph = 'unplug' | 'dash' | 'off' | 'eyeoff'; type WidgetLang = 'fr' | 'en'; type EmbedTheme = 'light' | 'dark' | 'auto'; interface BadgeOptions { host?: string; variant?: BadgeVariant; glyph?: BadgeGlyph; lang?: WidgetLang; } interface EmbedOptions { host?: string; theme?: EmbedTheme; lang?: WidgetLang; } declare function normalizeHost(host?: string): string; /** URL of the badge SVG. `variant` defaults to `a`, `lang` to `fr`; `glyph` only affects the fallback. */ declare function badgeUrl(domain: string, opts?: BadgeOptions): string; /** URL of the embed iframe page. `theme` defaults to `light`, `lang` to `fr`. */ declare function embedUrl(domain: string, opts?: EmbedOptions): string; type StatsPeriod = '24h' | '7d' | '30d' | '90d' | '12mo' | 'custom'; type StatsDimension = 'page' | 'referrer' | 'source' | 'country' | 'region' | 'city' | 'browser' | 'os' | 'device' | 'utm_source' | 'utm_medium' | 'utm_campaign'; interface StatsMetrics { visitors: number; pageviews: number; avgDurationS: number; bounceRate: number; } interface StatsSummary extends StatsMetrics { previous?: StatsMetrics; } interface StatsPoint { at: string; visitors: number; pageviews: number; } interface StatsTimeseries { interval: string; points: StatsPoint[]; previous?: StatsPoint[]; } interface StatsBreakdownRow { label: string; visitors: number; pageviews: number; } interface StatsBreakdown { dimension: string; rows: StatsBreakdownRow[]; } interface StatsRealtime { visitors: number; } interface StatsParams { period?: StatsPeriod; from?: string; to?: string; tz?: string; country?: string; interval?: string; compare?: 'previous'; } interface StatsClientOptions { /** Takt host, e.g. `https://takt.example.com`. Defaults to the hosted Takt origin. */ host?: string; /** Default domain so per-call `domain` becomes optional. */ domain?: string; } /** Typed error for the public stats API, carrying the HTTP status. */ declare class PublicApiError extends Error { readonly status: number; constructor(status: number, message: string); } interface StatsClient { summary(domain?: string, params?: StatsParams): Promise; timeseries(domain?: string, params?: StatsParams): Promise; realtime(domain?: string): Promise; breakdown(dimension: StatsDimension, domain?: string, params?: StatsParams): Promise; } /** Create a stats client bound to a host (and optionally a default domain). */ declare function createStats(opts?: StatsClientOptions): StatsClient; type Revenue = { amount: string; currency: string; }; /** Options for {@link init} — `createTakt`'s {@link Config} plus the autocapture toggles. */ interface InitOptions { domain?: string; endpoint?: string; scriptOrigin?: string; respectDnt?: boolean; excludeLocalhost?: boolean; exclude?: string[]; enabled?: boolean; debug?: boolean; sampleRate?: number; trackQuery?: boolean; queryParams?: string[]; scrubUrl?: UrlScrubber; auto?: boolean; outbound?: boolean; files?: boolean; fileExtensions?: string[]; notFound?: boolean; tagged?: boolean; } /** * Bootstrap the default instance: create it, enable requested autocapture, and — * unless `auto` is `false` — start SPA tracking and fire an initial pageview. */ declare function init(opts?: InitOptions): Analytics; /** Track a custom event on the default instance. No-op until {@link init} has run. */ declare function track(name: string, opts?: TrackOptions): void; /** Send a pageview on the default instance. No-op until {@link init} has run. */ declare function pageview(): void; /** Opt the visitor out of tracking (persisted). No-op until {@link init} has run. */ declare function optOut(): void; /** Reverse a previous {@link optOut}. No-op until {@link init} has run. */ declare function optIn(): void; declare function _reset(): void; export { type BadgeGlyph, type BadgeOptions, type BadgeVariant, type Config, type EmbedOptions, type EmbedTheme, type InitOptions, type Payload, PublicApiError, type Revenue, type StatsBreakdown, type StatsBreakdownRow, type StatsClient, type StatsClientOptions, type StatsDimension, type StatsMetrics, type StatsParams, type StatsPeriod, type StatsPoint, type StatsRealtime, type StatsSummary, type StatsTimeseries, type TrackOptions, type WidgetLang, _reset, badgeUrl, createStats, createTakt, embedUrl, init, normalizeHost, optIn, optOut, pageview, track };