/** * Matomo A/B Testing integration for @socialgouv/matomo-next * * Provides typed support for creating and managing A/B tests via * Matomo's AbTesting plugin (https://plugins.matomo.org/AbTesting). * * @module ab-testing */ /** Unique experiment name as configured in Matomo */ export type ABTestName = string; /** Variant name (e.g. "original", "variant-a", "variant-b") */ export type ABTestVariant = string; /** A single variation in an A/B test */ export interface ABTestVariation { /** Display name / identifier of this variation */ name: ABTestVariant; } /** Full definition of a single A/B test experiment */ export interface ABTestDefinition { /** Matomo experiment name (must match Matomo dashboard) */ name: ABTestName; /** Percentage of visitors included in the experiment (0–100) */ percentage: number; /** Available variations (including control/"original") */ variations: ABTestVariation[]; /** ISO 8601 start date (optional scheduling) */ startDateTime?: string; /** ISO 8601 end date (optional scheduling) */ endDateTime?: string; /** * Custom participation trigger. * Return `true` to include the current visitor in the experiment. * Defaults to `() => true` (all visitors). */ trigger?: () => boolean; } /** Runtime state for a single experiment */ export interface MatomoABTestState { abTest: ABTestName; variant: ABTestVariant | null; isReady: boolean; } declare global { interface Window { /** * Runtime store for activated Matomo A/B tests. * Keyed by test name to support multiple concurrent experiments. */ __MATOMO_AB_TEST__?: Record; } } /** Parameters accepted by {@link initABTesting} */ export interface InitABTestingParams { /** Master switch – when `false` the function is a no-op */ enabled: boolean; /** Current page pathname (e.g. from Next.js `usePathname()`) */ pathname: string; /** URL patterns to exclude from experiments */ excludeUrlsPatterns?: RegExp[]; /** List of experiments to register */ tests: ABTestDefinition[]; } /** * Register one or more Matomo A/B tests. * * **Preferred:** pass `abTests` directly to `trackAppRouter` / `trackPagesRouter` * — this function will be called automatically. * * You can also call it manually for advanced use cases (e.g. conditional init). * * @example * ```ts * // Preferred — automatic init via settings * trackAppRouter({ * url: MATOMO_URL, * siteId: MATOMO_SITE_ID, * pathname, * searchParams, * abTests: [ * { * name: "homepage-hero", * percentage: 100, * variations: [{ name: "original" }, { name: "new-hero" }], * }, * ], * }); * * // Manual — for advanced use cases * initABTesting({ * enabled: true, * pathname: pathname ?? "", * tests: [...], * }); * ``` */ export declare function initABTesting({ enabled, pathname, excludeUrlsPatterns, tests, }: InitABTestingParams): void; /** * Read the current state of a specific A/B test. * * Useful outside of React (e.g. in server components or plain functions). * Inside React prefer `useABTestVariant()`. */ export declare function getABTestState(testName: ABTestName): MatomoABTestState | null; //# sourceMappingURL=ab-testing.d.ts.map