Skip to content

Commit a5c1d0e

Browse files
authored
feat(snaps): Add integration for new RPC method snap_trackEvent (#15209)
## **Description** Add integration for new RPC method: `snap_trackEvent` SIP-32: https://metamask.github.io/SIPs/SIPS/sip-32 Related PRs: - Snaps: MetaMask/snaps#3375 - Extension: MetaMask/metamask-extension#32554 ## **Related issues** MetaMask/snaps#3274 ## **Manual testing steps** 1. Within some of the preinstalled Snaps use `snap_trackEvent` RPC method and send some tracking data in format specified in [SIP-32](https://metamask.github.io/SIPs/SIPS/sip-32). 2. Find a way and verify that the event is sent (intercept MetaMetrics track event method or check with other e2e metrics testing utilities) Example Snap code used for testing the method: ```typescript await snap.request({ method: 'snap_trackEvent', params: { event: { event: 'SnapExportUsed', properties: { export: 'onRpcRequest', origin: 'https://metamask.io', snap_category: null, snap_id: 'npm:@metamask/example-snap', success: true, }, sensitiveProperties: { transaction_hash: 'transaction-hash', }, }, }, }); ``` ## **Screenshots/Recordings** ### **Before** n/a ### **After** n/a ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] 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 3e8647c commit a5c1d0e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

app/core/Permissions/specifications.js

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export const unrestrictedMethods = Object.freeze([
171171
'snap_resolveInterface',
172172
'snap_setState',
173173
'snap_scheduleBackgroundEvent',
174+
'snap_trackEvent',
174175
'snap_cancelBackgroundEvent',
175176
'snap_getBackgroundEvents',
176177
'snap_experimentalProviderRequest',

app/core/Snaps/SnapsMethodMiddleware.ts

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import {
2626
SnapInterfaceControllerUpdateInterfaceStateAction,
2727
} from '../Engine/controllers/snaps';
2828
import { KeyringTypes } from '@metamask/keyring-controller';
29+
import { MetaMetrics } from '../../../app/core/Analytics';
30+
import { MetricsEventBuilder } from '../Analytics/MetricsEventBuilder';
31+
import { Json } from '@metamask/utils';
2932

3033
export function getSnapIdFromRequest(
3134
request: Record<string, unknown>,
@@ -121,6 +124,19 @@ const snapMethodMiddlewareBuilder = (
121124
controllerMessenger,
122125
SnapControllerGetSnapAction,
123126
),
127+
trackEvent: (eventPayload: {
128+
event: string;
129+
properties: Record<string, Json>;
130+
sensitiveProperties: Record<string, Json>;
131+
}) => {
132+
MetaMetrics.getInstance().trackEvent(
133+
MetricsEventBuilder.createEventBuilder({
134+
category: eventPayload.event,
135+
properties: eventPayload.properties,
136+
sensitiveProperties: eventPayload.sensitiveProperties,
137+
}).build(),
138+
);
139+
},
124140
updateInterfaceState: controllerMessenger.call.bind(
125141
controllerMessenger,
126142
SnapInterfaceControllerUpdateInterfaceStateAction,

0 commit comments

Comments
 (0)