Skip to content

feat(analytics-controller): add optional pre-consent event queue#9252

Open
gauthierpetetin wants to merge 3 commits into
mainfrom
feat/analytics-controller-pre-consent-queue
Open

feat(analytics-controller): add optional pre-consent event queue#9252
gauthierpetetin wants to merge 3 commits into
mainfrom
feat/analytics-controller-pre-consent-queue

Conversation

@gauthierpetetin

@gauthierpetetin gauthierpetetin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Explanation

Adds 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.

References

Fixes: N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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 AnalyticsController via isPreConsentQueueEnabled (default off). When enabled, track events fired while the user is undecided (consentDecisionMade false) are stored in persisted preConsentEventQueue instead of being dropped; they are replayed on opt-in (through the normal delivery path, including eventQueue when persistence is on) and discarded on opt-out.

Introduces consentDecisionMade (default false, set by optIn/optOut), selectConsentDecisionMade, and resetConsentDecision (undecided again; clears delivery and pre-consent queues). optOut now also clears queued delivery and pre-consent events. init reconciles 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.

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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/analytics-controller/src/AnalyticsController.ts Outdated
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 consentDecisionMade and preConsentEventQueue controller state, with metadata and reconciliation/replay/clear logic.
  • Adds resetConsentDecision to the controller API/messenger actions, plus a new selectConsentDecisionMade selector.
  • 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

  • initialState is built by spreading getDefaultAnalyticsControllerState() (which sets consentDecisionMade: false) over the provided state. For persisted states from before consentDecisionMade existed, this forces consentDecisionMade to false ("undecided"). If a client later enables isPreConsentQueueEnabled, users who previously had only optedIn: false will start persisting pre-consent events, which is a backward-compatibility behavior change and may conflict with prior opt-out expectations. Consider defaulting consentDecisionMade to true when the incoming state does 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.

Comment thread packages/analytics-controller/CHANGELOG.md Outdated
Comment thread packages/analytics-controller/src/AnalyticsController.test.ts
Comment thread packages/analytics-controller/src/AnalyticsController.test.ts Outdated
- 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 NicolasMassart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really clean implementation of the pre-consent queue! Nice work!

@gauthierpetetin

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-previews

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.3-preview-5133205c8
@metamask-previews/accounts-controller@39.0.3-preview-5133205c8
@metamask-previews/address-book-controller@7.1.2-preview-5133205c8
@metamask-previews/ai-controllers@0.7.0-preview-5133205c8
@metamask-previews/analytics-controller@1.1.1-preview-5133205c8
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-5133205c8
@metamask-previews/announcement-controller@8.1.0-preview-5133205c8
@metamask-previews/app-metadata-controller@2.0.1-preview-5133205c8
@metamask-previews/approval-controller@9.0.2-preview-5133205c8
@metamask-previews/assets-controller@9.0.2-preview-5133205c8
@metamask-previews/assets-controllers@109.2.2-preview-5133205c8
@metamask-previews/authenticated-user-storage@2.1.0-preview-5133205c8
@metamask-previews/base-controller@9.1.0-preview-5133205c8
@metamask-previews/base-data-service@0.1.3-preview-5133205c8
@metamask-previews/bitcoin-regtest-up@0.0.0-preview-5133205c8
@metamask-previews/bridge-controller@76.0.0-preview-5133205c8
@metamask-previews/bridge-status-controller@72.2.0-preview-5133205c8
@metamask-previews/build-utils@3.0.4-preview-5133205c8
@metamask-previews/chain-agnostic-permission@1.6.2-preview-5133205c8
@metamask-previews/chomp-api-service@3.1.0-preview-5133205c8
@metamask-previews/claims-controller@0.5.3-preview-5133205c8
@metamask-previews/client-controller@1.0.1-preview-5133205c8
@metamask-previews/compliance-controller@2.1.0-preview-5133205c8
@metamask-previews/composable-controller@12.0.1-preview-5133205c8
@metamask-previews/config-registry-controller@0.4.1-preview-5133205c8
@metamask-previews/connectivity-controller@0.2.0-preview-5133205c8
@metamask-previews/controller-utils@12.3.0-preview-5133205c8
@metamask-previews/core-backend@6.3.3-preview-5133205c8
@metamask-previews/delegation-controller@3.0.2-preview-5133205c8
@metamask-previews/earn-controller@12.2.1-preview-5133205c8
@metamask-previews/eip-5792-middleware@3.0.4-preview-5133205c8
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-5133205c8
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-5133205c8
@metamask-previews/ens-controller@19.1.4-preview-5133205c8
@metamask-previews/eth-block-tracker@15.0.1-preview-5133205c8
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-5133205c8
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-5133205c8
@metamask-previews/foundryup@1.0.1-preview-5133205c8
@metamask-previews/gas-fee-controller@26.2.3-preview-5133205c8
@metamask-previews/gator-permissions-controller@4.2.1-preview-5133205c8
@metamask-previews/geolocation-controller@0.1.3-preview-5133205c8
@metamask-previews/java-tron-up@0.0.0-preview-5133205c8
@metamask-previews/json-rpc-engine@10.5.0-preview-5133205c8
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-5133205c8
@metamask-previews/keyring-controller@27.1.0-preview-5133205c8
@metamask-previews/local-node-utils@0.0.0-preview-5133205c8
@metamask-previews/logging-controller@8.0.2-preview-5133205c8
@metamask-previews/message-manager@14.1.2-preview-5133205c8
@metamask-previews/messenger@1.2.0-preview-5133205c8
@metamask-previews/messenger-cli@0.2.0-preview-5133205c8
@metamask-previews/money-account-balance-service@2.1.1-preview-5133205c8
@metamask-previews/money-account-controller@0.3.3-preview-5133205c8
@metamask-previews/money-account-upgrade-controller@2.1.0-preview-5133205c8
@metamask-previews/multichain-account-service@11.0.0-preview-5133205c8
@metamask-previews/multichain-api-middleware@3.1.5-preview-5133205c8
@metamask-previews/multichain-network-controller@3.1.4-preview-5133205c8
@metamask-previews/multichain-transactions-controller@7.1.1-preview-5133205c8
@metamask-previews/name-controller@9.1.2-preview-5133205c8
@metamask-previews/network-controller@33.0.0-preview-5133205c8
@metamask-previews/network-enablement-controller@5.4.0-preview-5133205c8
@metamask-previews/notification-services-controller@24.2.0-preview-5133205c8
@metamask-previews/passkey-controller@2.0.1-preview-5133205c8
@metamask-previews/permission-controller@13.1.1-preview-5133205c8
@metamask-previews/permission-log-controller@5.1.0-preview-5133205c8
@metamask-previews/perps-controller@8.3.0-preview-5133205c8
@metamask-previews/phishing-controller@17.2.0-preview-5133205c8
@metamask-previews/polling-controller@16.0.7-preview-5133205c8
@metamask-previews/preferences-controller@23.1.0-preview-5133205c8
@metamask-previews/profile-metrics-controller@4.0.0-preview-5133205c8
@metamask-previews/profile-sync-controller@28.2.0-preview-5133205c8
@metamask-previews/ramps-controller@14.3.0-preview-5133205c8
@metamask-previews/rate-limit-controller@7.0.1-preview-5133205c8
@metamask-previews/react-data-query@0.2.1-preview-5133205c8
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-5133205c8
@metamask-previews/sample-controllers@5.0.2-preview-5133205c8
@metamask-previews/seedless-onboarding-controller@10.0.2-preview-5133205c8
@metamask-previews/selected-network-controller@26.1.4-preview-5133205c8
@metamask-previews/shield-controller@5.1.2-preview-5133205c8
@metamask-previews/signature-controller@39.2.6-preview-5133205c8
@metamask-previews/smart-transactions-controller@24.2.3-preview-5133205c8
@metamask-previews/snap-account-service@1.0.0-preview-5133205c8
@metamask-previews/social-controllers@2.3.1-preview-5133205c8
@metamask-previews/solana-test-validator-up@0.0.0-preview-5133205c8
@metamask-previews/storage-service@1.0.2-preview-5133205c8
@metamask-previews/subscription-controller@6.2.0-preview-5133205c8
@metamask-previews/transaction-controller@68.1.1-preview-5133205c8
@metamask-previews/transaction-pay-controller@23.14.0-preview-5133205c8
@metamask-previews/user-operation-controller@41.2.5-preview-5133205c8
@metamask-previews/wallet@4.0.0-preview-5133205c8
@metamask-previews/wallet-cli@0.0.0-preview-5133205c8

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.

3 participants