Skip to content

2.87.0 Release - #662

Merged
jakewski merged 11 commits into
masterfrom
2.87.0-rc
Dec 2, 2026
Merged

jakewski merged 11 commits into
masterfrom
2.87.0-rc

Conversation

@jakewski

Copy link
Copy Markdown
Collaborator
  • Adds consent_mode: 'exempt' for CNIL's audience-measurement exemption. Until opt_in_tracking(), the SDK stores nothing and sends only anonymous page views, clicks, scrolls and page exits ($mp_web_page_view, $mp_click, $mp_scroll, $mp_page_leave) with a fixed set of non-identifying properties: URLs are cut to origin and path, $browser_version is truncated to the major version, time is rounded down to the hour, and each event carries $mp_exempt: true. Exempt events are sent one per request, never batched or queued, and skip before_send_events (on_track still runs, before the filter). Remote settings are fetched in this mode so they can turn on the autocapture the events come from. After an opt-in, tracking works as under 'require_consent'; opt_out_tracking() stops full tracking but leaves the visitor exempt.
  • Adds a consent_exempt_allowlist config ({events: [], properties: []}) that adds events and properties to what 'exempt' sends before consent. Anything listed is sent without consent.
  • Adds mixpanel.object_to_tracking() for the objection link in a privacy policy. It stops all tracking, exempt measurement included; opt_in_tracking() and clear_opt_in_out_tracking() lift it, opt_out_tracking() does not. Outside 'exempt' it works as opt_out_tracking(). A stored objection counts as opted out in has_opted_out_tracking(). It is included in the snippet and wrapper stubs.
  • Visual experiments: variants are now matched on the structured Target URL rule ($mp.target) when present: a main URL pattern (*, **, :name segments) or anchored regex on origin and pathname, plus optional query-param and hash rules. Variants without a target keep the origin + pathname match on $mp.url.
  • Visual experiments: targeting is re-evaluated on every navigation, including query- and hash-only changes. Navigating between pages that match the same variants no longer reverts and reapplies the changes.
  • Visual experiments: the editor preview now follows the edited experiment's target to every matching page, and still shows on the page where it was authored.
  • Visual experiments: $experiment_started now fires the same way for every variant, control included: once the page matches and one of the variant's $mp.exposureSelectors is in the DOM, or on the URL match alone when it has none. Previously control fired on URL match while treatment waited for a change to land, which could cause sample-ratio mismatch. Selector presence is judged before treatment changes apply, and missing selectors are watched for until the next navigation, delivery or reset. Visual exposures now include $matched_url (with mp_preview_token redacted).
  • Visual experiments: fixes elements the page removes and re-inserts keeping or losing a variant's changes incorrectly, and fixes setText revert pulling children the page had moved elsewhere back under the original parent.
  • Fixes identify() with a new distinct id carrying feature flag state over to the new user: activated first-time-event variants and tracked exposures carried over, so $experiment_started could be sent with a variant the new user never earned. identify() now resets flags (clearing stored variants) before refetching, and whenReady()/getVariant() called right after wait for the refetch.
  • Moves URL matching (urlMatchesRegexList and the new Target URL matcher) into a shared url-matching module.

awakebutstillinbed and others added 10 commits November 16, 2026 19:15
…le (#522)

* Visual experiments runtime: mutation engine + editor preview

Adds the SDK-side runtime for no-code visual experiments, hardened for
production from the earlier POC and aligned to the current editor wire
protocol (iron/apps/experiments/src/editor-protocol.ts).

- VisualChangeEngine (per-instance, no module singleton) applies the five
  supported mutation types (setAttribute incl. attribute:"html" -> innerHTML,
  setStyle, setClasses, setAttributes, hide) and rejects unknown types. A
  MutationObserver re-applies changes as the page re-renders using per-selector
  dirty tracking (WeakSet per mutation) rather than a full revert/reapply.
- Flag delivery reads value.$mp.{url, visualChanges} and replays a variant's
  changes only when $mp.url matches the current page by origin + pathname,
  aggregating matching variants and applying once, on both the persistence-load
  and network-fetch paths.
- Editor preview channel (mp_editor_preview postMessage) is gated on same-origin
  and a trusted __mpExtensionId allowlist (production Data Inspector extension
  id), with a 32 KB payload guard.
- Single init option visual_experiments (default false) enables both the replay
  engine and the preview listener.

Adds unit coverage for the engine (mutation types, unknown-type rejection,
revert, dirty tracking, per-instance isolation), the preview listener
(allowlist/origin gating, teardown), and flag delivery (URL scoping,
aggregation, persistence-vs-network ordering).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Added anti-flicker timeout

* Visual experiments: suppress an experiment's apply path during its editor session

While the Data Inspector extension is authoring a visual experiment, the SDK's
normal flag-delivery apply path and the live editor preview shared one engine
and fought each other. The extension now names the experiment it is authoring
via an optional experimentId on the mp_editor_preview message; on receipt the
SDK suppresses only that experiment's delivered visualChanges (matched by
experiment_id), leaving the live preview as its sole driver for the life of the
page. Other experiments keep applying normally.

Also fix the preview channel rejecting an empty mutations array: an empty set is
a valid "cleared / no mutations" state and now reverts the prior preview to
baseline instead of being dropped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Code Review

* Address Greptile P1s: same-node reapply, pre-body init, shared hide refcount

- engine: re-apply mutations to in-place re-rendered nodes (same identity)
  without duplicating undo; observe attributes/characterData too
- engine: retry observer start until <body> exists when flags settle early
- anti-flicker: reference-count the shared hide so the page stays hidden
  until the last enabled instance reveals

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Track $experiment_started with type visual for visual experiments (#501)

* Track $experiment_started for visual experiments

Visual experiment variants were applied straight from the flags map, bypassing
getVariantSync, so no exposure event was ever sent. Track $experiment_started
(with $experiment_type 'visual') for each variant whose visual changes are
actually applied on the current page, gated on visual_experiments being enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: track visual exposure on actual apply

- The engine now takes an optional onFirstApply(index) callback, fired once per
  mutation the first time it actually changes an element (including later
  observer re-applies). Flags tracks a visual exposure from that callback, so
  unmatched selectors, skipped mutations, and oversized payloads no longer count.
- Visual exposures dedupe in their own set, so an earlier code read of the same
  flag no longer swallows the visual exposure.
- The engine guards the callback so a throwing tracker can't break the apply
  loop. Drops the visualExperimentsEnabled option, now redundant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: deferred first-apply reports, reset guard

- The engine queues first-apply reports during an apply pass and delivers them
  once the pass completes, so exposure tracking (and anything a before_track
  hook does, like suppressing the experiment) never runs mid-mutation. Remaining
  reports are dropped if the callback reverts or replaces the set.
- reset() bumps a generation counter so a late first-apply from a visual set
  applied under the previous identity isn't tracked under the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Track visual exposure for variants with a url but no changes (#508)

* Track visual exposure for variants with a url but no changes

A control variant carries $mp.url but an empty visualChanges list, so the
engine never reports a first apply for it and no $experiment_started was sent.
Track it as a visual exposure as soon as its url matches the current page.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Gate control exposure on visual experiments being enabled

* Discard pending control exposures after visitor reset

* Restore existing comments outside exposure guards

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

* Support shared visual experiment previews in the SDK (#493)

* Support shared visual experiment previews in the SDK

* Use mp_preview_token for preview URLs and flags requests

* Address shared preview review feedback and add browser coverage

* Redact preview parameter values with best-effort URL sanitization

* Expose SDK_VERSION instead of preview capability method

* Simplify URL redaction with decoded query parameter names

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>

* Encapsulate visual experiment setup in flags manager

Remove the redundant anti-flicker browser check and wrap the visual engine and anti-flicker controller with safewrapClass. Preserve the public experiments API and verify page reveal when flag delivery is disabled, empty, or fails.

* Preserve visual previews and DOM state during replay

Compose editor previews with unrelated live experiments, restore original child nodes when reverting text edits, and pause mutation observation during engine writes. Cover control previews, refreshes, navigation, exposure tracking, and replay-loop regressions.

* Fix shared preview integration test cleanup

* Clarify visual experiment delivery setup and expose tunnel errors

* Bound integration jobs and cancel superseded browser runs

* Keep CI configuration unchanged in visual experiments PR

* address greptile comments

* Split visual experiments out of the flags manager

Move the visual delivery, editor session, and anti-flicker wiring into a
VisualExperimentsManager under src/visual-experiments. Flags now only calls
onFlagsDelivered, onDeliverySettled, and onReset on it, and the manager calls
back into flags for the current variants and for exposure tracking.

Also address the review cleanups: rename experiment-mutations to
visual-experiments, name the engine capability check minApisSupported, size
the payload limit in characters, move the navigation event constants into
utils so navigation no longer imports from autocapture, drop the protocol
types that referenced the analytics repo, and remove a stray history comment.

Tests are split into a manager suite, a flags-to-manager delivery suite, and
the mixpanel.experiments end-to-end suite.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Report exposures for flags named after object prototype keys

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Add browser tests for visual experiments

Covers anti-flicker hide and reveal, every mutation type with revert,
observer re-application, SPA navigation and editor sessions against a
real DOM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [MULTI-1255] Add the structured Target URL matcher for visual experiments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Run the shared Target URL vectors against the SDK matcher

Vectors copied verbatim from the monorepo at f227de0eb428
(iron/apps/experiments/src/components/utils/visual-url-target-vectors.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Match visual-experiment variants on $mp.target, falling back to $mp.url

A variant with a Target URL rule is matched by urlTargetMatches; one without
keeps the alpha origin + path match on $mp.url. Preview-token variants are
delivered through the same onFlagsDelivered path, so they use the same
matcher. While any delivered variant has a target, SPA replay dedupes on the
query string and hash as well, since the rule can match on them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Re-import the URL target matcher with each visual experiments test window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Move URL matching into a shared top-level module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the visual changes payload limit per variant and re-run dependent selectors

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Pass a consent gate to the flag manager in visual experiments tests

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Clear visual changes on reset and re-deliver after first-time event activation

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Remove internal monorepo references from URL matching docs and vectors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add JSDoc typedefs for the Target URL rule and annotate url-matching.js

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Carlos Trevino <35301701+carlosdanieltt@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Jakub Grzegorzewski <jakewski@gmail.com>
Co-authored-by: Carlos Trevino <carlosdanieltt@gmail.com>
Co-authored-by: alexrmeyer <alex.meyer@mixpanel.com>
Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Elliot Feinberg <5232369+elliotrfeinberg@users.noreply.github.com>
Co-authored-by: TAL <tal@mixpanel.com>
… the editor preview follow the target (#524)

* Visual experiments runtime: mutation engine + editor preview

Adds the SDK-side runtime for no-code visual experiments, hardened for
production from the earlier POC and aligned to the current editor wire
protocol (iron/apps/experiments/src/editor-protocol.ts).

- VisualChangeEngine (per-instance, no module singleton) applies the five
  supported mutation types (setAttribute incl. attribute:"html" -> innerHTML,
  setStyle, setClasses, setAttributes, hide) and rejects unknown types. A
  MutationObserver re-applies changes as the page re-renders using per-selector
  dirty tracking (WeakSet per mutation) rather than a full revert/reapply.
- Flag delivery reads value.$mp.{url, visualChanges} and replays a variant's
  changes only when $mp.url matches the current page by origin + pathname,
  aggregating matching variants and applying once, on both the persistence-load
  and network-fetch paths.
- Editor preview channel (mp_editor_preview postMessage) is gated on same-origin
  and a trusted __mpExtensionId allowlist (production Data Inspector extension
  id), with a 32 KB payload guard.
- Single init option visual_experiments (default false) enables both the replay
  engine and the preview listener.

Adds unit coverage for the engine (mutation types, unknown-type rejection,
revert, dirty tracking, per-instance isolation), the preview listener
(allowlist/origin gating, teardown), and flag delivery (URL scoping,
aggregation, persistence-vs-network ordering).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Added anti-flicker timeout

* Visual experiments: suppress an experiment's apply path during its editor session

While the Data Inspector extension is authoring a visual experiment, the SDK's
normal flag-delivery apply path and the live editor preview shared one engine
and fought each other. The extension now names the experiment it is authoring
via an optional experimentId on the mp_editor_preview message; on receipt the
SDK suppresses only that experiment's delivered visualChanges (matched by
experiment_id), leaving the live preview as its sole driver for the life of the
page. Other experiments keep applying normally.

Also fix the preview channel rejecting an empty mutations array: an empty set is
a valid "cleared / no mutations" state and now reverts the prior preview to
baseline instead of being dropped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Code Review

* Address Greptile P1s: same-node reapply, pre-body init, shared hide refcount

- engine: re-apply mutations to in-place re-rendered nodes (same identity)
  without duplicating undo; observe attributes/characterData too
- engine: retry observer start until <body> exists when flags settle early
- anti-flicker: reference-count the shared hide so the page stays hidden
  until the last enabled instance reveals

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Track $experiment_started with type visual for visual experiments (#501)

* Track $experiment_started for visual experiments

Visual experiment variants were applied straight from the flags map, bypassing
getVariantSync, so no exposure event was ever sent. Track $experiment_started
(with $experiment_type 'visual') for each variant whose visual changes are
actually applied on the current page, gated on visual_experiments being enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: track visual exposure on actual apply

- The engine now takes an optional onFirstApply(index) callback, fired once per
  mutation the first time it actually changes an element (including later
  observer re-applies). Flags tracks a visual exposure from that callback, so
  unmatched selectors, skipped mutations, and oversized payloads no longer count.
- Visual exposures dedupe in their own set, so an earlier code read of the same
  flag no longer swallows the visual exposure.
- The engine guards the callback so a throwing tracker can't break the apply
  loop. Drops the visualExperimentsEnabled option, now redundant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: deferred first-apply reports, reset guard

- The engine queues first-apply reports during an apply pass and delivers them
  once the pass completes, so exposure tracking (and anything a before_track
  hook does, like suppressing the experiment) never runs mid-mutation. Remaining
  reports are dropped if the callback reverts or replaces the set.
- reset() bumps a generation counter so a late first-apply from a visual set
  applied under the previous identity isn't tracked under the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Track visual exposure for variants with a url but no changes (#508)

* Track visual exposure for variants with a url but no changes

A control variant carries $mp.url but an empty visualChanges list, so the
engine never reports a first apply for it and no $experiment_started was sent.
Track it as a visual exposure as soon as its url matches the current page.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Gate control exposure on visual experiments being enabled

* Discard pending control exposures after visitor reset

* Restore existing comments outside exposure guards

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

* Support shared visual experiment previews in the SDK (#493)

* Support shared visual experiment previews in the SDK

* Use mp_preview_token for preview URLs and flags requests

* Address shared preview review feedback and add browser coverage

* Redact preview parameter values with best-effort URL sanitization

* Expose SDK_VERSION instead of preview capability method

* Simplify URL redaction with decoded query parameter names

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>

* Encapsulate visual experiment setup in flags manager

Remove the redundant anti-flicker browser check and wrap the visual engine and anti-flicker controller with safewrapClass. Preserve the public experiments API and verify page reveal when flag delivery is disabled, empty, or fails.

* Preserve visual previews and DOM state during replay

Compose editor previews with unrelated live experiments, restore original child nodes when reverting text edits, and pause mutation observation during engine writes. Cover control previews, refreshes, navigation, exposure tracking, and replay-loop regressions.

* Fix shared preview integration test cleanup

* Clarify visual experiment delivery setup and expose tunnel errors

* Bound integration jobs and cancel superseded browser runs

* Keep CI configuration unchanged in visual experiments PR

* address greptile comments

* Split visual experiments out of the flags manager

Move the visual delivery, editor session, and anti-flicker wiring into a
VisualExperimentsManager under src/visual-experiments. Flags now only calls
onFlagsDelivered, onDeliverySettled, and onReset on it, and the manager calls
back into flags for the current variants and for exposure tracking.

Also address the review cleanups: rename experiment-mutations to
visual-experiments, name the engine capability check minApisSupported, size
the payload limit in characters, move the navigation event constants into
utils so navigation no longer imports from autocapture, drop the protocol
types that referenced the analytics repo, and remove a stray history comment.

Tests are split into a manager suite, a flags-to-manager delivery suite, and
the mixpanel.experiments end-to-end suite.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Report exposures for flags named after object prototype keys

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Add browser tests for visual experiments

Covers anti-flicker hide and reveal, every mutation type with revert,
observer re-application, SPA navigation and editor sessions against a
real DOM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [MULTI-1255] Add the structured Target URL matcher for visual experiments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Run the shared Target URL vectors against the SDK matcher

Vectors copied verbatim from the monorepo at f227de0eb428
(iron/apps/experiments/src/components/utils/visual-url-target-vectors.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Match visual-experiment variants on $mp.target, falling back to $mp.url

A variant with a Target URL rule is matched by urlTargetMatches; one without
keeps the alpha origin + path match on $mp.url. Preview-token variants are
delivered through the same onFlagsDelivered path, so they use the same
matcher. While any delivered variant has a target, SPA replay dedupes on the
query string and hash as well, since the rule can match on them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Re-import the URL target matcher with each visual experiments test window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Re-evaluate visual targeting on every navigation, deduped on the matched-variant set

Replaces the page-URL replay key with a key over the sorted set of matched
variants (flag key + variant key) plus whether the editor preview applies,
so query- and hash-only navigations re-run matching and a path change under
the same pattern does not revert and reapply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Let the editor preview follow the edited experiment's target

The preview applies on any page a delivered variant of the edited
experiment matches ($mp.target, or $mp.url without one) and reverts on
other pages. Without a delivered variant to take the target from it stays
on the page where it was authored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Keep the editor preview on its authoring page as well as its target

A preview authored on a page outside the delivered variant's target (for
example while the target itself is being edited) still shows there, and it
also follows the experiment's target to every matching page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Drop undo entries for detached elements on each observer pass

Navigating under one URL pattern keeps the applied set, so the engine's
undo stack was only cleared by a full apply or revert. Each undo entry
now records its element, and _reapplyDirty prunes entries whose element
is no longer attached before re-applying to new nodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Restore detached elements before dropping their undo

A detached element can still come back: a parent's setText undo re-attaches
the children it saved, and pages can re-insert removed nodes. Pruning their
undo entries left those nodes carrying the variant after a revert. Run each
detached entry's undo before dropping it, and forget the element in the
applied sets so a re-inserted node is applied and recorded afresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Keep page-moved children in place when pruning setText undo

Pruning a detached setText element ran its undo, which re-appended every
saved child, including ones the page had moved into the live document. Those
children vanished while the experiment was active. Pruning now leaves
attached saved children where they are; a full revert is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1256] Leave page-moved children in place on setText revert

A full revert no longer pulls an original child back under its setText
parent if the page has since moved it elsewhere in the live document.
Children that are still detached are restored as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Move URL matching into a shared top-level module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the visual changes payload limit per variant and re-run dependent selectors

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Pass a consent gate to the flag manager in visual experiments tests

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Clear visual changes on reset and re-deliver after first-time event activation

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [MULTI-1256] Record the matched-set key before exposure callbacks and reuse the navigation match

A before_track hook can navigate while trackExposure runs; the nested apply's
key was then overwritten by the outer call's, so returning to the first page
hit the dedup and left the second page's changes applied. applyForCurrentPage
also passes its match result into _applyForFlags instead of matching twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove internal monorepo references from URL matching docs and vectors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add JSDoc typedefs for the Target URL rule and annotate url-matching.js

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Carlos Trevino <35301701+carlosdanieltt@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Jakub Grzegorzewski <jakewski@gmail.com>
Co-authored-by: Carlos Trevino <carlosdanieltt@gmail.com>
Co-authored-by: alexrmeyer <alex.meyer@mixpanel.com>
Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Elliot Feinberg <5232369+elliotrfeinberg@users.noreply.github.com>
Co-authored-by: TAL <tal@mixpanel.com>
…ch and selector presence (#525)

* Visual experiments runtime: mutation engine + editor preview

Adds the SDK-side runtime for no-code visual experiments, hardened for
production from the earlier POC and aligned to the current editor wire
protocol (iron/apps/experiments/src/editor-protocol.ts).

- VisualChangeEngine (per-instance, no module singleton) applies the five
  supported mutation types (setAttribute incl. attribute:"html" -> innerHTML,
  setStyle, setClasses, setAttributes, hide) and rejects unknown types. A
  MutationObserver re-applies changes as the page re-renders using per-selector
  dirty tracking (WeakSet per mutation) rather than a full revert/reapply.
- Flag delivery reads value.$mp.{url, visualChanges} and replays a variant's
  changes only when $mp.url matches the current page by origin + pathname,
  aggregating matching variants and applying once, on both the persistence-load
  and network-fetch paths.
- Editor preview channel (mp_editor_preview postMessage) is gated on same-origin
  and a trusted __mpExtensionId allowlist (production Data Inspector extension
  id), with a 32 KB payload guard.
- Single init option visual_experiments (default false) enables both the replay
  engine and the preview listener.

Adds unit coverage for the engine (mutation types, unknown-type rejection,
revert, dirty tracking, per-instance isolation), the preview listener
(allowlist/origin gating, teardown), and flag delivery (URL scoping,
aggregation, persistence-vs-network ordering).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Added anti-flicker timeout

* Visual experiments: suppress an experiment's apply path during its editor session

While the Data Inspector extension is authoring a visual experiment, the SDK's
normal flag-delivery apply path and the live editor preview shared one engine
and fought each other. The extension now names the experiment it is authoring
via an optional experimentId on the mp_editor_preview message; on receipt the
SDK suppresses only that experiment's delivered visualChanges (matched by
experiment_id), leaving the live preview as its sole driver for the life of the
page. Other experiments keep applying normally.

Also fix the preview channel rejecting an empty mutations array: an empty set is
a valid "cleared / no mutations" state and now reverts the prior preview to
baseline instead of being dropped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Code Review

* Address Greptile P1s: same-node reapply, pre-body init, shared hide refcount

- engine: re-apply mutations to in-place re-rendered nodes (same identity)
  without duplicating undo; observe attributes/characterData too
- engine: retry observer start until <body> exists when flags settle early
- anti-flicker: reference-count the shared hide so the page stays hidden
  until the last enabled instance reveals

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Track $experiment_started with type visual for visual experiments (#501)

* Track $experiment_started for visual experiments

Visual experiment variants were applied straight from the flags map, bypassing
getVariantSync, so no exposure event was ever sent. Track $experiment_started
(with $experiment_type 'visual') for each variant whose visual changes are
actually applied on the current page, gated on visual_experiments being enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: track visual exposure on actual apply

- The engine now takes an optional onFirstApply(index) callback, fired once per
  mutation the first time it actually changes an element (including later
  observer re-applies). Flags tracks a visual exposure from that callback, so
  unmatched selectors, skipped mutations, and oversized payloads no longer count.
- Visual exposures dedupe in their own set, so an earlier code read of the same
  flag no longer swallows the visual exposure.
- The engine guards the callback so a throwing tracker can't break the apply
  loop. Drops the visualExperimentsEnabled option, now redundant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Address Greptile P1s: deferred first-apply reports, reset guard

- The engine queues first-apply reports during an apply pass and delivers them
  once the pass completes, so exposure tracking (and anything a before_track
  hook does, like suppressing the experiment) never runs mid-mutation. Remaining
  reports are dropped if the callback reverts or replaces the set.
- reset() bumps a generation counter so a late first-apply from a visual set
  applied under the previous identity isn't tracked under the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Track visual exposure for variants with a url but no changes (#508)

* Track visual exposure for variants with a url but no changes

A control variant carries $mp.url but an empty visualChanges list, so the
engine never reports a first apply for it and no $experiment_started was sent.
Track it as a visual exposure as soon as its url matches the current page.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Gate control exposure on visual experiments being enabled

* Discard pending control exposures after visitor reset

* Restore existing comments outside exposure guards

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

* Support shared visual experiment previews in the SDK (#493)

* Support shared visual experiment previews in the SDK

* Use mp_preview_token for preview URLs and flags requests

* Address shared preview review feedback and add browser coverage

* Redact preview parameter values with best-effort URL sanitization

* Expose SDK_VERSION instead of preview capability method

* Simplify URL redaction with decoded query parameter names

---------

Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>

* Encapsulate visual experiment setup in flags manager

Remove the redundant anti-flicker browser check and wrap the visual engine and anti-flicker controller with safewrapClass. Preserve the public experiments API and verify page reveal when flag delivery is disabled, empty, or fails.

* Preserve visual previews and DOM state during replay

Compose editor previews with unrelated live experiments, restore original child nodes when reverting text edits, and pause mutation observation during engine writes. Cover control previews, refreshes, navigation, exposure tracking, and replay-loop regressions.

* Fix shared preview integration test cleanup

* Clarify visual experiment delivery setup and expose tunnel errors

* Bound integration jobs and cancel superseded browser runs

* Keep CI configuration unchanged in visual experiments PR

* address greptile comments

* Split visual experiments out of the flags manager

Move the visual delivery, editor session, and anti-flicker wiring into a
VisualExperimentsManager under src/visual-experiments. Flags now only calls
onFlagsDelivered, onDeliverySettled, and onReset on it, and the manager calls
back into flags for the current variants and for exposure tracking.

Also address the review cleanups: rename experiment-mutations to
visual-experiments, name the engine capability check minApisSupported, size
the payload limit in characters, move the navigation event constants into
utils so navigation no longer imports from autocapture, drop the protocol
types that referenced the analytics repo, and remove a stray history comment.

Tests are split into a manager suite, a flags-to-manager delivery suite, and
the mixpanel.experiments end-to-end suite.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Report exposures for flags named after object prototype keys

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Add browser tests for visual experiments

Covers anti-flicker hide and reveal, every mutation type with revert,
observer re-application, SPA navigation and editor sessions against a
real DOM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [MULTI-1255] Add the structured Target URL matcher for visual experiments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Run the shared Target URL vectors against the SDK matcher

Vectors copied verbatim from the monorepo at f227de0eb428
(iron/apps/experiments/src/components/utils/visual-url-target-vectors.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1255] Match visual-experiment variants on $mp.target, falling back to $mp.url

A variant with a Target URL rule is matched by urlTargetMatches; one without
keeps the alpha origin + path match on $mp.url. Preview-token variants are
delivered through the same onFlagsDelivered path, so they use the same
matcher. While any delivered variant has a target, SPA replay dedupes on the
query string and hash as well, since the rule can match on them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Re-import the URL target matcher with each visual experiments test window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1257] Expose both visual-experiment arms on URL match and exposure-selector presence

Control fired $experiment_started on URL match while treatment waited for the
engine to report a changed element, so pages without that element counted
control visitors and dropped treatment ones (SRM). Every matching variant now
reports once its page matches and one of $mp.exposureSelectors is in the DOM,
or on URL match alone when it has none. A missing selector is waited for with a
MutationObserver, torn down on re-apply (navigation, delivery, editor revert)
and on reset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1257] Add the matched page url to visual $experiment_started as $matched_url

The visual-experiments module reports a copy of the variant carrying
'matched_url' (location.href when the set was matched, so a selector that
renders later still reports the page it matched on). trackFeatureCheck maps it
to $matched_url; code-read exposures never carry it. The variant copy is the
pass-through because mixpanel-core's trackExposureFunc forwards only
(flagKey, variant).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1257] Redact the preview token from the visual exposure $matched_url

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1257] Judge exposure selectors on the page before treatment changes apply

Selector presence is checked before the engine applies the set, so a
treatment that removes a selector's class or attribute is still counted
like its control. Only variants with no selector present wait on the
watcher's MutationObserver, whose microtask callback runs before the
engine's animation-frame re-apply touches a late-arriving element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [MULTI-1257] Register pending exposure watches before reporting present variants

A tracking hook that runs while reporting one variant's exposure can insert
another variant's selector. The watcher's observer starts on the first
watch(), so a variant registered after that insertion never saw it. Register
every pending watch first, then report the variants already present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Move URL matching into a shared top-level module

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the visual changes payload limit per variant and re-run dependent selectors

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Pass a consent gate to the flag manager in visual experiments tests

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Clear visual changes on reset and re-deliver after first-time event activation

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Check exposure selectors against the page before the previous set's changes

When a delivery replaces an applied set and some variant has exposure
selectors, revert the previous set before the presence check, then apply the
new set in the same task. A treatment re-delivered after a cached apply that
removed the selector's class, and a control replacing that treatment, now both
report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove internal monorepo references from URL matching docs and vectors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add JSDoc typedefs for the Target URL rule and annotate url-matching.js

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Drop an apply's remaining exposures once a re-apply replaces it

Every apply takes a new generation, so a tracking hook that navigates (or
otherwise re-applies) stops the outer loop from reporting the replaced
set's variants and from overwriting the replay state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove unused first-apply reporting hooks from visual-changes engine

index.js no longer passes onFirstApply, so _onFirstApply, _firstApplyReported,
_pendingFirstApply, _queueFirstApply, _flushFirstApply and the onFirstApply
parameter of applyVisualChanges had no production caller. Drop them and the
tests that exercised the callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Carlos Trevino <35301701+carlosdanieltt@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Jakub Grzegorzewski <jakewski@gmail.com>
Co-authored-by: Carlos Trevino <carlosdanieltt@gmail.com>
Co-authored-by: alexrmeyer <alex.meyer@mixpanel.com>
Co-authored-by: no value <283800250+alexrmeyer@users.noreply.github.com>
Co-authored-by: Elliot Feinberg <5232369+elliotrfeinberg@users.noreply.github.com>
Co-authored-by: TAL <tal@mixpanel.com>
* Reset feature flags when identify changes the distinct id

identify only refetched flags, so activated first-time-event variants
carried over to the new user and $experiment_started was sent for them
with a variant they never earned. Reset the flag manager instead, which
clears flags, tracked features, pending and activated first-time events
and stored variants before refetching.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Expose the reset refetch to flag readers immediately

reset() cleared fetchPromise and only started fetching after the
persistence clear finished, so whenReady() and getVariant() called right
after identify() resolved early or returned the fallback. Set
fetchPromise to the clear-then-fetch chain up front.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@jakewski
jakewski requested review from a team and rahul-mixpanel November 24, 2026 14:44
Comment thread CHANGELOG.md Outdated
@@ -1,3 +1,16 @@
**2.87.0** (23 Nov 2026)

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.

Suggested change
**2.87.0** (23 Nov 2026)
**2.87.0** (30 Nov 2026)

@jakewski
jakewski merged commit bfcc779 into master Dec 2, 2026
29 of 30 checks passed
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.

5 participants