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

Abierto
#445 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, playwright, react, typescript, vite

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
67
Forks
47
Merge medio
1 d 5 h
PR fusionados (30 d)
4

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Flagsmith/flagsmith-js-client

Todos los issues de Flagsmith/flagsmith-js-client

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.