Skip to content

Commit

Permalink
feat: add profile_id as a metametrics user trait
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuartu committed Feb 25, 2025
1 parent 5ddd7e9 commit cdcede6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/scripts/controllers/metametrics-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
sessionData: undefined,
});

expect(traits).toStrictEqual({
Expand Down Expand Up @@ -1555,6 +1556,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
sessionData: undefined,
});

const updatedTraits = controller._buildUserTraitsObject({
Expand Down Expand Up @@ -1614,6 +1616,14 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
sessionData: {
accessToken: '',
expiresIn: '',
profile: {
identifierId: 'identifierId',
profileId: 'profileId',
},
},
});

expect(updatedTraits).toStrictEqual({
Expand All @@ -1622,6 +1632,7 @@ describe('MetaMetricsController', function () {
[MetaMetricsUserTrait.NumberOfTokens]: 1,
[MetaMetricsUserTrait.OpenSeaApiEnabled]: false,
[MetaMetricsUserTrait.ShowNativeTokenAsMainBalance]: false,
[MetaMetricsUserTrait.ProfileId]: 'profileId',
});
});
});
Expand Down Expand Up @@ -1681,6 +1692,14 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
sessionData: {
accessToken: '',
expiresIn: '',
profile: {
identifierId: 'identifierId',
profileId: 'profileId',
},
},
});

const updatedTraits = controller._buildUserTraitsObject({
Expand Down Expand Up @@ -1730,6 +1749,14 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
sessionData: {
accessToken: '',
expiresIn: '',
profile: {
identifierId: 'identifierId',
profileId: 'profileId',
},
},
});
expect(updatedTraits).toStrictEqual(null);
});
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
RestrictedMessenger,
} from '@metamask/base-controller';
import { AddressBookControllerState } from '@metamask/address-book-controller';
import { AuthenticationControllerState } from '@metamask/profile-sync-controller/auth';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import {
METAMETRICS_ANONYMOUS_ID,
Expand Down Expand Up @@ -168,6 +169,7 @@ export type MetaMaskState = {
privacyMode: PreferencesControllerState['preferences']['privacyMode'];
tokenNetworkFilter: string[];
};
sessionData: AuthenticationControllerState['sessionData'];
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {
[address: string]: {
Expand Down Expand Up @@ -1237,6 +1239,8 @@ export default class MetaMetricsController extends BaseController<
[MetaMetricsUserTrait.NetworkFilterPreference]: Object.keys(
metamaskState.preferences.tokenNetworkFilter || {},
),
[MetaMetricsUserTrait.ProfileId]:
metamaskState.sessionData?.profile?.profileId,
};

if (!previousUserTraits && metamaskState.participateInMetaMetrics) {
Expand Down
8 changes: 8 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ export type MetaMetricsUserTraits = {
* The number of petname addresses
*/
petname_addresses_count?: number;
/**
* The profile ID of the user if they have been signed in
*/
profile_id?: string;
};

export enum MetaMetricsUserTrait {
Expand Down Expand Up @@ -598,6 +602,10 @@ export enum MetaMetricsUserTrait {
* Identified when the user prefers to see all tokens or current network tokens in wallet list
*/
NetworkFilterPreference = 'selected_network_filter',
/**
* Identified when the user signs in
*/
ProfileId = 'profile_id',
}

/**
Expand Down

0 comments on commit cdcede6

Please sign in to comment.