feat(analytics-controller): add optional pre-consent event queue#9252
feat(analytics-controller): add optional pre-consent event queue#9252gauthierpetetin wants to merge 3 commits into
Conversation
Add an opt-in pre-consent event queue to AnalyticsController, gated by the new isPreConsentQueueEnabled option (disabled by default). Track events received while the user is undecided are persisted and replayed on opt-in, or discarded on opt-out. Adds a consentDecisionMade state field, a selectConsentDecisionMade selector, and a resetConsentDecision action. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b05a866. Configure here.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “pre-consent” track-event queue to AnalyticsController, allowing clients to persist track events while the user is undecided and then replay them on opt-in (or discard on opt-out), gated behind a new isPreConsentQueueEnabled option (default off).
Changes:
- Introduces
consentDecisionMadeandpreConsentEventQueuecontroller state, with metadata and reconciliation/replay/clear logic. - Adds
resetConsentDecisionto the controller API/messenger actions, plus a newselectConsentDecisionMadeselector. - Extends the Jest test suite and updates the package changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/analytics-controller/src/selectors.ts | Adds selectConsentDecisionMade selector for distinguishing undecided vs explicit opt-out. |
| packages/analytics-controller/src/index.ts | Exports the new AnalyticsControllerResetConsentDecisionAction type. |
| packages/analytics-controller/src/AnalyticsController.ts | Adds pre-consent queue state/metadata, feature flag, queueing/replay/cleanup logic, and resetConsentDecision. |
| packages/analytics-controller/src/AnalyticsController.test.ts | Adds/updates tests for consentDecisionMade, pre-consent queue behavior, and the new selector. |
| packages/analytics-controller/src/AnalyticsController-method-action-types.ts | Adds resetConsentDecision method action type and includes it in the union. |
| packages/analytics-controller/CHANGELOG.md | Documents the new optional pre-consent queue feature. |
Comments suppressed due to low confidence (1)
packages/analytics-controller/src/AnalyticsController.ts:421
initialStateis built by spreadinggetDefaultAnalyticsControllerState()(which setsconsentDecisionMade: false) over the providedstate. For persisted states from beforeconsentDecisionMadeexisted, this forcesconsentDecisionMadetofalse("undecided"). If a client later enablesisPreConsentQueueEnabled, users who previously had onlyoptedIn: falsewill start persisting pre-consent events, which is a backward-compatibility behavior change and may conflict with prior opt-out expectations. Consider defaultingconsentDecisionMadetotruewhen the incomingstatedoes not specify it, preserving the legacy "disabled means drop" behavior unless clients explicitly opt into the undecided state.
isPreConsentQueueEnabled = false,
}: AnalyticsControllerOptions) {
const initialState: AnalyticsControllerState = {
...getDefaultAnalyticsControllerState(),
...state,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Drop a stale persisted pre-consent queue on init when the queue is disabled, so it can never be replayed by a later enabled instance. - Add a deriveStateFromMetadata test asserting preConsentEventQueue is persisted but excluded from logs, debug snapshots, and UI. - Move selectConsentDecisionMade tests into selectors.test.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
NicolasMassart
left a comment
There was a problem hiding this comment.
Really clean implementation of the pre-consent queue! Nice work!
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |

Explanation
Adds an opt-in pre-consent event queue to AnalyticsController, gated by the new
isPreConsentQueueEnabledoption (disabled by default).Track events received while the user is undecided are persisted and replayed on opt-in, or discarded on opt-out.
References
Fixes: N/A
Checklist
Note
Medium Risk
Touches analytics consent and what gets stored or sent before/after opt-in/out; opt-out and reset now purge more persisted data, but the feature is off by default and track-only for the pre-consent path.
Overview
Adds an opt-in pre-consent flow to
AnalyticsControllerviaisPreConsentQueueEnabled(default off). When enabled, track events fired while the user is undecided (consentDecisionMadefalse) are stored in persistedpreConsentEventQueueinstead of being dropped; they are replayed on opt-in (through the normal delivery path, includingeventQueuewhen persistence is on) and discarded on opt-out.Introduces
consentDecisionMade(default false, set byoptIn/optOut),selectConsentDecisionMade, andresetConsentDecision(undecided again; clears delivery and pre-consent queues).optOutnow also clears queued delivery and pre-consent events.initreconciles stale persisted pre-consent queues (replay if opted in, clear if opted out or feature disabled).Legacy behavior is unchanged when the flag is off: undecided users still do not get events queued or sent.
Reviewed by Cursor Bugbot for commit 5133205. Bugbot is set up for automated code reviews on this repo. Configure here.