@mrrocket/sdk 0.11.0 → 0.13.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Ctx, type CockpitContext, type CockpitUser, useCtx } from \"./context\";\nimport { Survey, forgetStoredDismissals } from \"./survey\";\nimport { RageDetector, clickInfo, seenDepth } from \"./capture\";\nimport type { ReplayHandle } from \"./replay\";\nimport { type ErrorCapture, startErrorCapture } from \"./errors\";\nimport {\n type AttributionMode,\n DEFAULT_REFERRAL_DAYS,\n captureReferral,\n carriesReferral,\n forgetStoredReferral,\n getReferral,\n resetReferral,\n storeReferral,\n} from \"./referral\";\nimport {\n type CockpitConfig,\n type CockpitEvent,\n type ConsentChoice,\n type ConsentMode,\n EMBED_PARAM,\n EXPOSURE_PARAM,\n ID_COOKIE,\n PREVIEW_PARAM,\n SDK_VERSION,\n SESSION_COOKIE,\n type VariantId,\n envKey,\n experimentsOfText,\n exposureFrom,\n flagFor,\n parsePreview,\n redirectFor,\n resolveHost,\n resolveVariant,\n textChanges,\n} from \"./core\";\nimport type { PushResult, WebPushOptions } from \"./push-web\";\nimport { bodies } from \"./batch\";\nimport { YEAR_S, deleteCookie, enterPage, page, privacySignal, touchSession, visitorId, writeCookie } from \"./web-state\";\nimport { type CancelFlowOptions, type CancelFlowResult, type FlowsController, createFlows } from \"./flows\";\nimport { startPicker } from \"./pick\";\nimport type { FlowsTheme } from \"./flows-ui\";\nimport { forgetFlowsStorage, webFlowsEnv } from \"./flows-web\";\n\n/** Tells the developer once, in the browser console, why the SDK is not reaching MRRocket (a wrong host or key is the usual cause). */\nconst warned = new Set<string>();\nconst warnOnce = (message: string) => {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[MRRocket] ${message}`);\n};\n\nexport interface CockpitProviderProps {\n /** The product's public key from Cockpit › Settings › SDK. Safe in the browser. Default: `NEXT_PUBLIC_MRROCKET_KEY`. */\n apiKey?: string;\n /** Where MRRocket runs, like `https://app.example.com`. Default: `NEXT_PUBLIC_MRROCKET_HOST`, else the page's own origin. */\n host?: string;\n preview?: Record<string, VariantId>;\n embedded?: boolean;\n /** Config fetched on the server, to render the right variant on the first paint. */\n config?: CockpitConfig;\n /** Your own id for this visitor, for example a signed-in user id. Keeps variants stable without cookies. */\n distinctId?: string;\n /**\n * \"cookieless\" (default) stores nothing in the browser, \"cookies\" keeps a visitor cookie for a year, \"off\" sends\n * nothing. The SDK does not remember the choice: set it on every page load, from the prop or setConsent().\n */\n consent?: ConsentMode;\n /** Send nothing when the browser asks not to be tracked (Do Not Track or Global Privacy Control). */\n respectDnt?: boolean;\n /**\n * The visitor's consent to session recordings, separate from analytics (default false). Recording also needs the\n * product to record (Cockpit › Sessions) and analytics not \"off\". Without it nothing is recorded or buffered.\n * Change it later with `setConsent({ replay })`.\n */\n replay?: boolean;\n /**\n * Clicks and scroll depth for Heatmaps (default true): where a click landed, a short selector and a link's or\n * button's label, never typed text. Sent under the normal analytics consent as `$click`, `$rageclick` and `$scroll`.\n */\n heatmaps?: boolean;\n /** Ask visitors the surveys you run in Cockpit. Set false to switch them off. */\n surveys?: boolean;\n /**\n * Error tracking for Build › Errors (default true): uncaught errors and unhandled promise rejections, with the page\n * and the last pages and clicks, under the normal analytics consent. Report errors you catch with\n * `useCockpit().captureError(error)`.\n */\n errors?: boolean;\n /** Your release (a version or a commit), so MRRocket can tell which release an error came with. */\n release?: string;\n /**\n * Affiliate referrals (`?ref=` links and MRRocket's tracked links). \"consent\" (default): stored in the first-party\n * `mrr_ref` cookie only while consent is \"cookies\", in memory otherwise. \"always\": stored whatever the consent (only\n * where your legal basis allows it). \"off\": referrals are ignored.\n */\n attribution?: AttributionMode;\n /** The query parameter of direct partner links, default `ref` (`https://your.site/?ref=maya`). */\n referralParam?: string;\n /**\n * Onboarding flows start on their own when the visitor does their trigger (default true). False: only\n * `useCockpit().startOnboarding()` starts one. In-app messages and `openCancelFlow` work either way.\n */\n onboarding?: boolean;\n /** The look of the cancel flow, onboarding and message dialogs: `{ theme: \"dark\", accent: \"#0f766e\", className }`. */\n appearance?: FlowsTheme;\n children: ReactNode;\n}\n\n/**\n * Put it once around your app, in `app/layout.tsx`. It loads your experiments, keeps each visitor in one variant,\n * records page views and sends your events to Cockpit in small batches.\n *\n * `preview` forces variants for this render, for example from the `ck_preview` search param on the server,\n * so a Cockpit preview never flickers. Without it the provider reads the param itself after the first render.\n */\nexport const CockpitProvider = ({\n apiKey: apiKeyProp,\n host: hostProp,\n preview: forced,\n embedded: embeddedProp,\n config: bootstrapConfig,\n distinctId: bootstrapId,\n consent: consentProp = \"cookieless\",\n respectDnt = false,\n replay: replayProp = false,\n heatmaps = true,\n surveys = true,\n errors = true,\n release,\n attribution = \"consent\",\n referralParam = \"ref\",\n onboarding = true,\n appearance,\n children,\n}: CockpitProviderProps) => {\n const pathname = usePathname();\n const apiKey = apiKeyProp ?? envKey() ?? \"\";\n const host = resolveHost(hostProp);\n const [config, setConfig] = useState<CockpitConfig | null>(bootstrapConfig ?? null);\n const [consent, setConsentState] = useState<ConsentMode>(consentProp);\n const [replayConsent, setReplayConsent] = useState(replayProp);\n const [mounted, setMounted] = useState(false);\n const [dnt, setDnt] = useState(false);\n // The visitor id and the consent mode it was made for; null until the browser has been read.\n const [visitor, setVisitor] = useState<{ mode: ConsentMode; id: string } | null>(null);\n const [identified, setIdentified] = useState<string | undefined>();\n const [urlPreview, setUrlPreview] = useState<Record<string, VariantId>>({});\n const [urlEmbedded, setUrlEmbedded] = useState(false);\n const [user, setUser] = useState<CockpitUser | undefined>();\n const [ready, setReady] = useState(!!bootstrapConfig);\n const queue = useRef<CockpitEvent[]>([]);\n // Calls from before the visitor was known (a child's effect runs before ours); replayed once it is.\n const early = useRef<(() => void)[]>([]);\n const exposed = useRef(new Set<string>());\n const lastPage = useRef<string | null>(null);\n\n const bootstrap = bootstrapId && bootstrapId !== \"anonymous\" ? bootstrapId : undefined;\n const preview = useMemo(() => ({ ...urlPreview, ...forced }), [urlPreview, forced]);\n const embedded = embeddedProp ?? urlEmbedded;\n const effectiveConsent: ConsentMode = respectDnt && dnt ? \"off\" : consent;\n const distinctId = identified ?? bootstrap ?? visitor?.id ?? \"anonymous\";\n const tracking = !embedded && effectiveConsent !== \"off\" && visitor?.mode === effectiveConsent;\n // Without cookies, events carry an id only after identify(); the server counts everyone else by its daily hash.\n const sendId = effectiveConsent === \"cookies\" ? distinctId : identified;\n\n // Preview flags and the browser's privacy signal, once, in the browser.\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n setUrlPreview(parsePreview(params.get(PREVIEW_PARAM)));\n setUrlEmbedded(params.get(EMBED_PARAM) === \"1\");\n setDnt(privacySignal());\n setMounted(true);\n // Opened by MRRocket's onboarding editor to pick an element for a tour step (./pick.ts); only then, only in a frame.\n return params.get(EMBED_PARAM) === \"1\" ? (startPicker() ?? undefined) : undefined;\n }, []);\n\n const setConsent = useCallback((choice: ConsentChoice) => {\n const { analytics: mode, replay } = typeof choice === \"string\" ? { analytics: choice, replay: undefined } : choice;\n if (mode === \"off\") queue.current.length = 0;\n if (mode) setConsentState(mode);\n if (typeof replay === \"boolean\") setReplayConsent(replay);\n }, []);\n\n // Follow the `consent` and `replay` props when they change; setConsent() calls in between stay until they do.\n const lastProp = useRef(consentProp);\n useEffect(() => {\n if (lastProp.current === consentProp) return;\n lastProp.current = consentProp;\n setConsent(consentProp);\n }, [consentProp, setConsent]);\n const lastReplayProp = useRef(replayProp);\n useEffect(() => {\n if (lastReplayProp.current === replayProp) return;\n lastReplayProp.current = replayProp;\n setConsent({ replay: replayProp });\n }, [replayProp, setConsent]);\n\n // Storage follows consent. Leaving \"cookies\" deletes what the SDK stored; this page keeps its id in memory.\n const storedFor = useRef<ConsentMode | null>(null);\n useEffect(() => {\n if (!mounted) return;\n const before = storedFor.current;\n storedFor.current = effectiveConsent;\n if (before === \"cookies\" && effectiveConsent !== \"cookies\") {\n deleteCookie(ID_COOKIE);\n deleteCookie(SESSION_COOKIE);\n forgetStoredDismissals();\n forgetFlowsStorage();\n }\n if (effectiveConsent === \"off\") {\n queue.current.length = 0;\n page.session = undefined;\n }\n setVisitor({ mode: effectiveConsent, id: visitorId(effectiveConsent, !bootstrap) });\n }, [mounted, effectiveConsent, bootstrap]);\n\n // Experiments for this key. Without a key or when MRRocket is unreachable the page keeps control and carries on.\n useEffect(() => {\n if (!apiKey) warnOnce(\"No public key. Pass apiKey or set NEXT_PUBLIC_MRROCKET_KEY; nothing is tracked until then.\");\n if (bootstrapConfig || !apiKey) {\n setReady(true);\n return;\n }\n let live = true;\n fetch(`${host}/api/sdk/config?key=${encodeURIComponent(apiKey)}`)\n .then((r) => {\n if (!r.ok) warnOnce(`Config request to ${host || \"this origin\"} answered ${r.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);\n return r.ok ? r.json() : null;\n })\n .then((c: CockpitConfig | null) => {\n if (!live) return;\n if (c && Array.isArray(c.experiments)) setConfig(c);\n setReady(true);\n })\n .catch(() => {\n warnOnce(`Could not reach ${host || \"this origin\"}. Check NEXT_PUBLIC_MRROCKET_HOST. The page keeps working with control variants.`);\n if (live) setReady(true);\n });\n return () => {\n live = false;\n };\n }, [apiKey, host, bootstrapConfig]);\n\n const flush = useCallback(\n (beacon = false) => {\n if (!queue.current.length) return;\n if (!apiKey) {\n queue.current.length = 0;\n return;\n }\n const url = `${host}/api/sdk/events`;\n for (const body of bodies(apiKey, queue.current.splice(0), { v: SDK_VERSION, errors })) {\n const sent = beacon && typeof navigator !== \"undefined\" && \"sendBeacon\" in navigator && navigator.sendBeacon(url, body);\n if (!sent)\n fetch(url, { method: \"POST\", headers: { \"content-type\": \"application/json\" }, body, keepalive: true })\n .then((r) => {\n if (!r.ok) warnOnce(`Events were rejected with ${r.status}. Check the public key (Settings › SDK) and NEXT_PUBLIC_MRROCKET_HOST.`);\n })\n .catch(() => warnOnce(`Could not reach ${host || \"this origin\"} to send events. Check NEXT_PUBLIC_MRROCKET_HOST.`));\n }\n },\n [apiKey, host, errors],\n );\n\n useEffect(() => {\n const timer = window.setInterval(() => flush(), 2000);\n const leave = () => flush(true);\n window.addEventListener(\"pagehide\", leave);\n return () => {\n window.clearInterval(timer);\n window.removeEventListener(\"pagehide\", leave);\n flush(true);\n };\n }, [flush]);\n\n // The latest values for callbacks that must not change identity, so effects that use them run once.\n const live = useRef({ resolved: false, tracking, distinctId, sendId, persist: false, identified: false });\n live.current = { resolved: visitor !== null, tracking, distinctId, sendId, persist: visitor?.mode === \"cookies\", identified: !!identified };\n\n const record = useCallback((event: string, props: Record<string, unknown> | undefined, ts = Date.now(), url?: string) => {\n const now = live.current;\n if (!now.resolved) {\n early.current.push(() => record(event, props, ts, url));\n return;\n }\n // Previews in Cockpit never count, and nothing is sent without consent.\n if (!now.tracking) return;\n const referral = carriesReferral(event) ? getReferral() : null;\n queue.current.push({\n event,\n props: referral ? { ...props, $referral: { code: referral.code, clickId: referral.clickId } } : props,\n distinctId: now.sendId,\n sessionId: touchSession(now.persist),\n ts,\n url: url ?? window.location.href,\n referrer: page.referrer,\n ...page.utm,\n screen: { w: window.screen.width, h: window.screen.height },\n });\n }, []);\n\n // The running recorder, if this visit records (see the recording effect below).\n const replayer = useRef<ReplayHandle | null>(null);\n // Error tracking, while `errors` is on (see the effect below).\n const errorer = useRef<ErrorCapture | null>(null);\n\n // The cancel flow, onboarding and in-app messages (flows.ts): one controller for the provider's lifetime.\n const flowsRef = useRef<FlowsController | null>(null);\n const flows = (flowsRef.current ??= createFlows(\n webFlowsEnv({\n host,\n apiKey,\n track: (event, props) => record(event, props),\n personId: () => (live.current.tracking && live.current.identified ? live.current.distinctId : undefined),\n canStore: () => live.current.persist,\n auto: onboarding,\n }),\n ));\n\n const track = useCallback(\n (event: string, props?: Record<string, unknown>) => {\n record(event, props);\n if (live.current.tracking) replayer.current?.event(event);\n flows.onEvent(event);\n },\n [record, flows],\n );\n\n const identify = useCallback(\n (id: string, props?: Record<string, unknown>) => {\n const now = live.current;\n if (!now.resolved) {\n early.current.push(() => identify(id, props));\n return;\n }\n const previous = now.sendId;\n // From here on events carry this id in every mode; only \"cookies\" keeps it for the next visit.\n live.current = { ...now, distinctId: id, sendId: id, identified: true };\n record(\"$identify\", { ...props, id, ...(previous && previous !== id ? { previousId: previous } : {}) });\n replayer.current?.identify(id);\n if (now.persist) writeCookie(ID_COOKIE, id, YEAR_S);\n setIdentified(id);\n setUser({ id, ...(props as Omit<CockpitUser, \"id\">) });\n },\n [record],\n );\n\n // Replay what came in before the visitor was known: sent when tracking is on, dropped when it is not.\n useEffect(() => {\n if (!visitor) return;\n for (const run of early.current.splice(0)) run();\n }, [visitor]);\n\n // Affiliate referrals: read once the consent is known and the program's cookie days have loaded.\n const referralDays = config?.referral?.cookieDays ?? DEFAULT_REFERRAL_DAYS;\n const storeReferrals = attribution === \"always\" ? effectiveConsent !== \"off\" : attribution === \"consent\" && effectiveConsent === \"cookies\";\n const captured = useRef<string | null>(null);\n const storedReferral = useRef(false);\n useEffect(() => {\n if (!visitor || !ready || embedded) return;\n if (attribution === \"off\" || effectiveConsent === \"off\") {\n resetReferral();\n if (attribution === \"off\" || storedReferral.current) forgetStoredReferral();\n return;\n }\n const href = window.location.href;\n if (captured.current === href) return;\n captured.current = href;\n void captureReferral({\n search: window.location.search,\n param: referralParam,\n store: storeReferrals,\n days: referralDays,\n beacon: apiKey\n ? ({ code, clickId }) =>\n fetch(`${host}/api/sdk/affiliate/click`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ key: apiKey, code, clickId, url: href, referrer: document.referrer || undefined }),\n keepalive: true,\n })\n .then((r) => (r.ok ? (r.json() as Promise<{ clickId?: string | null }>) : null))\n .then((b) => b?.clickId ?? null)\n : undefined,\n });\n }, [visitor, ready, embedded, attribution, effectiveConsent, pathname, referralParam, storeReferrals, referralDays, apiKey, host]);\n\n // Consent given later keeps this page load's referral; consent withdrawn deletes what was stored.\n useEffect(() => {\n if (!mounted) return;\n const r = getReferral();\n if (storeReferrals && r) storeReferral(r, referralDays);\n else if (!storeReferrals && storedReferral.current) forgetStoredReferral();\n storedReferral.current = storeReferrals;\n }, [mounted, storeReferrals, referralDays]);\n\n // `tracking` is a dependency so that variants seen before consent are recorded once tracking starts.\n const expose = useCallback(\n (key: string, variant: VariantId) => {\n if (!tracking) return;\n const mark = `${pathname}|${key}`;\n if (exposed.current.has(mark)) return;\n exposed.current.add(mark);\n track(\"$exposure\", { experiment: key, variant });\n },\n [pathname, track, tracking],\n );\n\n // Redirects, once per page: a page redirect or a redirect test's variant sends the visitor on as soon as the config is\n // known (`experimentRedirect` in proxy.ts does it before the page renders, without a flash). A redirect test's\n // control stays and is recorded here; the page a variant lands on records it from `ck_x`, then drops the parameter.\n const decided = useRef<{ path: string; r: ReturnType<typeof redirectFor> } | null>(null);\n const arrived = useRef<string | null | undefined>(undefined);\n useEffect(() => {\n if (!ready || !visitor) return;\n if (decided.current?.path !== pathname) {\n const r = redirectFor(config, window.location.href, distinctId, preview);\n decided.current = { path: pathname, r };\n if (r?.to) {\n flush(true);\n window.location.replace(r.to);\n return;\n }\n }\n if (arrived.current === undefined) {\n const params = new URLSearchParams(window.location.search);\n arrived.current = params.get(EXPOSURE_PARAM);\n if (arrived.current !== null) {\n params.delete(EXPOSURE_PARAM);\n const q = params.toString();\n window.history.replaceState(window.history.state, \"\", `${window.location.pathname}${q ? `?${q}` : \"\"}${window.location.hash}`);\n }\n }\n if (!tracking) return;\n const r = decided.current.r;\n if (r?.experiment && !r.to) expose(r.experiment, r.variant!);\n const x = exposureFrom(config, arrived.current);\n if (x) expose(x.experiment, x.variant);\n arrived.current = null;\n }, [ready, visitor, pathname, config, distinctId, preview, tracking, expose, flush]);\n\n // The referrer and campaign of each page; before the page view below, so it already carries them.\n useEffect(() => {\n enterPage();\n replayer.current?.page(pathname);\n errorer.current?.crumb(\"navigation\", pathname);\n }, [pathname]);\n\n // Errors of the page for Build › Errors; sent only while tracking (consent, not a preview), like events.\n useEffect(() => {\n if (!errors || !apiKey || embedded) return;\n const capture = startErrorCapture({\n host,\n apiKey,\n release,\n context: () => ({ send: live.current.tracking, distinctId: live.current.sendId, sessionId: page.session?.id }),\n warn: warnOnce,\n });\n errorer.current = capture;\n capture.crumb(\"navigation\", window.location.pathname);\n return () => {\n capture.stop();\n if (errorer.current === capture) errorer.current = null;\n };\n }, [errors, apiKey, host, release, embedded]);\n\n const captureError = useCallback((error: unknown) => errorer.current?.capture(error, \"manual\"), []);\n\n // One page view per route change while tracking, so a later setConsent() records the current page right away\n // (a ref keeps React's dev double-run from counting twice).\n useEffect(() => {\n if (!tracking || lastPage.current === pathname) return;\n lastPage.current = pathname;\n // Exposures are remembered per path (\"/pricing|test\"), so nothing needs clearing here.\n track(\"$pageview\", { path: pathname });\n }, [pathname, tracking, track]);\n\n // Clicks on anything marked `data-ck-goal=\"signup_started\"` count as that goal. Every click also feeds Heatmaps\n // (`$click`, `$rageclick` on the third quick click on one spot) and, when this visit records, the recording.\n const rage = useRef(new RageDetector());\n useEffect(() => {\n const onClick = (e: MouseEvent) => {\n const el = (e.target as HTMLElement | null)?.closest<HTMLElement>(\"[data-ck-goal]\");\n if (el?.dataset.ckGoal) track(el.dataset.ckGoal, { text: el.textContent?.trim().slice(0, 80) });\n if (!live.current.tracking) return;\n const c = clickInfo(e);\n if (!c) return;\n const raged = rage.current.push(c.x, c.y, Date.now());\n if (c.label || c.selector) errorer.current?.crumb(\"click\", c.label || c.selector);\n replayer.current?.click(c, raged);\n if (!heatmaps) return;\n const props = { x: c.x, y: c.y, vw: c.vw, vh: c.vh, docH: c.docH, selector: c.selector, label: c.label, dead: !c.interactive };\n record(\"$click\", props);\n if (raged) record(\"$rageclick\", props);\n };\n document.addEventListener(\"click\", onClick);\n return () => document.removeEventListener(\"click\", onClick);\n }, [track, record, heatmaps]);\n\n // Scroll depth for Heatmaps: the deepest point seen on each page, sent when the page changes or hides.\n const depth = useRef<{ url: string; max: number; docH: number } | null>(null);\n useEffect(() => {\n if (!heatmaps || !tracking || embedded) return;\n const send = () => {\n const d = depth.current;\n if (d && d.max > 0) record(\"$scroll\", { depth: d.max, docH: d.docH, vw: window.innerWidth, vh: window.innerHeight }, Date.now(), d.url);\n depth.current = null;\n };\n const measure = () => {\n const doc = document.documentElement;\n const docH = Math.max(doc.scrollHeight, document.body?.scrollHeight ?? 0);\n const max = seenDepth();\n const href = window.location.href;\n if (depth.current?.url !== href) depth.current = { url: href, max, docH };\n else if (max > depth.current.max) depth.current = { url: href, max, docH };\n };\n measure();\n let frame = 0;\n const onScroll = () => {\n if (frame) return;\n frame = window.requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n };\n const onHide = () => {\n send();\n flush(true);\n };\n window.addEventListener(\"scroll\", onScroll, { passive: true });\n window.addEventListener(\"pagehide\", onHide);\n return () => {\n window.removeEventListener(\"scroll\", onScroll);\n window.removeEventListener(\"pagehide\", onHide);\n window.cancelAnimationFrame(frame);\n send();\n };\n }, [heatmaps, tracking, embedded, pathname, record, flush]);\n\n // Session recording: only with the visitor's replay consent, while tracking, and when the product records. The\n // recorder and rrweb are loaded here, lazily; withdrawing consent stops it and drops what was not sent.\n const replayConfig = config?.replay;\n const recording = tracking && replayConsent && !!replayConfig && !!apiKey;\n useEffect(() => {\n if (!recording || !replayConfig) return;\n let active = true;\n let handle: ReplayHandle | null = null;\n // `typeof window` is a build-time constant in Next.js: on the server this folds to null and the import (with\n // rrweb) never enters the server bundle.\n void (typeof window === \"undefined\" ? Promise.resolve(null) : import(\"./replay\"))\n .then((m) =>\n m?.startReplay({\n host,\n apiKey,\n sessionId: touchSession(live.current.persist),\n distinctId: live.current.sendId,\n identified: live.current.identified,\n sampleRate: replayConfig.sampleRate,\n warn: warnOnce,\n }),\n )\n .then((h) => {\n if (!active) h?.stop(true);\n else replayer.current = handle = h ?? null;\n })\n .catch(() => warnOnce(\"Session recording could not start (the recorder did not load).\"));\n return () => {\n active = false;\n handle?.stop(true);\n if (replayer.current === handle) replayer.current = null;\n };\n }, [recording, replayConfig, host, apiKey]);\n\n // The flows follow the config and the person: their messages and onboarding progress load once both are known.\n useEffect(() => {\n if (!ready || !visitor || embedded) return;\n flows.setConfig(config);\n void flows.refresh();\n }, [flows, ready, visitor, embedded, config, identified, tracking, effectiveConsent]);\n\n // The dialogs load the first time something is about to show (a dynamic import), and stay mounted after.\n const look = useRef(appearance);\n look.current = appearance;\n useEffect(() => {\n if (embedded) return;\n let unmount: (() => void) | null = null;\n let loading = false;\n let gone = false;\n const show = () => {\n if (unmount || loading || !flows.view()) return;\n loading = true;\n void (typeof window === \"undefined\" ? Promise.resolve(null) : import(\"./flows-ui\"))\n .then((m) => {\n if (!m || gone) return;\n unmount = m.mountFlows(flows, look.current);\n })\n .catch(() => warnOnce(\"The cancel flow and onboarding dialogs did not load.\"))\n .finally(() => {\n loading = false;\n });\n };\n const off = flows.subscribe(show);\n show();\n return () => {\n gone = true;\n off();\n unmount?.();\n };\n }, [flows, embedded]);\n\n const openCancelFlow = useCallback((options?: CancelFlowOptions) => flows.openCancelFlow(options), [flows]);\n const startOnboarding = useCallback((id?: string) => flows.startOnboarding(id), [flows]);\n\n // Web push (push-web.ts, a dynamic import on the first call). The permission is asked here, synchronously inside the\n // click that called it: Safari refuses one asked after an await.\n const subscribeToPush = useCallback(\n (options?: WebPushOptions): Promise<PushResult> => {\n if (typeof window === \"undefined\") return Promise.resolve({ status: \"unsupported\" });\n const now = live.current;\n const distinctId = now.tracking && now.identified ? now.distinctId : undefined;\n if (!distinctId) return Promise.resolve({ status: \"not-signed-in\" });\n const N = window.Notification;\n const permission = Promise.resolve(N && N.permission === \"default\" && options?.ask !== false ? N.requestPermission() : N?.permission);\n return import(\"./push-web\").then((m) => m.subscribeWebPush({ host, apiKey, distinctId, permission }, options));\n },\n [host, apiKey],\n );\n const unsubscribeFromPush = useCallback(\n () =>\n typeof window === \"undefined\"\n ? Promise.resolve(false)\n : import(\"./push-web\").then((m) => m.unsubscribeWebPush({ host, apiKey, distinctId: live.current.identified ? live.current.distinctId : undefined })),\n [host, apiKey],\n );\n\n const texts = useMemo(() => textChanges(config, distinctId, preview), [config, distinctId, preview]);\n\n const value = useMemo<CockpitContext>(\n () => ({\n apiKey,\n host,\n user,\n ready,\n distinctId,\n config,\n preview,\n embedded,\n consent,\n effectiveConsent,\n replayConsent,\n setConsent,\n texts,\n track,\n identify,\n expose,\n captureError,\n openCancelFlow,\n startOnboarding,\n subscribeToPush,\n unsubscribeFromPush,\n }),\n [\n apiKey,\n host,\n user,\n ready,\n distinctId,\n config,\n preview,\n embedded,\n consent,\n effectiveConsent,\n replayConsent,\n setConsent,\n texts,\n track,\n identify,\n expose,\n captureError,\n openCancelFlow,\n startOnboarding,\n subscribeToPush,\n unsubscribeFromPush,\n ],\n );\n return (\n <Ctx.Provider value={value}>\n {children}\n {surveys ? <Survey /> : null}\n </Ctx.Provider>\n );\n};\n\n/**\n * `track`, `identify`, `captureError`, the consent mode, the replay consent and their setter, the visitor id and whether\n * the experiments and flags have loaded. `setConsent(\"cookies\")` sets the mode, `setConsent({ replay: true })` the\n * replay consent.\n */\nexport const useCockpit = () => {\n const { track, identify, captureError, distinctId, ready, embedded, consent, replayConsent, setConsent, openCancelFlow, startOnboarding } = useCtx();\n return { track, identify, captureError, distinctId, ready, embedded, consent, replay: replayConsent, setConsent, openCancelFlow, startOnboarding };\n};\n\n/**\n * Push notifications from your Lifecycle journeys for the signed-in person (`identify` first). Call `subscribe()` from\n * a click: it asks the browser's permission and signs this browser up (your site hosts `/mrrocket-sw.js`). Call\n * `unsubscribe()` on sign-out. Resolves with `{ status: \"subscribed\" | \"denied\" | \"not-asked\" | \"unsupported\" |\n * \"not-signed-in\" | \"error\" }`.\n *\n * const push = usePush();\n * <button onClick={() => push.subscribe()}>Turn on notifications</button>\n */\nexport const usePush = (): { subscribe: (options?: WebPushOptions) => Promise<PushResult>; unsubscribe: () => Promise<boolean> } => {\n const { subscribeToPush, unsubscribeFromPush } = useCtx();\n return useMemo(() => ({ subscribe: subscribeToPush, unsubscribe: unsubscribeFromPush }), [subscribeToPush, unsubscribeFromPush]);\n};\n\n/**\n * A feature flag from MRRocket › Build › Feature flags: true while it is on for this visitor (its audience and rollout\n * in Production), false while it is off, unknown, or the flags have not loaded yet (`useCockpit().ready`). The person's\n * properties from `identify(id, props)` feed the audience conditions (\"Email\", \"Plan\" …).\n *\n * const newCheckout = useFlag(\"new-checkout\");\n */\nexport const useFlag = (key: string): boolean => useFlagValue(key) !== false;\n\n/** The variant of a multivariate flag for this visitor (\"control\", \"test\" …), or null while the flag is off. */\nexport const useFlagVariant = (key: string): string | null => {\n const v = useFlagValue(key);\n return typeof v === \"string\" ? v : null;\n};\n\nconst useFlagValue = (key: string) => {\n const { config, distinctId, user } = useCtx();\n return useMemo(() => flagFor(key, config, distinctId, { ...user }), [key, config, distinctId, user]);\n};\n\n/** The variant this visitor sees, for example `\"control\"` or `\"a\"`. Records the exposure. */\nexport const useVariant = (key: string): VariantId => {\n const { config, distinctId, preview, expose } = useCtx();\n const variant = resolveVariant(key, config, distinctId, preview);\n useEffect(() => {\n if (config || preview[key]) expose(key, variant);\n }, [config, preview, key, variant, expose]);\n return variant;\n};\n\n/** Renders the element for the visitor's variant; control when the variant has no element. */\nexport const Experiment = ({ name, variants }: { name: string; variants: Record<VariantId, ReactNode> & { control: ReactNode } }) => {\n const variant = useVariant(name);\n return <>{variants[variant] ?? variants.control}</>;\n};\n\n/**\n * A text that experiments may change without a deploy: Cockpit sends the new copy for `id` and this renders it.\n * Write your default as the children.\n */\nexport const Text = ({ id, children }: { id: string; children: string }) => {\n const { texts, config, distinctId, preview, expose } = useCtx();\n // Showing a text a running test changes is an exposure to that test, whichever variant the visitor has.\n useEffect(() => {\n for (const key of experimentsOfText(config, id)) expose(key, resolveVariant(key, config, distinctId, preview));\n }, [config, id, distinctId, preview, expose]);\n return <>{texts[id] ?? children}</>;\n};\n\n/**\n * The cancel flow you built in MRRocket › Churn › Cancel flow. Call `open` from your Cancel button: it shows the flow\n * and resolves with what the customer did. MRRocket never changes the subscription; your `onCancel` and `onSave` do.\n *\n * const cancelFlow = useCancelFlow();\n * <button onClick={() => cancelFlow.open({ customer: \"business\", onCancel: cancelSubscription, onSave: applyOffer })}>\n */\nexport const useCancelFlow = (): { open: (options?: CancelFlowOptions) => Promise<CancelFlowResult> } => {\n const { openCancelFlow } = useCtx();\n return useMemo(() => ({ open: openCancelFlow }), [openCancelFlow]);\n};\n"],"mappings":";;;AAEA,SAAyB,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClF,SAAS,mBAAmB;AAC5B,SAAS,KAA4C,cAAc;AACnE,SAAS,QAAQ,8BAA8B;AAC/C,SAAS,cAAc,WAAW,iBAAiB;AAEnD,SAA4B,yBAAyB;AACrD;AAAA,EAEI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP;AAAA,EAKI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,cAAc;AACvB,SAAS,QAAQ,cAAc,WAAW,MAAM,eAAe,cAAc,WAAW,mBAAmB;AAC3G,SAA8E,mBAAmB;AACjG,SAAS,mBAAmB;AAE5B,SAAS,oBAAoB,mBAAmB;AAqoBxC,SAgEG,UA9DY,KAFf;AAloBR,IAAM,SAAS,oBAAI,IAAY;AAC/B,IAAM,WAAW,CAAC,YAAoB;AAClC,MAAI,OAAO,IAAI,OAAO,EAAG;AACzB,SAAO,IAAI,OAAO;AAClB,UAAQ,KAAK,cAAc,OAAO,EAAE;AACxC;AAkEO,IAAM,kBAAkB,CAAC;AAAA,EAC5B,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AO,KAAK,eAAe,KAAK,QAAQ,YAAY,OAAO,CAAC;AAAA,EACjH,GAAG,CAAC,QAAQ,IAAI,YAAY,SAAS,MAAM,CAAC;AAC5C,SAAO,gCAAG,gBAAM,EAAE,KAAK,UAAS;AACpC;AASO,IAAM,gBAAgB,MAA4E;AACrG,QAAM,EAAE,eAAe,IAAI,OAAO;AAClC,SAAO,QAAQ,OAAO,EAAE,MAAM,eAAe,IAAI,CAAC,cAAc,CAAC;AACrE;","names":["live","r","distinctId"]}
1
+ {"version":3,"sources":["../src/client.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Ctx, type CockpitContext, type CockpitUser, useCtx } from \"./context\";\nimport { Survey, forgetStoredDismissals } from \"./survey\";\nimport { RageDetector, clickInfo, seenDepth } from \"./capture\";\nimport type { ReplayHandle } from \"./replay\";\nimport { type ErrorCapture, startErrorCapture } from \"./errors\";\nimport {\n type AttributionMode,\n DEFAULT_REFERRAL_DAYS,\n captureReferral,\n carriesReferral,\n forgetStoredReferral,\n getReferral,\n resetReferral,\n storeReferral,\n} from \"./referral\";\nimport {\n type CockpitConfig,\n type CockpitEvent,\n type ConsentChoice,\n type ConsentMode,\n EMBED_PARAM,\n EXPOSURE_PARAM,\n ID_COOKIE,\n PREVIEW_PARAM,\n SDK_VERSION,\n SESSION_COOKIE,\n type VariantId,\n envKey,\n experimentsOfText,\n exposureFrom,\n flagFor,\n parsePreview,\n redirectFor,\n resolveHost,\n resolveVariant,\n textChanges,\n} from \"./core\";\nimport type { PushResult, WebPushOptions } from \"./push-web\";\nimport { bodies } from \"./batch\";\nimport { YEAR_S, deleteCookie, enterPage, page, privacySignal, touchSession, visitorId, writeCookie } from \"./web-state\";\nimport { type CancelFlowOptions, type CancelFlowResult, type FlowsController, createFlows } from \"./flows\";\nimport { startPicker } from \"./pick\";\nimport type { FlowsTheme } from \"./flows-ui\";\nimport { forgetFlowsStorage, webFlowsEnv } from \"./flows-web\";\n\n/** Tells the developer once, in the browser console, why the SDK is not reaching MRRocket (a wrong host or key is the usual cause). */\nconst warned = new Set<string>();\nconst warnOnce = (message: string) => {\n if (warned.has(message)) return;\n warned.add(message);\n console.warn(`[MRRocket] ${message}`);\n};\n\nexport interface CockpitProviderProps {\n /** The product's public key from Cockpit › Settings › SDK. Safe in the browser. Default: `NEXT_PUBLIC_MRROCKET_KEY`. */\n apiKey?: string;\n /** Where MRRocket runs, like `https://app.example.com`. Default: `NEXT_PUBLIC_MRROCKET_HOST`, else the page's own origin. */\n host?: string;\n preview?: Record<string, VariantId>;\n embedded?: boolean;\n /** Config fetched on the server, to render the right variant on the first paint. */\n config?: CockpitConfig;\n /** Your own id for this visitor, for example a signed-in user id. Keeps variants stable without cookies. */\n distinctId?: string;\n /**\n * \"cookieless\" (default) stores nothing in the browser, \"cookies\" keeps a visitor cookie for a year, \"off\" sends\n * nothing. The SDK does not remember the choice: set it on every page load, from the prop or setConsent().\n */\n consent?: ConsentMode;\n /** Send nothing when the browser asks not to be tracked (Do Not Track or Global Privacy Control). */\n respectDnt?: boolean;\n /**\n * The visitor's consent to session recordings, separate from analytics (default false). Recording also needs the\n * product to record (Cockpit › Sessions) and analytics not \"off\". Without it nothing is recorded or buffered.\n * Change it later with `setConsent({ replay })`.\n */\n replay?: boolean;\n /**\n * Clicks and scroll depth for Heatmaps (default true): where a click landed, a short selector and a link's or\n * button's label, never typed text. Sent under the normal analytics consent as `$click`, `$rageclick` and `$scroll`.\n */\n heatmaps?: boolean;\n /** Ask visitors the surveys you run in Cockpit. Set false to switch them off. */\n surveys?: boolean;\n /**\n * Error tracking for Build › Errors (default true): uncaught errors and unhandled promise rejections, with the page\n * and the last pages and clicks, under the normal analytics consent. Report errors you catch with\n * `useCockpit().captureError(error)`.\n */\n errors?: boolean;\n /** Your release (a version or a commit), so MRRocket can tell which release an error came with. */\n release?: string;\n /**\n * Affiliate referrals (`?ref=` links and MRRocket's tracked links). \"consent\" (default): stored in the first-party\n * `mrr_ref` cookie only while consent is \"cookies\", in memory otherwise. \"always\": stored whatever the consent (only\n * where your legal basis allows it). \"off\": referrals are ignored.\n */\n attribution?: AttributionMode;\n /** The query parameter of direct partner links, default `ref` (`https://your.site/?ref=maya`). */\n referralParam?: string;\n /**\n * Onboarding flows start on their own when the visitor does their trigger (default true). False: only\n * `useCockpit().startOnboarding()` starts one. In-app messages and `openCancelFlow` work either way.\n */\n onboarding?: boolean;\n /** The look of the cancel flow, onboarding and message dialogs: `{ theme: \"dark\", accent: \"#0f766e\", className }`. */\n appearance?: FlowsTheme;\n /**\n * Form leads (0.12.0): a submitted form marked `data-mrrocket-form` becomes a contact in MRRocket (default true).\n * \"auto\" also captures any form with an email field (never one with a password field); false captures none. Only\n * the email, the name and the other fields a person typed go out, never passwords, card or hidden fields (forms.ts).\n */\n forms?: boolean | \"auto\";\n children: ReactNode;\n}\n\n/**\n * Put it once around your app, in `app/layout.tsx`. It loads your experiments, keeps each visitor in one variant,\n * records page views and sends your events to Cockpit in small batches.\n *\n * `preview` forces variants for this render, for example from the `ck_preview` search param on the server,\n * so a Cockpit preview never flickers. Without it the provider reads the param itself after the first render.\n */\nexport const CockpitProvider = ({\n apiKey: apiKeyProp,\n host: hostProp,\n preview: forced,\n embedded: embeddedProp,\n config: bootstrapConfig,\n distinctId: bootstrapId,\n consent: consentProp = \"cookieless\",\n respectDnt = false,\n replay: replayProp = false,\n heatmaps = true,\n surveys = true,\n errors = true,\n release,\n attribution = \"consent\",\n referralParam = \"ref\",\n onboarding = true,\n appearance,\n forms = true,\n children,\n}: CockpitProviderProps) => {\n const pathname = usePathname();\n const apiKey = apiKeyProp ?? envKey() ?? \"\";\n const host = resolveHost(hostProp);\n const [config, setConfig] = useState<CockpitConfig | null>(bootstrapConfig ?? null);\n const [consent, setConsentState] = useState<ConsentMode>(consentProp);\n const [replayConsent, setReplayConsent] = useState(replayProp);\n const [mounted, setMounted] = useState(false);\n const [dnt, setDnt] = useState(false);\n // The visitor id and the consent mode it was made for; null until the browser has been read.\n const [visitor, setVisitor] = useState<{ mode: ConsentMode; id: string } | null>(null);\n const [identified, setIdentified] = useState<string | undefined>();\n const [urlPreview, setUrlPreview] = useState<Record<string, VariantId>>({});\n const [urlEmbedded, setUrlEmbedded] = useState(false);\n const [user, setUser] = useState<CockpitUser | undefined>();\n const [ready, setReady] = useState(!!bootstrapConfig);\n const queue = useRef<CockpitEvent[]>([]);\n // Calls from before the visitor was known (a child's effect runs before ours); replayed once it is.\n const early = useRef<(() => void)[]>([]);\n const exposed = useRef(new Set<string>());\n const lastPage = useRef<string | null>(null);\n\n const bootstrap = bootstrapId && bootstrapId !== \"anonymous\" ? bootstrapId : undefined;\n const preview = useMemo(() => ({ ...urlPreview, ...forced }), [urlPreview, forced]);\n const embedded = embeddedProp ?? urlEmbedded;\n const effectiveConsent: ConsentMode = respectDnt && dnt ? \"off\" : consent;\n const distinctId = identified ?? bootstrap ?? visitor?.id ?? \"anonymous\";\n const tracking = !embedded && effectiveConsent !== \"off\" && visitor?.mode === effectiveConsent;\n // Without cookies, events carry an id only after identify(); the server counts everyone else by its daily hash.\n const sendId = effectiveConsent === \"cookies\" ? distinctId : identified;\n\n // Preview flags and the browser's privacy signal, once, in the browser.\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n setUrlPreview(parsePreview(params.get(PREVIEW_PARAM)));\n setUrlEmbedded(params.get(EMBED_PARAM) === \"1\");\n setDnt(privacySignal());\n setMounted(true);\n // Opened by MRRocket's onboarding editor to pick an element for a tour step (./pick.ts); only then, only in a frame.\n return params.get(EMBED_PARAM) === \"1\" ? (startPicker() ?? undefined) : undefined;\n }, []);\n\n const setConsent = useCallback((choice: ConsentChoice) => {\n const { analytics: mode, replay } = typeof choice === \"string\" ? { analytics: choice, replay: undefined } : choice;\n if (mode === \"off\") queue.current.length = 0;\n if (mode) setConsentState(mode);\n if (typeof replay === \"boolean\") setReplayConsent(replay);\n }, []);\n\n // Follow the `consent` and `replay` props when they change; setConsent() calls in between stay until they do.\n const lastProp = useRef(consentProp);\n useEffect(() => {\n if (lastProp.current === consentProp) return;\n lastProp.current = consentProp;\n setConsent(consentProp);\n }, [consentProp, setConsent]);\n const lastReplayProp = useRef(replayProp);\n useEffect(() => {\n if (lastReplayProp.current === replayProp) return;\n lastReplayProp.current = replayProp;\n setConsent({ replay: replayProp });\n }, [replayProp, setConsent]);\n\n // Storage follows consent. Leaving \"cookies\" deletes what the SDK stored; this page keeps its id in memory.\n const storedFor = useRef<ConsentMode | null>(null);\n useEffect(() => {\n if (!mounted) return;\n const before = storedFor.current;\n storedFor.current = effectiveConsent;\n if (before === \"cookies\" && effectiveConsent !== \"cookies\") {\n deleteCookie(ID_COOKIE);\n deleteCookie(SESSION_COOKIE);\n forgetStoredDismissals();\n forgetFlowsStorage();\n }\n if (effectiveConsent === \"off\") {\n queue.current.length = 0;\n page.session = undefined;\n }\n setVisitor({ mode: effectiveConsent, id: visitorId(effectiveConsent, !bootstrap) });\n }, [mounted, effectiveConsent, bootstrap]);\n\n // Experiments for this key. Without a key or when MRRocket is unreachable the page keeps control and carries on.\n useEffect(() => {\n if (!apiKey) warnOnce(\"No public key. Pass apiKey or set NEXT_PUBLIC_MRROCKET_KEY; nothing is tracked until then.\");\n if (bootstrapConfig || !apiKey) {\n setReady(true);\n return;\n }\n let live = true;\n fetch(`${host}/api/sdk/config?key=${encodeURIComponent(apiKey)}`)\n .then((r) => {\n if (!r.ok) warnOnce(`Config request to ${host || \"this origin\"} answered ${r.status}. Check the public key and NEXT_PUBLIC_MRROCKET_HOST.`);\n return r.ok ? r.json() : null;\n })\n .then((c: CockpitConfig | null) => {\n if (!live) return;\n if (c && Array.isArray(c.experiments)) setConfig(c);\n setReady(true);\n })\n .catch(() => {\n warnOnce(`Could not reach ${host || \"this origin\"}. Check NEXT_PUBLIC_MRROCKET_HOST. The page keeps working with control variants.`);\n if (live) setReady(true);\n });\n return () => {\n live = false;\n };\n }, [apiKey, host, bootstrapConfig]);\n\n const flush = useCallback(\n (beacon = false) => {\n if (!queue.current.length) return;\n if (!apiKey) {\n queue.current.length = 0;\n return;\n }\n const url = `${host}/api/sdk/events`;\n for (const body of bodies(apiKey, queue.current.splice(0), { v: SDK_VERSION, errors })) {\n const sent = beacon && typeof navigator !== \"undefined\" && \"sendBeacon\" in navigator && navigator.sendBeacon(url, body);\n if (!sent)\n fetch(url, { method: \"POST\", headers: { \"content-type\": \"application/json\" }, body, keepalive: true })\n .then((r) => {\n if (!r.ok) warnOnce(`Events were rejected with ${r.status}. Check the public key (Settings › SDK) and NEXT_PUBLIC_MRROCKET_HOST.`);\n })\n .catch(() => warnOnce(`Could not reach ${host || \"this origin\"} to send events. Check NEXT_PUBLIC_MRROCKET_HOST.`));\n }\n },\n [apiKey, host, errors],\n );\n\n useEffect(() => {\n const timer = window.setInterval(() => flush(), 2000);\n const leave = () => flush(true);\n window.addEventListener(\"pagehide\", leave);\n return () => {\n window.clearInterval(timer);\n window.removeEventListener(\"pagehide\", leave);\n flush(true);\n };\n }, [flush]);\n\n // The latest values for callbacks that must not change identity, so effects that use them run once.\n const live = useRef({ resolved: false, tracking, distinctId, sendId, persist: false, identified: false });\n live.current = { resolved: visitor !== null, tracking, distinctId, sendId, persist: visitor?.mode === \"cookies\", identified: !!identified };\n\n const record = useCallback((event: string, props: Record<string, unknown> | undefined, ts = Date.now(), url?: string) => {\n const now = live.current;\n if (!now.resolved) {\n early.current.push(() => record(event, props, ts, url));\n return;\n }\n // Previews in Cockpit never count, and nothing is sent without consent.\n if (!now.tracking) return;\n const referral = carriesReferral(event) ? getReferral() : null;\n queue.current.push({\n event,\n props: referral ? { ...props, $referral: { code: referral.code, clickId: referral.clickId } } : props,\n distinctId: now.sendId,\n sessionId: touchSession(now.persist),\n ts,\n url: url ?? window.location.href,\n referrer: page.referrer,\n ...page.utm,\n screen: { w: window.screen.width, h: window.screen.height },\n });\n }, []);\n\n // The running recorder, if this visit records (see the recording effect below).\n const replayer = useRef<ReplayHandle | null>(null);\n // Error tracking, while `errors` is on (see the effect below).\n const errorer = useRef<ErrorCapture | null>(null);\n\n // The cancel flow, onboarding and in-app messages (flows.ts): one controller for the provider's lifetime.\n const flowsRef = useRef<FlowsController | null>(null);\n const flows = (flowsRef.current ??= createFlows(\n webFlowsEnv({\n host,\n apiKey,\n track: (event, props) => record(event, props),\n personId: () => (live.current.tracking && live.current.identified ? live.current.distinctId : undefined),\n canStore: () => live.current.persist,\n auto: onboarding,\n }),\n ));\n\n const track = useCallback(\n (event: string, props?: Record<string, unknown>) => {\n record(event, props);\n if (live.current.tracking) replayer.current?.event(event);\n flows.onEvent(event);\n },\n [record, flows],\n );\n\n const identify = useCallback(\n (id: string, props?: Record<string, unknown>) => {\n const now = live.current;\n if (!now.resolved) {\n early.current.push(() => identify(id, props));\n return;\n }\n const previous = now.sendId;\n // From here on events carry this id in every mode; only \"cookies\" keeps it for the next visit.\n live.current = { ...now, distinctId: id, sendId: id, identified: true };\n record(\"$identify\", { ...props, id, ...(previous && previous !== id ? { previousId: previous } : {}) });\n replayer.current?.identify(id);\n if (now.persist) writeCookie(ID_COOKIE, id, YEAR_S);\n setIdentified(id);\n setUser({ id, ...(props as Omit<CockpitUser, \"id\">) });\n },\n [record],\n );\n\n // Form leads (forms.ts, a dynamic import): one submit listener on the document while `forms` is on.\n const identifyRef = useRef(identify);\n identifyRef.current = identify;\n useEffect(() => {\n if (!forms || !apiKey || embedded || typeof window === \"undefined\") return;\n let off: (() => void) | undefined;\n let gone = false;\n void import(\"./forms\")\n .then((m) => {\n if (gone) return;\n off = m.watchForms({\n host,\n apiKey,\n auto: forms === \"auto\",\n distinctId: () => (live.current.tracking ? live.current.sendId : undefined),\n identified: () => live.current.identified,\n identify: (id, props) => identifyRef.current(id, props),\n tracking: () => live.current.tracking,\n referrer: () => page.referrer,\n utm: () => page.utm,\n });\n })\n .catch(() => undefined);\n return () => {\n gone = true;\n off?.();\n };\n }, [forms, apiKey, host, embedded]);\n\n // Replay what came in before the visitor was known: sent when tracking is on, dropped when it is not.\n useEffect(() => {\n if (!visitor) return;\n for (const run of early.current.splice(0)) run();\n }, [visitor]);\n\n // Affiliate referrals: read once the consent is known and the program's cookie days have loaded.\n const referralDays = config?.referral?.cookieDays ?? DEFAULT_REFERRAL_DAYS;\n const storeReferrals = attribution === \"always\" ? effectiveConsent !== \"off\" : attribution === \"consent\" && effectiveConsent === \"cookies\";\n const captured = useRef<string | null>(null);\n const storedReferral = useRef(false);\n useEffect(() => {\n if (!visitor || !ready || embedded) return;\n if (attribution === \"off\" || effectiveConsent === \"off\") {\n resetReferral();\n if (attribution === \"off\" || storedReferral.current) forgetStoredReferral();\n return;\n }\n const href = window.location.href;\n if (captured.current === href) return;\n captured.current = href;\n void captureReferral({\n search: window.location.search,\n param: referralParam,\n store: storeReferrals,\n days: referralDays,\n beacon: apiKey\n ? ({ code, clickId }) =>\n fetch(`${host}/api/sdk/affiliate/click`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ key: apiKey, code, clickId, url: href, referrer: document.referrer || undefined }),\n keepalive: true,\n })\n .then((r) => (r.ok ? (r.json() as Promise<{ clickId?: string | null }>) : null))\n .then((b) => b?.clickId ?? null)\n : undefined,\n });\n }, [visitor, ready, embedded, attribution, effectiveConsent, pathname, referralParam, storeReferrals, referralDays, apiKey, host]);\n\n // Consent given later keeps this page load's referral; consent withdrawn deletes what was stored.\n useEffect(() => {\n if (!mounted) return;\n const r = getReferral();\n if (storeReferrals && r) storeReferral(r, referralDays);\n else if (!storeReferrals && storedReferral.current) forgetStoredReferral();\n storedReferral.current = storeReferrals;\n }, [mounted, storeReferrals, referralDays]);\n\n // `tracking` is a dependency so that variants seen before consent are recorded once tracking starts.\n const expose = useCallback(\n (key: string, variant: VariantId) => {\n if (!tracking) return;\n const mark = `${pathname}|${key}`;\n if (exposed.current.has(mark)) return;\n exposed.current.add(mark);\n track(\"$exposure\", { experiment: key, variant });\n },\n [pathname, track, tracking],\n );\n\n // Redirects, once per page: a page redirect or a redirect test's variant sends the visitor on as soon as the config is\n // known (`experimentRedirect` in proxy.ts does it before the page renders, without a flash). A redirect test's\n // control stays and is recorded here; the page a variant lands on records it from `ck_x`, then drops the parameter.\n const decided = useRef<{ path: string; r: ReturnType<typeof redirectFor> } | null>(null);\n const arrived = useRef<string | null | undefined>(undefined);\n useEffect(() => {\n if (!ready || !visitor) return;\n if (decided.current?.path !== pathname) {\n const r = redirectFor(config, window.location.href, distinctId, preview);\n decided.current = { path: pathname, r };\n if (r?.to) {\n flush(true);\n window.location.replace(r.to);\n return;\n }\n }\n if (arrived.current === undefined) {\n const params = new URLSearchParams(window.location.search);\n arrived.current = params.get(EXPOSURE_PARAM);\n if (arrived.current !== null) {\n params.delete(EXPOSURE_PARAM);\n const q = params.toString();\n window.history.replaceState(window.history.state, \"\", `${window.location.pathname}${q ? `?${q}` : \"\"}${window.location.hash}`);\n }\n }\n if (!tracking) return;\n const r = decided.current.r;\n if (r?.experiment && !r.to) expose(r.experiment, r.variant!);\n const x = exposureFrom(config, arrived.current);\n if (x) expose(x.experiment, x.variant);\n arrived.current = null;\n }, [ready, visitor, pathname, config, distinctId, preview, tracking, expose, flush]);\n\n // The referrer and campaign of each page; before the page view below, so it already carries them.\n useEffect(() => {\n enterPage();\n replayer.current?.page(pathname);\n errorer.current?.crumb(\"navigation\", pathname);\n }, [pathname]);\n\n // Errors of the page for Build › Errors; sent only while tracking (consent, not a preview), like events.\n useEffect(() => {\n if (!errors || !apiKey || embedded) return;\n const capture = startErrorCapture({\n host,\n apiKey,\n release,\n context: () => ({ send: live.current.tracking, distinctId: live.current.sendId, sessionId: page.session?.id }),\n warn: warnOnce,\n });\n errorer.current = capture;\n capture.crumb(\"navigation\", window.location.pathname);\n return () => {\n capture.stop();\n if (errorer.current === capture) errorer.current = null;\n };\n }, [errors, apiKey, host, release, embedded]);\n\n const captureError = useCallback((error: unknown) => errorer.current?.capture(error, \"manual\"), []);\n\n // One page view per route change while tracking, so a later setConsent() records the current page right away\n // (a ref keeps React's dev double-run from counting twice).\n useEffect(() => {\n if (!tracking || lastPage.current === pathname) return;\n lastPage.current = pathname;\n // Exposures are remembered per path (\"/pricing|test\"), so nothing needs clearing here.\n track(\"$pageview\", { path: pathname });\n }, [pathname, tracking, track]);\n\n // Clicks on anything marked `data-ck-goal=\"signup_started\"` count as that goal. Every click also feeds Heatmaps\n // (`$click`, `$rageclick` on the third quick click on one spot) and, when this visit records, the recording.\n const rage = useRef(new RageDetector());\n useEffect(() => {\n const onClick = (e: MouseEvent) => {\n const el = (e.target as HTMLElement | null)?.closest<HTMLElement>(\"[data-ck-goal]\");\n if (el?.dataset.ckGoal) track(el.dataset.ckGoal, { text: el.textContent?.trim().slice(0, 80) });\n if (!live.current.tracking) return;\n const c = clickInfo(e);\n if (!c) return;\n const raged = rage.current.push(c.x, c.y, Date.now());\n if (c.label || c.selector) errorer.current?.crumb(\"click\", c.label || c.selector);\n replayer.current?.click(c, raged);\n if (!heatmaps) return;\n const props = { x: c.x, y: c.y, vw: c.vw, vh: c.vh, docH: c.docH, selector: c.selector, label: c.label, dead: !c.interactive };\n record(\"$click\", props);\n if (raged) record(\"$rageclick\", props);\n };\n document.addEventListener(\"click\", onClick);\n return () => document.removeEventListener(\"click\", onClick);\n }, [track, record, heatmaps]);\n\n // Scroll depth for Heatmaps: the deepest point seen on each page, sent when the page changes or hides.\n const depth = useRef<{ url: string; max: number; docH: number } | null>(null);\n useEffect(() => {\n if (!heatmaps || !tracking || embedded) return;\n const send = () => {\n const d = depth.current;\n if (d && d.max > 0) record(\"$scroll\", { depth: d.max, docH: d.docH, vw: window.innerWidth, vh: window.innerHeight }, Date.now(), d.url);\n depth.current = null;\n };\n const measure = () => {\n const doc = document.documentElement;\n const docH = Math.max(doc.scrollHeight, document.body?.scrollHeight ?? 0);\n const max = seenDepth();\n const href = window.location.href;\n if (depth.current?.url !== href) depth.current = { url: href, max, docH };\n else if (max > depth.current.max) depth.current = { url: href, max, docH };\n };\n measure();\n let frame = 0;\n const onScroll = () => {\n if (frame) return;\n frame = window.requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n };\n const onHide = () => {\n send();\n flush(true);\n };\n window.addEventListener(\"scroll\", onScroll, { passive: true });\n window.addEventListener(\"pagehide\", onHide);\n return () => {\n window.removeEventListener(\"scroll\", onScroll);\n window.removeEventListener(\"pagehide\", onHide);\n window.cancelAnimationFrame(frame);\n send();\n };\n }, [heatmaps, tracking, embedded, pathname, record, flush]);\n\n // Session recording: only with the visitor's replay consent, while tracking, and when the product records. The\n // recorder and rrweb are loaded here, lazily; withdrawing consent stops it and drops what was not sent.\n const replayConfig = config?.replay;\n const recording = tracking && replayConsent && !!replayConfig && !!apiKey;\n useEffect(() => {\n if (!recording || !replayConfig) return;\n let active = true;\n let handle: ReplayHandle | null = null;\n // `typeof window` is a build-time constant in Next.js: on the server this folds to null and the import (with\n // rrweb) never enters the server bundle.\n void (typeof window === \"undefined\" ? Promise.resolve(null) : import(\"./replay\"))\n .then((m) =>\n m?.startReplay({\n host,\n apiKey,\n sessionId: touchSession(live.current.persist),\n distinctId: live.current.sendId,\n identified: live.current.identified,\n sampleRate: replayConfig.sampleRate,\n warn: warnOnce,\n }),\n )\n .then((h) => {\n if (!active) h?.stop(true);\n else replayer.current = handle = h ?? null;\n })\n .catch(() => warnOnce(\"Session recording could not start (the recorder did not load).\"));\n return () => {\n active = false;\n handle?.stop(true);\n if (replayer.current === handle) replayer.current = null;\n };\n }, [recording, replayConfig, host, apiKey]);\n\n // The flows follow the config and the person: their messages and onboarding progress load once both are known.\n useEffect(() => {\n if (!ready || !visitor || embedded) return;\n flows.setConfig(config);\n void flows.refresh();\n }, [flows, ready, visitor, embedded, config, identified, tracking, effectiveConsent]);\n\n // The dialogs load the first time something is about to show (a dynamic import), and stay mounted after.\n const look = useRef(appearance);\n look.current = appearance;\n useEffect(() => {\n if (embedded) return;\n let unmount: (() => void) | null = null;\n let loading = false;\n let gone = false;\n const show = () => {\n if (unmount || loading || !flows.view()) return;\n loading = true;\n void (typeof window === \"undefined\" ? Promise.resolve(null) : import(\"./flows-ui\"))\n .then((m) => {\n if (!m || gone) return;\n unmount = m.mountFlows(flows, look.current);\n })\n .catch(() => warnOnce(\"The cancel flow and onboarding dialogs did not load.\"))\n .finally(() => {\n loading = false;\n });\n };\n const off = flows.subscribe(show);\n show();\n return () => {\n gone = true;\n off();\n unmount?.();\n };\n }, [flows, embedded]);\n\n const openCancelFlow = useCallback((options?: CancelFlowOptions) => flows.openCancelFlow(options), [flows]);\n const startOnboarding = useCallback((id?: string) => flows.startOnboarding(id), [flows]);\n\n // Web push (push-web.ts, a dynamic import on the first call). The permission is asked here, synchronously inside the\n // click that called it: Safari refuses one asked after an await.\n const subscribeToPush = useCallback(\n (options?: WebPushOptions): Promise<PushResult> => {\n if (typeof window === \"undefined\") return Promise.resolve({ status: \"unsupported\" });\n const now = live.current;\n const distinctId = now.tracking && now.identified ? now.distinctId : undefined;\n if (!distinctId) return Promise.resolve({ status: \"not-signed-in\" });\n const N = window.Notification;\n const permission = Promise.resolve(N && N.permission === \"default\" && options?.ask !== false ? N.requestPermission() : N?.permission);\n return import(\"./push-web\").then((m) => m.subscribeWebPush({ host, apiKey, distinctId, permission }, options));\n },\n [host, apiKey],\n );\n const unsubscribeFromPush = useCallback(\n () =>\n typeof window === \"undefined\"\n ? Promise.resolve(false)\n : import(\"./push-web\").then((m) => m.unsubscribeWebPush({ host, apiKey, distinctId: live.current.identified ? live.current.distinctId : undefined })),\n [host, apiKey],\n );\n\n const texts = useMemo(() => textChanges(config, distinctId, preview), [config, distinctId, preview]);\n\n const value = useMemo<CockpitContext>(\n () => ({\n apiKey,\n host,\n user,\n ready,\n distinctId,\n config,\n preview,\n embedded,\n consent,\n effectiveConsent,\n replayConsent,\n setConsent,\n texts,\n track,\n identify,\n expose,\n captureError,\n openCancelFlow,\n startOnboarding,\n subscribeToPush,\n unsubscribeFromPush,\n }),\n [\n apiKey,\n host,\n user,\n ready,\n distinctId,\n config,\n preview,\n embedded,\n consent,\n effectiveConsent,\n replayConsent,\n setConsent,\n texts,\n track,\n identify,\n expose,\n captureError,\n openCancelFlow,\n startOnboarding,\n subscribeToPush,\n unsubscribeFromPush,\n ],\n );\n return (\n <Ctx.Provider value={value}>\n {children}\n {surveys ? <Survey /> : null}\n </Ctx.Provider>\n );\n};\n\n/**\n * `track`, `identify`, `captureError`, the consent mode, the replay consent and their setter, the visitor id and whether\n * the experiments and flags have loaded. `setConsent(\"cookies\")` sets the mode, `setConsent({ replay: true })` the\n * replay consent.\n */\nexport const useCockpit = () => {\n const { track, identify, captureError, distinctId, ready, embedded, consent, replayConsent, setConsent, openCancelFlow, startOnboarding } = useCtx();\n return { track, identify, captureError, distinctId, ready, embedded, consent, replay: replayConsent, setConsent, openCancelFlow, startOnboarding };\n};\n\n/**\n * Push notifications from your Lifecycle journeys for the signed-in person (`identify` first). Call `subscribe()` from\n * a click: it asks the browser's permission and signs this browser up (your site hosts `/mrrocket-sw.js`). Call\n * `unsubscribe()` on sign-out. Resolves with `{ status: \"subscribed\" | \"denied\" | \"not-asked\" | \"unsupported\" |\n * \"not-signed-in\" | \"error\" }`.\n *\n * const push = usePush();\n * <button onClick={() => push.subscribe()}>Turn on notifications</button>\n */\nexport const usePush = (): { subscribe: (options?: WebPushOptions) => Promise<PushResult>; unsubscribe: () => Promise<boolean> } => {\n const { subscribeToPush, unsubscribeFromPush } = useCtx();\n return useMemo(() => ({ subscribe: subscribeToPush, unsubscribe: unsubscribeFromPush }), [subscribeToPush, unsubscribeFromPush]);\n};\n\n/**\n * A feature flag from MRRocket › Build › Feature flags: true while it is on for this visitor (its audience and rollout\n * in Production), false while it is off, unknown, or the flags have not loaded yet (`useCockpit().ready`). The person's\n * properties from `identify(id, props)` feed the audience conditions (\"Email\", \"Plan\" …).\n *\n * const newCheckout = useFlag(\"new-checkout\");\n */\nexport const useFlag = (key: string): boolean => useFlagValue(key) !== false;\n\n/** The variant of a multivariate flag for this visitor (\"control\", \"test\" …), or null while the flag is off. */\nexport const useFlagVariant = (key: string): string | null => {\n const v = useFlagValue(key);\n return typeof v === \"string\" ? v : null;\n};\n\nconst useFlagValue = (key: string) => {\n const { config, distinctId, user } = useCtx();\n return useMemo(() => flagFor(key, config, distinctId, { ...user }), [key, config, distinctId, user]);\n};\n\n/** The variant this visitor sees, for example `\"control\"` or `\"a\"`. Records the exposure. */\nexport const useVariant = (key: string): VariantId => {\n const { config, distinctId, preview, expose } = useCtx();\n const variant = resolveVariant(key, config, distinctId, preview);\n useEffect(() => {\n if (config || preview[key]) expose(key, variant);\n }, [config, preview, key, variant, expose]);\n return variant;\n};\n\n/** Renders the element for the visitor's variant; control when the variant has no element. */\nexport const Experiment = ({ name, variants }: { name: string; variants: Record<VariantId, ReactNode> & { control: ReactNode } }) => {\n const variant = useVariant(name);\n return <>{variants[variant] ?? variants.control}</>;\n};\n\n/**\n * A text that experiments may change without a deploy: Cockpit sends the new copy for `id` and this renders it.\n * Write your default as the children.\n */\nexport const Text = ({ id, children }: { id: string; children: string }) => {\n const { texts, config, distinctId, preview, expose } = useCtx();\n // Showing a text a running test changes is an exposure to that test, whichever variant the visitor has.\n useEffect(() => {\n for (const key of experimentsOfText(config, id)) expose(key, resolveVariant(key, config, distinctId, preview));\n }, [config, id, distinctId, preview, expose]);\n return <>{texts[id] ?? children}</>;\n};\n\n/**\n * The cancel flow you built in MRRocket › Churn › Cancel flow. Call `open` from your Cancel button: it shows the flow\n * and resolves with what the customer did. MRRocket never changes the subscription; your `onCancel` and `onSave` do.\n *\n * const cancelFlow = useCancelFlow();\n * <button onClick={() => cancelFlow.open({ customer: \"business\", onCancel: cancelSubscription, onSave: applyOffer })}>\n */\nexport const useCancelFlow = (): { open: (options?: CancelFlowOptions) => Promise<CancelFlowResult> } => {\n const { openCancelFlow } = useCtx();\n return useMemo(() => ({ open: openCancelFlow }), [openCancelFlow]);\n};\n"],"mappings":";;;AAEA,SAAyB,aAAa,WAAW,SAAS,QA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;AAGO,IAAM,aAAa,CAAC,EAAE,MAAM,SAAS,MAAyF;AACjI,QAAM,UAAU,WAAW,IAAI;AAC/B,SAAO,gCAAG,mBAAS,OAAO,KAAK,SAAS,SAAQ;AACpD;AAMO,IAAM,OAAO,CAAC,EAAE,IAAI,SAAS,MAAwC;AACxE,QAAM,EAAE,OAAO,QAAQ,YAAY,SAAS,OAAO,IAAI,OAAO;AAE9D,YAAU,MAAM;AACZ,eAAW,OAAO,kBAAkB,QAAQ,EAAE,EAAG,QAAO,KAAK,eAAe,KAAK,QAAQ,YAAY,OAAO,CAAC;AAAA,EACjH,GAAG,CAAC,QAAQ,IAAI,YAAY,SAAS,MAAM,CAAC;AAC5C,SAAO,gCAAG,gBAAM,EAAE,KAAK,UAAS;AACpC;AASO,IAAM,gBAAgB,MAA4E;AACrG,QAAM,EAAE,eAAe,IAAI,OAAO;AAClC,SAAO,QAAQ,OAAO,EAAE,MAAM,eAAe,IAAI,CAAC,cAAc,CAAC;AACrE;","names":["live","r","distinctId"]}
package/dist/core.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  import type { CancelFlowConfig, OnboardingFlow } from "./flows.js";
6
6
  export type VariantId = string;
7
7
  /** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */
8
- export declare const SDK_VERSION = "0.11.0";
8
+ export declare const SDK_VERSION = "0.13.0";
9
9
  /** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */
10
10
  export interface VariantConfig {
11
11
  id: VariantId;
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core.ts
2
- var SDK_VERSION = "0.11.0";
2
+ var SDK_VERSION = "0.13.0";
3
3
  var propOf = (person, name) => {
4
4
  const want = name.trim().toLowerCase();
5
5
  for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.11.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto 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E,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO,IAAI,EAAE,YAAY,KAAK,QAAQ,IAAI;AAC1F;AAOO,IAAM,UAAU,MAA0B;AAC7C,MAAI;AACA,WAAO,QAAQ,IAAI,6BAA6B;AAAA,EACpD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,IAAM,SAAS,MAA0B;AAC5C,MAAI;AACA,WAAO,QAAQ,IAAI,4BAA4B;AAAA,EACnD,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAMO,IAAM,cAAc,CAAC,UAAmB,QAAQ,QAAQ,KAAK,IAAI,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAG1F,IAAM,gBAAgB,MACzB,OAAO,WAAW,eAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,MAAM,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * The part of the SDK that runs anywhere: experiment config, variant assignment, preview links and event shapes.\n * No React, no browser APIs, so the server helper, the proxy helper and the client share it.\n */\nimport type { CancelFlowConfig, OnboardingFlow } from \"./flows\";\n\nexport type VariantId = string;\n\n/** This build of the SDK. Sent with the config request so MRRocket knows what the site runs (error tracking, flags). */\nexport const SDK_VERSION = \"0.13.0\";\n\n/** One variant of an experiment. `changes` replaces texts that the page marks with `<Text id>`. */\nexport interface VariantConfig {\n id: VariantId;\n /** Share of traffic, 0 to 1. The weights of an experiment add up to 1. */\n weight: number;\n changes?: Record<string, string>;\n /**\n * A redirect test: where this variant sends the visitor instead of the test's page (a path like \"/pricing-b\" or a\n * full address). Control has none and stays. SDK 0.7.0+.\n */\n url?: string;\n}\n\nexport interface ExperimentConfig {\n /** The experiment's key, the same as in Cockpit. */\n key: string;\n status: \"running\" | \"draft\" | \"stopped\";\n /** Control first. */\n variants: VariantConfig[];\n /** A winner that shipped: everyone gets it, and nobody is assigned anymore. */\n winner?: VariantId;\n /** A redirect test: the path of the page it runs on (\"/pricing\"). Visitors there are sent to their variant's `url`. */\n path?: string;\n}\n\n/** A page redirect set in MRRocket (Conversion › Landing pages › Redirect): everyone on `from` goes to `to`. SDK 0.7.0+. */\nexport interface RedirectConfig {\n /** A path of the site, like \"/old-pricing\". */\n from: string;\n /** A path or a full address. */\n to: string;\n}\n\nexport interface CockpitConfig {\n /** The product the public key belongs to. */\n project: string;\n experiments: ExperimentConfig[];\n /** The product's affiliate program: how many days a partner's referral is kept. Missing without a program. */\n referral?: { cookieDays: number };\n /** Session recordings: present only while the product records (Cockpit › Sessions). See `ReplayConfig`. */\n replay?: ReplayConfig;\n /** Feature flags of the product in Production (MRRocket › Build › Feature flags), evaluated by `useFlag` and `getFlag`. */\n flags?: FlagConfig[];\n /**\n * Published copy for texts the site marks (`<Text id>`, `data-ck-text`): a landing page's headline, subheadline and\n * button (`pricing.headline` …) and a paywall's (`paywall.<placement>.headline` …) as published in MRRocket. A\n * running test's variant changes them on top. Missing when nothing is published. SDK 0.5.0+.\n */\n texts?: Record<string, string>;\n /** The product's live cancel flow (MRRocket › Churn › Cancel flow), for `cancelFlow.open()`. SDK 0.7.0+. */\n cancelFlow?: CancelFlowConfig;\n /** The in-app steps of live onboarding flows (tours, checklists, modals). SDK 0.7.0+. */\n onboarding?: OnboardingFlow[];\n /** A live Lifecycle journey has in-app messages: signed-in people ask `/api/sdk/inapp` for theirs. SDK 0.7.0+. */\n messages?: boolean;\n /** Page redirects set in MRRocket; the SDK sends visitors on before the page shows (`redirectFor`). SDK 0.7.0+. */\n redirects?: RedirectConfig[];\n}\n\n/** One condition of a flag's audience, on a property of the person (`identify(id, props)`), the id or the page. */\nexport interface FlagCondition {\n /** \"Email\", \"Plan\", \"Country\", \"id\", \"path\" … Matched against the person's properties without regard to case. */\n property: string;\n op: \"is\" | \"is not\" | \"in\" | \"not in\" | \"≥\" | \"in cohort\";\n values: string[];\n}\n\n/** Users who match every condition, of whom `rollout` percent get the flag. No conditions: everyone. */\nexport interface FlagConditionSet {\n conditions: FlagCondition[];\n /** 0 to 100. */\n rollout: number;\n}\n\nexport interface FlagConfig {\n key: string;\n /** Off: everyone gets the off side. */\n on: boolean;\n /** The first set a person matches decides; none matched: off. */\n sets: FlagConditionSet[];\n /** Multivariate flags: the variants and their split in percent (control included). Missing for an on/off flag. */\n variants?: { key: string; split: number; payload?: string }[];\n}\n\n/** What a person is for flag conditions: their properties from identify(), their id and the page they are on. */\nexport type FlagPerson = Record<string, unknown>;\n\nconst propOf = (person: FlagPerson, name: string) => {\n const want = name.trim().toLowerCase();\n for (const [k, v] of Object.entries(person)) if (k.toLowerCase() === want) return v;\n return undefined;\n};\n\n/** `\"@acme.com\"` matches every address at that domain; anything else matches the whole value, without regard to case. */\nconst same = (actual: string, value: string) => {\n const a = actual.trim().toLowerCase();\n const v = value.trim().toLowerCase();\n return v.startsWith(\"@\") ? a.endsWith(v) : a === v;\n};\n\nconst matchesCondition = (c: FlagCondition, person: FlagPerson) => {\n // Cohorts live in MRRocket; a browser cannot know them, so a cohort condition never matches here.\n if (c.op === \"in cohort\") return false;\n const raw = propOf(person, c.property);\n const actual = raw === undefined || raw === null ? \"\" : String(raw);\n if (c.op === \"≥\") {\n const a = Number(actual);\n const b = Number(c.values[0]);\n return actual !== \"\" && Number.isFinite(a) && Number.isFinite(b) && a >= b;\n }\n const hit = actual !== \"\" && c.values.some((v) => same(actual, v));\n return c.op === \"is\" || c.op === \"in\" ? hit : !hit;\n};\n\n/**\n * The flag for one person: `false` (off), `true` (on, an on/off flag) or the variant's key (a multivariate flag). The\n * bucket is a stable hash of flag and person, so a person keeps their side as the rollout grows.\n */\nexport const evaluateFlag = (flag: FlagConfig, distinctId: string, person: FlagPerson = {}): boolean | string => {\n if (!flag.on) return false;\n const subject = { id: distinctId, ...person };\n const set = flag.sets.length ? flag.sets.find((s) => s.conditions.every((c) => matchesCondition(c, subject))) : { conditions: [], rollout: 100 };\n if (!set) return false;\n if (flagUnit(`${flag.key}:rollout:${distinctId}`) * 100 >= set.rollout) return false;\n if (!flag.variants?.length) return true;\n const u = flagUnit(`${flag.key}:variant:${distinctId}`) * 100;\n let acc = 0;\n for (const v of flag.variants) {\n acc += v.split;\n if (u < acc) return v.key;\n }\n return flag.variants[flag.variants.length - 1].key;\n};\n\n/** A flag of the config for this person; an unknown flag (or no config) is off. */\nexport const flagFor = (key: string, config: CockpitConfig | null, distinctId: string, person: FlagPerson = {}) => {\n const flag = config?.flags?.find((f) => f.key === key);\n return flag ? evaluateFlag(flag, distinctId, person) : false;\n};\n\n/** One JavaScript error as it goes over the wire to `POST /api/sdk/errors`. */\nexport interface ErrorReport {\n /** \"TypeError\", \"Error\" … */\n type: string;\n message: string;\n /** The raw stack, at most 8 KB. MRRocket parses it into frames. */\n stack?: string;\n /** \"onerror\" (uncaught), \"onunhandledrejection\" (a rejected promise nobody caught) or \"manual\" (captureError). */\n mechanism: \"onerror\" | \"onunhandledrejection\" | \"manual\";\n handled: boolean;\n url: string;\n ts: number;\n /** What happened just before: pages and clicks, newest last, at most 20. */\n crumbs?: { ts: number; type: \"navigation\" | \"click\" | \"lifecycle\"; message: string }[];\n /** Your release (a version or commit), from the provider's `release` prop. */\n release?: string;\n distinctId?: string;\n sessionId?: string;\n}\n\n/**\n * Session recordings of a product, from the config. Recording also needs the visitor's own replay consent\n * (`<CockpitProvider replay>` or `setConsent({ replay: true })`); without it nothing is recorded or buffered.\n */\nexport interface ReplayConfig {\n /**\n * Share of sessions uploaded from their start, 0 to 1 (default 0.1). The others keep only the last minute in\n * memory and upload it when something goes wrong: a JS error, a rage click, a `purchase…` or `checkout…` event.\n */\n sampleRate: number;\n}\n\n/**\n * What the SDK may send and store.\n * - \"cookieless\" (default): no cookie, no localStorage. Events go without a visitor id; the server counts visitors\n * with a hash of key, date, IP and user agent that changes every day.\n * - \"cookies\": a persistent `ck_id` cookie identifies the visitor across visits, `ck_sid` holds the session.\n * - \"off\": nothing is sent and nothing is stored.\n */\nexport type ConsentMode = \"cookieless\" | \"cookies\" | \"off\";\n\n/**\n * What `setConsent` takes: a mode as before, or the parts to change. `replay` is the separate consent for session\n * recordings (default false); it applies only while analytics is not \"off\".\n *\n * setConsent(\"cookies\");\n * setConsent({ replay: true });\n * setConsent({ analytics: \"cookieless\", replay: false });\n */\nexport type ConsentChoice = ConsentMode | { analytics?: ConsentMode; replay?: boolean };\n\n/** The campaign parameters the SDK reads from the landing URL. */\nexport const UTM_KEYS = [\"utm_source\", \"utm_medium\", \"utm_campaign\", \"utm_term\", \"utm_content\"] as const;\nexport type UtmKey = (typeof UTM_KEYS)[number];\n\n/** One event as it goes over the wire to `POST /api/sdk/events`. */\nexport interface CockpitEvent {\n event: string;\n /** The visitor. Missing in \"cookieless\" mode until identify(): the server then uses its daily visitor hash. */\n distinctId?: string;\n /** Ends after 30 minutes without an event. */\n sessionId?: string;\n props?: Record<string, unknown>;\n /** Milliseconds since the epoch. */\n ts: number;\n url?: string;\n /** `document.referrer` on the first page of a page load, the previous in-app URL after client-side navigation. */\n referrer?: string;\n utm_source?: string;\n utm_medium?: string;\n utm_campaign?: string;\n utm_term?: string;\n utm_content?: string;\n /** The screen size in CSS pixels (points on a phone). */\n screen?: { w: number; h: number };\n /** The app that sent it (React Native only): MRRocket stores it with the event and fills OS and device from it. */\n app?: AppContext;\n}\n\n/** Where a React Native event comes from. Every field is optional except the platform; nothing identifies the person. */\nexport interface AppContext {\n /** \"ios\" or \"android\" (React Native's `Platform.OS`). */\n platform: string;\n /** The app's version, like \"1.4.0\" (`expo-application`'s `nativeApplicationVersion`). */\n appVersion?: string;\n /** The build number, like \"42\". */\n build?: string;\n /** The OS version, like \"17.4\". */\n osVersion?: string;\n /** The device model, like \"iPhone 15 Pro\" (`expo-device`). */\n deviceModel?: string;\n /** \"phone\", \"tablet\", \"desktop\" or \"tv\" when `expo-device` knows it. */\n deviceType?: string;\n /** The first preferred locale, like \"de-DE\". */\n locale?: string;\n}\n\n/** The query parameter that forces variants, for previews in Cockpit: `?ck_preview=pricing-annual:a,home-hero:control`. */\nexport const PREVIEW_PARAM = \"ck_preview\";\n/** Set when Cockpit embeds the page: nothing is tracked, so previews never count as visits. */\nexport const EMBED_PARAM = \"ck_embed\";\n/** The cookie that keeps a visitor in the same variant across visits. Only written in \"cookies\" mode. */\nexport const ID_COOKIE = \"ck_id\";\n/** The cookie that holds the session id in \"cookies\" mode. */\nexport const SESSION_COOKIE = \"ck_sid\";\n/** A session ends after this long without an event. */\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000;\n\n/** The UTM parameters from a parameter lookup (`URLSearchParams.get` in a browser). Empty values are left out. */\nexport const utmFrom = (get: (name: string) => string | null | undefined): Partial<Record<UtmKey, string>> => {\n const out: Partial<Record<UtmKey, string>> = {};\n for (const key of UTM_KEYS) {\n const value = get(key)?.trim();\n if (value) out[key] = value.slice(0, 150);\n }\n return out;\n};\n\n/** The UTM parameters of a query string, like `\"?utm_source=x\"`. Empty values are left out. */\nexport const readUtm = (search: string): Partial<Record<UtmKey, string>> => {\n const params = new URLSearchParams(search);\n return utmFrom((k) => params.get(k));\n};\n\n/**\n * The query parameters of a URL or query string, without `URLSearchParams` (React Native's is incomplete): `+` is a\n * space, values are percent-decoded, the first of a repeated name wins.\n */\nexport const parseQuery = (url: string): Record<string, string> => {\n const out: Record<string, string> = {};\n const q = url.split(\"#\")[0];\n const at = q.indexOf(\"?\");\n if (at < 0) return out;\n const dec = (s: string) => {\n try {\n return decodeURIComponent(s.replace(/\\+/g, \" \"));\n } catch {\n return s;\n }\n };\n for (const pair of q.slice(at + 1).split(\"&\")) {\n if (!pair) continue;\n const eq = pair.indexOf(\"=\");\n const k = dec(eq < 0 ? pair : pair.slice(0, eq));\n if (k && !(k in out)) out[k] = eq < 0 ? \"\" : dec(pair.slice(eq + 1));\n }\n return out;\n};\n\n/** FNV-1a, 32 bit, mapped to [0, 1). Stable across server and browser. */\nexport const hashUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0) / 4294967296;\n};\n\n/**\n * FNV-1a with murmur3's finalizer, mapped to [0, 1): ids that differ only at the end (\"user-1\", \"user-2\") still spread\n * evenly, so a 30 % rollout reaches about 30 % of people. Flags only; experiments keep `hashUnit` so nobody switches.\n */\nexport const flagUnit = (input: string) => {\n let h = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n};\n\n/** The variant a visitor sees: a shipped winner, control while the experiment does not run, else a stable bucket by visitor. */\nexport const assign = (experiment: ExperimentConfig, distinctId: string): VariantId => {\n const control = experiment.variants[0]?.id ?? \"control\";\n if (experiment.winner) return experiment.winner;\n if (experiment.status !== \"running\") return control;\n const u = hashUnit(`${experiment.key}:${distinctId}`);\n let acc = 0;\n for (const v of experiment.variants) {\n acc += v.weight;\n if (u < acc) return v.id;\n }\n return experiment.variants[experiment.variants.length - 1]?.id ?? control;\n};\n\n/** `\"a:b,c:d\"` → `{ a: \"b\", c: \"d\" }`. Ignores anything malformed. */\nexport const parsePreview = (value: string | string[] | null | undefined): Record<string, VariantId> => {\n const raw = Array.isArray(value) ? value[0] : value;\n if (!raw) return {};\n const out: Record<string, VariantId> = {};\n for (const pair of raw.split(\",\")) {\n const [key, variant] = pair.split(\":\");\n if (key && variant) out[key.trim()] = variant.trim();\n }\n return out;\n};\n\n/** A link that shows one variant of a page, for example in Cockpit's preview frames. */\nexport const previewHref = (url: string, forced: Record<string, VariantId>, embed = true) => {\n const [path, query = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(query);\n const value = Object.entries(forced)\n .map(([k, v]) => `${k}:${v}`)\n .join(\",\");\n if (value) params.set(PREVIEW_PARAM, value);\n if (embed) params.set(EMBED_PARAM, \"1\");\n return `${path}?${params.toString()}`;\n};\n\n/** The variant for one experiment, from a forced preview first, then the config. Unknown experiments get control. */\n/** The experiments whose variants change the text `id`: showing that text is an exposure to them. */\nexport const experimentsOfText = (config: CockpitConfig | null, id: string) =>\n (config?.experiments ?? []).filter((e) => e.variants.some((v) => v.changes && id in v.changes)).map((e) => e.key);\n\nexport const resolveVariant = (key: string, config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>): VariantId => {\n if (preview[key]) return preview[key];\n const experiment = config?.experiments.find((e) => e.key === key);\n return experiment ? assign(experiment, distinctId) : \"control\";\n};\n\n/**\n * Every text change that applies to this visitor: the published texts first, then each experiment's in config order.\n * Control keeps the published (or the page's own) words, so only a non-control variant (assigned, forced in a preview,\n * or a shipped winner) changes them further.\n */\nexport const textChanges = (config: CockpitConfig | null, distinctId: string, preview: Record<string, VariantId>) => {\n const out: Record<string, string> = { ...(config?.texts ?? {}) };\n for (const experiment of config?.experiments ?? []) {\n const id = resolveVariant(experiment.key, config, distinctId, preview);\n if (id === (experiment.variants[0]?.id ?? \"control\")) continue;\n Object.assign(out, experiment.variants.find((v) => v.id === id)?.changes ?? {});\n }\n return out;\n};\n\n/**\n * The query parameter a redirect test adds to the variant's address (`ck_x=<test>:<variant>`): the page there records\n * the exposure and takes it out of the address bar. It also keeps that page from redirecting again.\n */\nexport const EXPOSURE_PARAM = \"ck_x\";\n\n/** What `redirectFor` decided: go to `to`, and/or the redirect test this page belongs to and the visitor's variant. */\nexport interface RedirectDecision {\n /** Where to send the visitor now. Missing for control, which stays on the page. */\n to?: string;\n /** The redirect test, while it runs: record `$exposure` for it (on this page for control, on `to` otherwise). */\n experiment?: string;\n variant?: VariantId;\n}\n\nconst pathOf = (p: string) => p.replace(/\\/+$/, \"\") || \"/\";\n\n/**\n * Where a page sends the visitor, before it shows: a page redirect set in MRRocket first, else a redirect test that runs\n * on this path (the visitor's variant, by the same stable assignment as every test). Null when nothing applies.\n *\n * - The new address keeps the page's query (UTM parameters) and its hash; a running test adds `ck_x=<test>:<variant>`,\n * so the page it lands on records the exposure (and never redirects again).\n * - `distinctId` null (no stable id, as on a server without the `ck_id` cookie): running tests are left to the browser,\n * page redirects and shipped winners still apply.\n * - A redirect to the page itself is ignored.\n */\nexport const redirectFor = (config: CockpitConfig | null, href: string, distinctId: string | null, preview: Record<string, VariantId> = {}): RedirectDecision | null => {\n if (!config) return null;\n let here: URL;\n try {\n here = new URL(href);\n } catch {\n return null;\n }\n if (here.searchParams.has(EXPOSURE_PARAM)) return null;\n const path = pathOf(here.pathname);\n const go = (to: string, mark?: string) => {\n let t: URL;\n try {\n t = new URL(to, here);\n } catch {\n return undefined;\n }\n if (!/^https?:$/.test(t.protocol) || (t.origin === here.origin && pathOf(t.pathname) === path)) return undefined;\n here.searchParams.forEach((v, k) => {\n if (!t.searchParams.has(k)) t.searchParams.set(k, v);\n });\n if (mark) t.searchParams.set(EXPOSURE_PARAM, mark);\n if (!t.hash) t.hash = here.hash;\n return t.href;\n };\n for (const r of config.redirects ?? []) {\n const to = r.from && pathOf(r.from) === path ? go(r.to) : undefined;\n if (to) return { to };\n }\n for (const e of config.experiments) {\n if (!e.path || pathOf(e.path) !== path) continue;\n const running = e.status === \"running\" && !e.winner;\n if (running && distinctId === null && !preview[e.key]) return null;\n const variant = resolveVariant(e.key, config, distinctId ?? \"\", preview);\n const url = e.variants.find((v) => v.id === variant)?.url;\n const to = url ? go(url, running ? `${e.key}:${variant}` : undefined) : undefined;\n return running ? { to, experiment: e.key, variant } : to ? { to } : null;\n }\n return null;\n};\n\n/** The test and variant a redirect test's `ck_x` names, when the config has them; null otherwise. */\nexport const exposureFrom = (config: CockpitConfig | null, value: string | null | undefined) => {\n const [key, variant] = (value ?? \"\").split(\":\");\n const e = config?.experiments.find((x) => x.key === key);\n return e && e.variants.some((v) => v.id === variant) ? { experiment: key, variant } : null;\n};\n\n/**\n * The MRRocket API host from `NEXT_PUBLIC_MRROCKET_HOST`. Written as a literal property access on purpose: Next.js\n * inlines `process.env.NEXT_PUBLIC_*` at build time, in the browser bundle and in the server bundle (also on\n * Cloudflare Workers), and only replaces the literal form. Without a bundler (or a `process`) it is undefined.\n */\nexport const envHost = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_HOST || undefined;\n } catch {\n return undefined;\n }\n};\n\n/** The public key from `NEXT_PUBLIC_MRROCKET_KEY`, the default for the `apiKey` prop. Same literal-access rule as `envHost`. */\nexport const envKey = (): string | undefined => {\n try {\n return process.env.NEXT_PUBLIC_MRROCKET_KEY || undefined;\n } catch {\n return undefined;\n }\n};\n\n/**\n * Where the API lives: the `host` prop, else `NEXT_PUBLIC_MRROCKET_HOST`, else \"\" (the page's own origin, which is how\n * MRRocket's own demo pages call it). Without a trailing slash.\n */\nexport const resolveHost = (host?: string) => (host ?? envHost() ?? \"\").trim().replace(/\\/+$/, \"\");\n\n/** A random visitor id. */\nexport const newDistinctId = () =>\n typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `ck_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;\n"],"mappings":";AASO,IAAM,cAAc;AAyF3B,IAAM,SAAS,CAAC,QAAoB,SAAiB;AACjD,QAAM,OAAO,KAAK,KAAK,EAAE,YAAY;AACrC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,MAAM,EAAG,KAAI,EAAE,YAAY,MAAM,KAAM,QAAO;AAClF,SAAO;AACX;AAGA,IAAM,OAAO,CAAC,QAAgB,UAAkB;AAC5C,QAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,QAAM,IAAI,MAAM,KAAK,EAAE,YAAY;AACnC,SAAO,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM;AACrD;AAEA,IAAM,mBAAmB,CAAC,GAAkB,WAAuB;AAE/D,MAAI,EAAE,OAAO,YAAa,QAAO;A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AG,KAAK,IAAI,EAAE,SAAS,EAAE,CAAC;","names":[]}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Form leads (0.12.0): a form on the customer's site becomes a contact in MRRocket when it is submitted. Forms marked
3
+ * `data-mrrocket-form` (its value names the form, e.g. `data-mrrocket-form="Demo request"`) are captured; with
4
+ * auto-detection on (`data-forms="auto"` on the script tag, `forms="auto"` on the provider) also any form with an email
5
+ * field, except forms with a password field (sign-in and sign-up) and forms marked `data-mrrocket-ignore`.
6
+ *
7
+ * What is sent: the email (required), the name, and the other fields a person typed, never passwords, card fields,
8
+ * hidden fields, files or fields whose name looks sensitive (`SENSITIVE`); a field or form part marked
9
+ * `data-mrrocket-ignore` stays out too. Plus the form's name, the page, the referrer, UTM, and the state of a checkbox
10
+ * marked `data-mrrocket-consent` (the visitor's own yes to hear from the site). MRRocket records consent as the contact's
11
+ * legal basis only when that box was ticked.
12
+ *
13
+ * No React and no globals beyond the DOM, so the script tag (`sdk-forms.js`, loaded only on pages with a form to
14
+ * capture) and the Next.js provider (a dynamic import) share it. `fieldsOf` is pure for the tests.
15
+ */
16
+ /** Field names that never leave the page, whatever the form says. */
17
+ export declare const SENSITIVE: RegExp;
18
+ export declare const EMAIL_RE: RegExp;
19
+ /** Limits: what a lead may carry, also checked again by the server. */
20
+ export declare const MAX_FIELDS = 30;
21
+ export declare const MAX_VALUE = 1000;
22
+ /** One control of a form as the filter sees it. */
23
+ export interface FieldInput {
24
+ name: string;
25
+ type: string;
26
+ value: string;
27
+ autocomplete?: string;
28
+ /** A checkbox or radio that is not ticked. */
29
+ unchecked?: boolean;
30
+ /** Marked `data-mrrocket-ignore` (itself or a part of the form around it). */
31
+ ignored?: boolean;
32
+ /** Marked `data-mrrocket-consent`. */
33
+ consent?: boolean;
34
+ }
35
+ export interface FormFields {
36
+ email: string | null;
37
+ name: string | null;
38
+ /** The other fields, by name; checkbox groups joined with ", ". */
39
+ fields: Record<string, string>;
40
+ /** True or false when the form has a checkbox marked `data-mrrocket-consent`; undefined without one. */
41
+ consent?: boolean;
42
+ }
43
+ /** Whether a field's value may be sent: not a password, card, hidden or sensitive-looking field. */
44
+ export declare const sendable: (f: Pick<FieldInput, "name" | "type" | "autocomplete" | "ignored">) => boolean;
45
+ /**
46
+ * The lead in a form's controls: the email (first valid one), the name (a full-name field, or first and last), the
47
+ * consent box's state, and the other sendable fields. Pure.
48
+ */
49
+ export declare const fieldsOf: (inputs: FieldInput[]) => FormFields;
50
+ /** What the page sends to `POST /api/sdk/forms`. */
51
+ export interface FormLead extends FormFields {
52
+ key: string;
53
+ form: string;
54
+ url: string;
55
+ title?: string;
56
+ referrer?: string;
57
+ utm?: Record<string, string>;
58
+ distinctId?: string;
59
+ }
60
+ /** The form's name: the value of `data-mrrocket-form`, else its name, id or label, else "Form on /path". */
61
+ export declare const formName: (form: HTMLFormElement) => string;
62
+ /** Whether a form is captured: marked, or (auto) one with an email field and no password field. */
63
+ export declare const captures: (form: HTMLFormElement, auto: boolean) => boolean;
64
+ /** The controls of a form, read for `fieldsOf`. */
65
+ export declare const inputsOf: (form: HTMLFormElement) => FieldInput[];
66
+ export interface WatchFormsOptions {
67
+ host: string;
68
+ apiKey: string;
69
+ /** Also forms with an email field that are not marked (default false). */
70
+ auto?: boolean;
71
+ /** The visitor id to link the lead to, while analytics consent allows one. */
72
+ distinctId: () => string | undefined;
73
+ /** Whether the site already called identify(). */
74
+ identified: () => boolean;
75
+ /** Links this visitor's history to the person (the SDK's own identify). */
76
+ identify: (id: string, props: Record<string, unknown>) => void;
77
+ /** Whether analytics consent lets the SDK identify the visitor (not "off"). */
78
+ tracking: () => boolean;
79
+ referrer?: () => string | undefined;
80
+ utm?: () => Record<string, string | undefined> | undefined;
81
+ }
82
+ /**
83
+ * Captures submits from now on (one listener on the document, capture phase, so it sees forms that render later and
84
+ * forms whose own handler stops the event). The lead goes out with `sendBeacon`, which survives the page leaving. Returns
85
+ * a function that stops it. Calling it twice keeps one listener.
86
+ */
87
+ export declare const watchForms: (o: WatchFormsOptions) => (() => void);