Skip to content

Commit c8995f0

Browse files
authored
feat: add profile_id as a metametrics user trait (#30552)
## **Description** This PR adds `profile_id` as a MetaMetrics user trait so that it gets attached to every event when present in the state. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30552?quickstart=1) ## **Related issues** Related to: https://consensyssoftware.atlassian.net/browse/IDENTITY-39 Segment PR: Consensys/segment-schema#243 ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent e8fa02b commit c8995f0

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

app/scripts/controllers/metametrics-controller.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ describe('MetaMetricsController', function () {
14591459
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
14601460
custodyAccountDetails: {},
14611461
///: END:ONLY_INCLUDE_IF
1462+
sessionData: undefined,
14621463
keyrings: [],
14631464
});
14641465

@@ -1558,6 +1559,7 @@ describe('MetaMetricsController', function () {
15581559
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
15591560
custodyAccountDetails: {},
15601561
///: END:ONLY_INCLUDE_IF
1562+
sessionData: undefined,
15611563
keyrings: [],
15621564
});
15631565

@@ -1618,6 +1620,14 @@ describe('MetaMetricsController', function () {
16181620
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
16191621
custodyAccountDetails: {},
16201622
///: END:ONLY_INCLUDE_IF
1623+
sessionData: {
1624+
accessToken: '',
1625+
expiresIn: '',
1626+
profile: {
1627+
identifierId: 'identifierId',
1628+
profileId: 'profileId',
1629+
},
1630+
},
16211631
keyrings: [],
16221632
});
16231633

@@ -1627,6 +1637,7 @@ describe('MetaMetricsController', function () {
16271637
[MetaMetricsUserTrait.NumberOfTokens]: 1,
16281638
[MetaMetricsUserTrait.OpenSeaApiEnabled]: false,
16291639
[MetaMetricsUserTrait.ShowNativeTokenAsMainBalance]: false,
1640+
[MetaMetricsUserTrait.ProfileId]: 'profileId',
16301641
});
16311642
});
16321643
});
@@ -1686,6 +1697,14 @@ describe('MetaMetricsController', function () {
16861697
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
16871698
custodyAccountDetails: {},
16881699
///: END:ONLY_INCLUDE_IF
1700+
sessionData: {
1701+
accessToken: '',
1702+
expiresIn: '',
1703+
profile: {
1704+
identifierId: 'identifierId',
1705+
profileId: 'profileId',
1706+
},
1707+
},
16891708
keyrings: [],
16901709
});
16911710

@@ -1736,6 +1755,14 @@ describe('MetaMetricsController', function () {
17361755
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
17371756
custodyAccountDetails: {},
17381757
///: END:ONLY_INCLUDE_IF
1758+
sessionData: {
1759+
accessToken: '',
1760+
expiresIn: '',
1761+
profile: {
1762+
identifierId: 'identifierId',
1763+
profileId: 'profileId',
1764+
},
1765+
},
17391766
keyrings: [],
17401767
});
17411768
expect(updatedTraits).toStrictEqual(null);

app/scripts/controllers/metametrics-controller.ts

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
RestrictedMessenger,
4040
} from '@metamask/base-controller';
4141
import { AddressBookControllerState } from '@metamask/address-book-controller';
42+
import { AuthenticationControllerState } from '@metamask/profile-sync-controller/auth';
4243
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
4344
import {
4445
METAMETRICS_ANONYMOUS_ID,
@@ -169,6 +170,7 @@ export type MetaMaskState = {
169170
privacyMode: PreferencesControllerState['preferences']['privacyMode'];
170171
tokenNetworkFilter: string[];
171172
};
173+
sessionData: AuthenticationControllerState['sessionData'];
172174
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
173175
custodyAccountDetails: {
174176
[address: string]: {
@@ -1242,6 +1244,8 @@ export default class MetaMetricsController extends BaseController<
12421244
[MetaMetricsUserTrait.NetworkFilterPreference]: Object.keys(
12431245
metamaskState.preferences.tokenNetworkFilter || {},
12441246
),
1247+
[MetaMetricsUserTrait.ProfileId]:
1248+
metamaskState.sessionData?.profile?.profileId,
12451249
};
12461250

12471251
if (!previousUserTraits && metamaskState.participateInMetaMetrics) {

shared/constants/metametrics.ts

+8
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ export type MetaMetricsUserTraits = {
494494
* The number of petname addresses
495495
*/
496496
petname_addresses_count?: number;
497+
/**
498+
* The profile ID of the user if they have been signed in
499+
*/
500+
profile_id?: string;
497501
};
498502

499503
export enum MetaMetricsUserTrait {
@@ -606,6 +610,10 @@ export enum MetaMetricsUserTrait {
606610
* Identified when the user prefers to see all tokens or current network tokens in wallet list
607611
*/
608612
NetworkFilterPreference = 'selected_network_filter',
613+
/**
614+
* Identified when the user signs in
615+
*/
616+
ProfileId = 'profile_id',
609617
}
610618

611619
/**

0 commit comments

Comments
 (0)