Repository navigation
fix(analytics): fold deco flag names into experiment keys the collector keeps - #841
thaisrocine wants to merge 2 commits into
Conversation
…or keeps A deco_segment flag name is the matcher's block name in the CMS, such as TestePLPIA, and the adapter passed it to setExperiment raw. The collector only keeps keys matching [a-z0-9][a-z0-9_-]*, so every capitalised matcher lost its arm on every event. The adapter now strips accents, lower-cases and maps anything else to "_"; valid keys are unchanged. Mirrors decocms/analytics, whose runtime/ is what production serves until it builds from this package. build-tag --check --src passes against this copy, so both build to the same bytes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
hugo-ccabral
left a comment
There was a problem hiding this comment.
Verdict: COMMENT - the fold is correct for the cookie path, but it now disagrees with the other setExperiment caller, which breaks the "page arm wins" rule in client.ts.
Blocking
runtime/modules/deco.ts:51: only the v7 cookie path is folded.client.ts:114/:150still pass v8experimentsnames raw, andclient.ts:148-150depends on both paths writing the same key so the arm the page rendered overwrites the stale v7 one. They no longer match. Trigger: a v8 site callsstartAnalytics({ modules: ["deco"], experiments: { TestePLPIA: false } })for a visitor who still has a v7deco_segmentwithactive: ["TestePLPIA"].cfg.xends up as{ testeplpia: "on", TestePLPIA: "off" }. The Worker dropsTestePLPIA(EXP_OK,shared/contract.ts:410) and storestesteplpia=on, so the event is attributed to treatment while the page showed control. Before this PR that event had no arm. Now it has the wrong one. → fix here: movekeyintoshared/contract.tsand apply it in one place every caller goes through: coresetExperiment/variant(runtime/src/index.ts:349-352), or at leastarmsOfas well.
Worth fixing
runtime/modules/deco.ts:41: different names can fold to the same key without any warning.TestePLPIA/testeplpiacollide, and so doPromo Natal/promo_natal.inactiveDrawnis written afteractive, so one experiment'soffcan overwrite another'son. Before, the Worker at least raisedexp.charset. Now nothing does, which goes against the contract's own rule that normalising should not be silent. → file an issue- Pre-existing: nested v8 tests (
plp-optimizer/b, the documented test-within-a-test) contain/, soEXP_OKrejects them and their arm is never stored. Folding in coresetExperiment(above) fixes this too. → file an issue
Checked, fine
The expKeyLen check runs on the folded key. Names that fold to empty (all non-Latin, all punctuation) are skipped. Keys that were already valid pass through unchanged, so existing data keeps its keys. Before this PR, invalid names were dropped entirely, so no history is split. The cookie parse is still inside try. CI is green.
| const set = (name: string, variant: string) => { | ||
| // Experiment keys allow hyphens; anything else the Worker normalises and flags. | ||
| if (name && name.length <= LIMITS.expKeyLen) setExperiment?.(name, variant); | ||
| const k = key(name); |
There was a problem hiding this comment.
fix here. This is the only caller that folds. client.ts:150 writes the v8 page's arms raw after this module loads, and that overwrite is how "the arm the page rendered wins". Once the keys differ, the overwrite no longer happens.
Trigger: startAnalytics({ modules: ["deco"], experiments: { TestePLPIA: false } }) for a visitor with a leftover v7 deco_segment of active: ["TestePLPIA"] gives cfg.x = { testeplpia: "on", TestePLPIA: "off" }. The Worker drops the raw key (EXP_OK) and records testeplpia=on, so the visitor is counted as treatment after being shown control. Before this PR that event had no arm. Now it has the wrong one.
Suggest: move this fold into shared/contract.ts and apply it in core setExperiment/variant (runtime/src/index.ts:349-352). Every caller goes through those (this module, armsOf, a site's own __dq.setExperiment), so one place covers them all. It would also stop the Worker dropping nested plp-optimizer/b keys, which contain /.
| .normalize("NFD") | ||
| .replace(/[\u0300-\u036f]/g, "") | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9_-]+/g, "_") |
There was a problem hiding this comment.
file an issue. This fold maps many names to one key, and nothing reports it: TestePLPIA/testeplpia and Promo Natal/promo_natal each end up the same. set runs over active first and then inactiveDrawn, so experiment B's off silently overwrites experiment A's on on every event. The Worker used to flag these as exp.charset, and the contract itself says normalising should not be silent. Cheap guard: if a folded key is already in cfg.x from a different raw name, skip it (or flag it) instead of overwriting.
… in the deco module Review of #841: only the v7 cookie path was folded, so a v8 page's own arm (`TestePLPIA: false`) and the deco module's arm (`testeplpia: on`) landed on different keys. The page's arm could no longer overwrite the stale v7 one, and the event was attributed to treatment while the page showed control. - `expKey` moves to `shared/contract.ts` and runs in core's `setExperiment`/`variant`. `armsOf` keys the pre-boot `x` the same way. Nested tests (`plp/b`) now travel as `plp_b` instead of being dropped by the collector. - The deco module keeps the first of two names that fold to one key. - The storefront side is written before the segment, ahead of the collector's 8-entry `exp` budget. Same source as decocms/analytics#69: `build-tag.mjs --check --src` matches its lock for all ten bundles. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Why
A
deco_segmentflag name is the matcher's block name in the CMS (TestePLPIA), and the deco adapter passed it tosetExperimentraw. The collector keeps only experiment keys matching[a-z0-9][a-z0-9_-]*, so every capitalised matcher lost its arm on every event. Monte Carlo runs all of its PLP tests underTestePLPIA.What changes
src/v8/analytics/runtime/modules/deco.ts: the adapter folds a flag name into a valid key: accents off, lower case, anything else to_. Valid keys pass through unchanged.This mirrors decocms/analytics#69. Until decocms/analytics builds the tag from this package (task 3.7), its own
runtime/is what production serves, so both copies have to change together.node ops/build-tag.mjs --check --src <this>/packages/blocks/src/v8/analyticspasses against this branch: both copies build to the same ten bundles.Test
The behaviour is asserted end to end in decocms/analytics (
tests/browser.spec.ts). Here:vitest run packages/blocks/src/v8/analytics(48 passed) andbiome checkare clean.🤖 Generated with Claude Code
Summary by cubic
Fixes deco experiment tracking so matcher flag names like
TestePLPIAno longer get dropped by the collector.The collector keeps only experiment keys matching
[a-z0-9][a-z0-9_-]*, so every capitalised matcher lost its arm on every event. Names are now folded into valid keys — accents stripped, lower-cased, everything else to_— while already-valid keys pass through unchanged. The fold runs in coresetExperiment/variantand the pre-bootx, so a page's own arm and the deco module's arm land on the same key. Nested tests (plp/b) now travel asplp_binstead of being dropped, and the deco module keeps the first of two names that fold to one key.Migration
decocms/analytics; both copies must land together because production servesdecocms/analytics' runtime until it builds from this package.build-tag --checkpasses against this branch, so both copies build to the same bundles.Written for commit 9adb904. Summary will update on new commits.