Skip to content

feat(analytics-controller): add optional context parameter for track, identify, view#8835

Open
gauthierpetetin wants to merge 1 commit into
mainfrom
codex/analytics-controller-context-options
Open

feat(analytics-controller): add optional context parameter for track, identify, view#8835
gauthierpetetin wants to merge 1 commit into
mainfrom
codex/analytics-controller-context-options

Conversation

@gauthierpetetin
Copy link
Copy Markdown
Contributor

@gauthierpetetin gauthierpetetin commented May 15, 2026

Explanation

Add the possibility to forward context to AnalyticsController for trackEvent, identify, and trackView functions, as this is needed in Extension.

Validation

  • yarn workspace @metamask/analytics-controller run jest --no-coverage packages/analytics-controller/src/AnalyticsController.test.ts
  • yarn workspace @metamask/analytics-controller run messenger-action-types:check
  • yarn workspace @metamask/analytics-controller run changelog:validate
  • yarn workspace @metamask/analytics-controller run build
  • yarn eslint packages/analytics-controller/src/AnalyticsController.ts packages/analytics-controller/src/AnalyticsController.test.ts packages/analytics-controller/src/AnalyticsPlatformAdapter.types.ts packages/analytics-controller/src/AnalyticsController-method-action-types.ts packages/analytics-controller/src/index.ts

References

Replaces #8701 which is no longer needed


Note

Low Risk
Low risk: adds an optional context payload and forwards it to adapters without changing existing behavior when omitted; main risk is downstream TypeScript/interface compatibility for AnalyticsPlatformAdapter implementations.

Overview
Adds an optional AnalyticsContext parameter to AnalyticsController methods trackEvent, identify, and trackView, and forwards it through to the underlying AnalyticsPlatformAdapter (track/identify/view).

Updates the adapter type definitions and public exports to include AnalyticsContext, and extends unit tests plus changelog to cover context forwarding (including event-splitting behavior and events without properties).

Reviewed by Cursor Bugbot for commit f3dcf3e. Bugbot is set up for automated code reviews on this repo. Configure here.

@gauthierpetetin gauthierpetetin changed the title [codex] Add analytics context forwarding Add analytics context forwarding May 15, 2026
@gauthierpetetin gauthierpetetin changed the title Add analytics context forwarding feat(analytics-controller): add optional context parameter for track, identify, view May 15, 2026
@gauthierpetetin gauthierpetetin force-pushed the codex/analytics-controller-context-options branch from d508c40 to f3dcf3e Compare May 15, 2026 15:36
@gauthierpetetin gauthierpetetin marked this pull request as ready for review May 15, 2026 15:38
@gauthierpetetin gauthierpetetin requested review from a team as code owners May 15, 2026 15:38
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 f3dcf3e. Configure here.

this.#platformAdapter.track(event.name, undefined, context);
} else {
this.#platformAdapter.track(event.name);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Redundant context branching repeated five times

Low Severity

The if (context) { call(args, context) } else { call(args) } branching pattern is duplicated five times across trackEvent, identify, and trackView. Since context is typed as optional (context?: AnalyticsContext) on the AnalyticsPlatformAdapter methods, simply always passing context (which is undefined when omitted) achieves the same result in a single call per site, removing ~20 lines of redundant branching and reducing the maintenance surface for future changes.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f3dcf3e. Configure here.

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.

1 participant