Experiment events are lost when a visitor leaves within flushInterval (no flush on pagehide)

Aperta
#445 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, playwright, react, typescript, vite

Direzione di ricerca

Start by locating the event processor and its flush interval behavior; the issue does not name source files or tests. Reproduce the reported short-visit case in the Playwright browser setup, then inspect how page lifecycle events and event delivery are handled. Done means exposures and conversions are delivered when a visitor leaves before the interval, with regression coverage for that case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: @flagsmith/flagsmith 12.6.0 (latest), browser, Experimentation with enableEvents: true.

What happens: the event processor buffers exposures and trackEvent calls and sends them every flushInterval (default 1e4, 10 seconds). Nothing flushes the buffer when the page is hidden or closed: there is no pagehide / visibilitychange handler, and the request doesn't use keepalive or navigator.sendBeacon. A visitor who leaves within 10 seconds never reaches the experiment, and neither does a conversion made just before leaving.

How we saw it: we ran 40 scripted browser visits (Playwright, real Chromium) through an experiment on a React + Vite app wired with FlagsmithProvider, getExperimentFlag and trackEvent. Each visit lasted 3–6 seconds.

Visits Exposures recorded
3–6 s, default flushInterval 0 of 40
11 s, default flushInterval 40 of 40
3–6 s, eventProcessorConfig: { flushInterval: 1000 } 40 of 40

Same app, same build, same Flagsmith instance; only the visit length or the interval changed. The app also called flagsmith.flushEvents() from a pagehide listener; with visits that end by closing the page, that didn't deliver the events either.

Why it matters for experiments: if one variant makes people leave sooner, that arm loses more exposures and conversions than the other, so the result is biased, and the sample ratio may still look fine.

Suggestion: flush on pagehide (and visibilitychange to hidden) with fetch(url, { keepalive: true, ... }) or navigator.sendBeacon, and consider a shorter default interval for experiment exposures. Until then, a line about flushInterval in the Experimentation docs and the coding-agent set-up prompt would save people from this.

Lingua principale
TypeScript
Stelle
67
Fork
47
Merge medio
1g 5h
PR unite (30g)
4

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Flagsmith/flagsmith-js-client

Tutte le issue di Flagsmith/flagsmith-js-client

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.