Skip to content

feat(server): send layerId with experiment exposures - #223

Merged
feugy merged 3 commits into
canaryfrom
feat/exposure-layer-id
Dec 3, 2026
Merged

feugy merged 3 commits into
canaryfrom
feat/exposure-layer-id

Conversation

@dferber90

Copy link
Copy Markdown

trackExposure now accepts an optional layerId and sends it in the exposure data, so exposures from layered experiments can be analyzed per layer.

Why

@vercel/flags-core (since 1.12.0) attaches layerId to the exposures it reports for experiments that run in a layer. trackExposure builds the ed payload from a fixed list of fields, so the layer id was dropped before it reached Web Analytics.

The same flags-core release added the not-in-layer assignment reason, which ExposureAssignmentReason didn't list. Callers had to cast to pass it through.

Approach

  • Add layerId?: string to ExposureInput and include it in ed when it's defined, the same way rampId and rampPercentage are handled. When it's left out, the payload is unchanged.
  • Add 'not-in-layer' to ExposureAssignmentReason. This only changes the type; the reason was already sent unchanged at runtime.

Validation

  • Added a test that posts an exposure with layerId: 'layer_a' and assignmentReason: 'not-in-layer' and checks both values are in ed.
  • vitest run src/server/experiments.test.ts: 22/22 pass.
  • biome check packages/web/src/server: clean.

Relevant context

The exposure ingestion endpoint has to keep (or start storing) ed.layerId for the value to show up in queries.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
analytics-astro Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-next15 Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-nextjs Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-nuxt Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-remix Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-sveltekit Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-sveltekit-old Ready Ready Preview Dec 3, 2026 10:29am UTC
analytics-vue Ready Ready Preview Dec 3, 2026 10:29am UTC

Request Review

The production e2e tests proxy the live va.vercel-scripts.com/v1/script.js, which no longer sends a client timestamp (ts) in pageview payloads.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>

@feugy feugy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for this PR.

For the record, it also removes outdated test expectations on the ts field which the ingestion overrides already.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
@feugy
feugy merged commit 70d1fa7 into canary Dec 3, 2026
16 checks passed
@feugy
feugy deleted the feat/exposure-layer-id branch December 3, 2026 10:31

This branch was successfully deployed

8 active deployments
Preview – analytics-nextjs — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-nuxt — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-sveltekit — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-vue — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-astro — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-next15 — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-remix — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Preview – analytics-sveltekit-old — a2900989 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants