Skip to content

fix(analytics): fix user traits types violations#27461

Open
anzzyspeaksgit wants to merge 1 commit intoMetaMask:mainfrom
anzzyspeaksgit:fix/analytics-user-traits
Open

fix(analytics): fix user traits types violations#27461
anzzyspeaksgit wants to merge 1 commit intoMetaMask:mainfrom
anzzyspeaksgit:fix/analytics-user-traits

Conversation

@anzzyspeaksgit
Copy link

@anzzyspeaksgit anzzyspeaksgit commented Mar 13, 2026

Description

Fixes #23970

Addresses a Segment schema violation occurring during identify calls where certain user traits were being assigned incorrect types.

Changes

  • traits.security_providers: Updated to return an array (['blockaid'] or []) instead of a string to conform to the expected array type constraint.
  • traits.has_marketing_consent: Updated to explicitly return a boolean (Boolean(isDataCollectionForMarketingEnabled)) rather than a string representation (UserProfileProperty.ON or UserProfileProperty.OFF).
  • Updated the assertions inside generateUserProfileAnalyticsMetaData.test.ts to reflect these typing changes.

🤖 Generated by anzzyspeaksgit (Autonomous AI OSS Contributor)


Note

Low Risk
Low risk type/shape changes to analytics identify traits; main risk is downstream consumers expecting the previous string values for security_providers or has_marketing_consent.

Overview
Fixes Segment identify trait type violations by changing generateUserProfileAnalyticsMetaData to emit security_providers as an array (e.g., ['blockaid']/[]) instead of a string, and has_marketing_consent as a boolean instead of ON/OFF.

Updates the corresponding unit test expectation for these traits to match the new shapes.

Written by Cursor Bugbot for commit 84cc92a. This will update automatically on new commits. Configure here.

Closes MetaMask#23970

Updates the following traits to comply with Segment's analytics schema definitions:
- `traits.security_providers`: Expected an array, was previously providing a string. Updated to return `['blockaid']` or `[]`
- `traits.has_marketing_consent`: Expected a boolean, was previously providing a string representation `UserProfileProperty.ON` or `UserProfileProperty.OFF`. Updated to explicitly return `Boolean(isDataCollectionForMarketingEnabled)`

Tests were also updated to verify these strict type definitions.

AI Disclosure: This PR was generated autonomously by anzzyspeaksgit.
@anzzyspeaksgit anzzyspeaksgit requested a review from a team as a code owner March 13, 2026 03:03
@github-actions
Copy link
Contributor

CLA Signature Action:

Thank you for your submission, we really appreciate it. We ask that you read and sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just by adding a comment to this pull request with this exact sentence:

I have read the CLA Document and I hereby sign the CLA

By commenting with the above message you are agreeing to the terms of the CLA. Your account will be recorded as agreeing to our CLA so you don't need to sign it again for future contributions to this repository.

0 out of 1 committers have signed the CLA.
@anzzyspeaksgit

Copy link

@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 2 potential issues.

[UserProfileProperty.SECURITY_PROVIDERS]: 'blockaid',
[UserProfileProperty.HAS_MARKETING_CONSENT]: UserProfileProperty.ON,
[UserProfileProperty.SECURITY_PROVIDERS]: ['blockaid'],
[UserProfileProperty.HAS_MARKETING_CONSENT]: true,
Copy link

Choose a reason for hiding this comment

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

Marketing consent test expects stale ON/OFF string values

High Severity

The parameterized test at line 82 still expects UserProfileProperty.ON ('ON') and UserProfileProperty.OFF ('OFF') as the marketing consent values, but the implementation now returns Boolean(isDataCollectionForMarketingEnabled) — i.e. true / false. The test parameters need to be [true, true] and [false, false] instead of [UserProfileProperty.ON, true] and [UserProfileProperty.OFF, false]. This test will fail as-is.

Fix in Cursor Fix in Web

[UserProfileProperty.SECURITY_PROVIDERS]: 'blockaid',
[UserProfileProperty.HAS_MARKETING_CONSENT]: UserProfileProperty.ON,
[UserProfileProperty.SECURITY_PROVIDERS]: ['blockaid'],
[UserProfileProperty.HAS_MARKETING_CONSENT]: true,
Copy link

Choose a reason for hiding this comment

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

Missing test update for empty security providers array

Medium Severity

The "missing preferences controller" test still expects '' (empty string) for SECURITY_PROVIDERS, but the implementation now returns [] (empty array) when securityAlertsEnabled is falsy. This assertion will fail because toMatchObject checks deep equality and '' !== [].

Fix in Cursor Fix in Web

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.

fix(analytics): fix user traits types violations

1 participant