/** * External dependencies */ import type { ConversionAction as CA, Dict, ExperimentId, ExperimentType, PageViewThrottleSettings, SegmentationRule, SiteId, Url, } from '@nab/types'; // ======== // SETTINGS // ======== export type Settings = { readonly ajaxUrl?: Url; readonly alternativeUrls: | { readonly experimentId: ExperimentId; readonly value: ReadonlyArray< Url >; } | undefined; readonly alternativeChecksum: string; readonly api: ApiSettings; readonly cookieTesting: false | number; readonly debugGui: Url | false; readonly excludeBots: boolean; readonly experiments: ReadonlyArray< ExperimentSummary >; readonly forceECommerceSessionSync: boolean; readonly gdprCookie: GdprCookieSetting; readonly heatmaps: ReadonlyArray< HeatmapSummary >; readonly hideQueryArgs: boolean; readonly homeUrl: Url; readonly ignoreTrailingSlash: boolean; readonly isGA4Integrated: boolean; readonly ga4TrackingMethod: 'gtm' | 'gtag' | false; readonly isStagingSite: boolean; readonly isTestedPostRequest: boolean; readonly maxCombinations: number; readonly nabPosition: 'first' | 'last'; readonly optimizeXPath: boolean; readonly participationChance: number; readonly postId: number | false; readonly preloadQueryArgUrls: ReadonlyArray< PreloadQueryArgUrl >; readonly segmentMatching: 'all' | 'some'; readonly singleConvPerView: boolean; readonly site: SiteId; readonly throttle: PageViewThrottleSettings; readonly timezone: string; readonly useControlUrl: boolean; readonly useSendBeacon: boolean; readonly version: string; }; export type Session = Required< Omit< Settings, 'experiments' > > & { readonly alternative: number; readonly experiments: ReadonlyArray< Experiment >; readonly currentUrl: string; readonly untestedUrl: string; readonly hasQuota: Promise< boolean >; }; export type MissingSessionRationale = | 'awaiting-session' | 'missing-session' | 'awaiting-variant'; export type ParamValue = string | number | boolean; export type PreloadQueryArgUrl = | { readonly type: 'alt-urls'; readonly altUrls: ReadonlyArray< Url >; readonly experimentId: ExperimentId; } | { readonly type: 'scope'; readonly scope: ReadonlyArray< UrlOrPartialUrl >; readonly altCount: number; }; // =========== // EXPERIMENTS // =========== export type ExperimentSummary = | ActiveExperimentSummary | InactiveExperimentSummary; export type ActiveExperimentSummary = Omit< InactiveExperimentSummary, 'active' | 'alternatives' > & { readonly active: true; readonly alternatives: | ReadonlyArray< AlternativeSummary > | ReadonlyArray< ScriptAlternative >; readonly heatmapTracking: boolean; readonly pageViewTracking: 'disabled' | 'header' | 'footer' | 'script'; readonly inline?: { readonly load: 'header' | 'footer'; readonly mode: 'unwrap' | 'visibility' | 'script'; }; }; export type InactiveExperimentSummary = { readonly active: false; readonly id: ExperimentId; readonly name?: string; readonly type: ExperimentType[ 'name' ]; readonly alternatives: ReadonlyArray< unknown >; readonly alternativeCuts?: ReadonlyArray< number >; readonly goals: ReadonlyArray< GoalSummary >; readonly segments: ReadonlyArray< SegmentSummary >; readonly segmentEvaluation: 'site' | 'tested-page'; }; export type Experiment = ActiveExperiment | InactiveExperiment; export type ActiveExperiment = ActiveExperimentSummary & ExtraProps; export type InactiveExperiment = InactiveExperimentSummary & ExtraProps; type ExtraProps = { readonly alternative: number; }; export type HeatmapSummary = { readonly id: ExperimentId; readonly name?: string; readonly participation: ReadonlyArray< SegmentationRule >; }; // =========== // EXP DETAILS // =========== export type AlternativeIndex = number; export type AlternativeSummary = Dict; export type ScriptAlternative = { readonly name: string; readonly run: ( done: () => void, utils: { readonly appendStyle: ( css: string ) => void; readonly domReady: ( fn: () => unknown ) => void; readonly elementReady: ( selector: string, fn: ( element: HTMLElement, setCss: ( style: string ) => void ) => unknown ) => void; readonly showContent: () => void; } ) => void; }; export type GoalIndex = number; export type GoalSummary = { readonly id: GoalIndex; readonly name: string; readonly conversionActions: ReadonlyArray< ConversionAction >; }; export type SegmentIndex = number; export type SegmentSummary = { readonly id: SegmentIndex; readonly name?: string; readonly segmentationRules: Omit< ReadonlyArray< SegmentationRule >, 'id' >; }; // =========== // CONVERSIONS // =========== export type ActionListener = ( allActions: ReadonlyArray< ConvertibleAction >, convert: Convert ) => void; export type Convert = ( conversions: ConvertingGoal | ReadonlyArray< ConvertingGoal > ) => void; export type ConversionAction< A extends Dict = Dict > = Pick< CA< A >, 'type' | 'attributes' > & { readonly active: boolean; }; export type ConvertibleAction< A extends Dict = Dict > = ConversionAction< A > & { readonly experiment: ExperimentId; readonly alternative: AlternativeIndex; readonly goal: GoalIndex; }; export type ConvertingGoal = { readonly experiment: ExperimentId; readonly goal: GoalIndex; }; export type GdprCookieSetting = { readonly name: string; readonly value: string; }; // ============ // HELPER TYPES // ============ type UrlOrPartialUrl = string; type ApiSettings = { readonly mode: 'native' | 'rest' | 'domain-forwarding'; readonly url: Url; };