mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Track usage of snap exports (#20503)
* Track usage of snap exports * Fix fencing * Small change to event name * Use MetaMetricsEventName
This commit is contained in:
parent
e9c641dfcd
commit
832e0b1cf2
@ -5,11 +5,16 @@ import { storeAsStream } from '@metamask/obs-store/dist/asStream';
|
|||||||
import { JsonRpcEngine } from 'json-rpc-engine';
|
import { JsonRpcEngine } from 'json-rpc-engine';
|
||||||
import { createEngineStream } from 'json-rpc-middleware-stream';
|
import { createEngineStream } from 'json-rpc-middleware-stream';
|
||||||
import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware';
|
import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware';
|
||||||
import { debounce } from 'lodash';
|
|
||||||
import {
|
import {
|
||||||
KeyringController,
|
KeyringController,
|
||||||
keyringBuilderFactory,
|
keyringBuilderFactory,
|
||||||
} from '@metamask/eth-keyring-controller';
|
} from '@metamask/eth-keyring-controller';
|
||||||
|
import {
|
||||||
|
debounce,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
||||||
|
throttle,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
|
} from 'lodash';
|
||||||
import createFilterMiddleware from 'eth-json-rpc-filters';
|
import createFilterMiddleware from 'eth-json-rpc-filters';
|
||||||
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager';
|
import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager';
|
||||||
import { errorCodes as rpcErrorCodes, EthereumRpcError } from 'eth-rpc-errors';
|
import { errorCodes as rpcErrorCodes, EthereumRpcError } from 'eth-rpc-errors';
|
||||||
@ -1782,6 +1787,39 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks snaps export usage. Note: This function is throttled to 1 call per 60 seconds.
|
||||||
|
*
|
||||||
|
* @param {string} handler - The handler to trigger on the snap for the request.
|
||||||
|
*/
|
||||||
|
_trackSnapExportUsage = throttle(
|
||||||
|
(handler) =>
|
||||||
|
this.metaMetricsController.trackEvent({
|
||||||
|
event: MetaMetricsEventName.SnapExportUsed,
|
||||||
|
category: MetaMetricsEventCategory.Snaps,
|
||||||
|
properties: {
|
||||||
|
export: handler,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
SECOND * 60,
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passes a JSON-RPC request object to the SnapController for execution.
|
||||||
|
*
|
||||||
|
* @param {object} args - A bag of options.
|
||||||
|
* @param {string} args.snapId - The ID of the recipient snap.
|
||||||
|
* @param {string} args.origin - The origin of the RPC request.
|
||||||
|
* @param {string} args.handler - The handler to trigger on the snap for the request.
|
||||||
|
* @param {object} args.request - The JSON-RPC request object.
|
||||||
|
* @returns The result of the JSON-RPC request.
|
||||||
|
*/
|
||||||
|
handleSnapRequest(args) {
|
||||||
|
this._trackSnapExportUsage(args.handler);
|
||||||
|
|
||||||
|
return this.controllerMessenger.call('SnapController:handleRequest', args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor helper for getting Snap permission specifications.
|
* Constructor helper for getting Snap permission specifications.
|
||||||
*/
|
*/
|
||||||
@ -1803,10 +1841,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
this.controllerMessenger,
|
this.controllerMessenger,
|
||||||
'SnapController:get',
|
'SnapController:get',
|
||||||
),
|
),
|
||||||
handleSnapRpcRequest: this.controllerMessenger.call.bind(
|
handleSnapRpcRequest: this.handleSnapRequest.bind(this),
|
||||||
this.controllerMessenger,
|
|
||||||
'SnapController:handleRequest',
|
|
||||||
),
|
|
||||||
getSnapState: this.controllerMessenger.call.bind(
|
getSnapState: this.controllerMessenger.call.bind(
|
||||||
this.controllerMessenger,
|
this.controllerMessenger,
|
||||||
'SnapController:getSnapState',
|
'SnapController:getSnapState',
|
||||||
@ -1958,7 +1993,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
`${this.snapController.name}:snapInstalled`,
|
`${this.snapController.name}:snapInstalled`,
|
||||||
(truncatedSnap) => {
|
(truncatedSnap) => {
|
||||||
this.metaMetricsController.trackEvent({
|
this.metaMetricsController.trackEvent({
|
||||||
event: 'Snap Installed',
|
event: MetaMetricsEventName.SnapInstalled,
|
||||||
category: MetaMetricsEventCategory.Snaps,
|
category: MetaMetricsEventCategory.Snaps,
|
||||||
properties: {
|
properties: {
|
||||||
snap_id: truncatedSnap.id,
|
snap_id: truncatedSnap.id,
|
||||||
@ -1972,7 +2007,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
`${this.snapController.name}:snapUpdated`,
|
`${this.snapController.name}:snapUpdated`,
|
||||||
(newSnap, oldVersion) => {
|
(newSnap, oldVersion) => {
|
||||||
this.metaMetricsController.trackEvent({
|
this.metaMetricsController.trackEvent({
|
||||||
event: 'Snap Updated',
|
event: MetaMetricsEventName.SnapUpdated,
|
||||||
category: MetaMetricsEventCategory.Snaps,
|
category: MetaMetricsEventCategory.Snaps,
|
||||||
properties: {
|
properties: {
|
||||||
snap_id: newSnap.id,
|
snap_id: newSnap.id,
|
||||||
@ -2549,10 +2584,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
this.controllerMessenger,
|
this.controllerMessenger,
|
||||||
'SnapController:remove',
|
'SnapController:remove',
|
||||||
),
|
),
|
||||||
handleSnapRequest: this.controllerMessenger.call.bind(
|
handleSnapRequest: this.handleSnapRequest.bind(this),
|
||||||
this.controllerMessenger,
|
|
||||||
'SnapController:handleRequest',
|
|
||||||
),
|
|
||||||
revokeDynamicSnapPermissions: this.controllerMessenger.call.bind(
|
revokeDynamicSnapPermissions: this.controllerMessenger.call.bind(
|
||||||
this.controllerMessenger,
|
this.controllerMessenger,
|
||||||
'SnapController:revokeDynamicPermissions',
|
'SnapController:revokeDynamicPermissions',
|
||||||
|
@ -599,6 +599,11 @@ export enum MetaMetricsEventName {
|
|||||||
ActivityScreenOpened = 'Activity Screen Opened',
|
ActivityScreenOpened = 'Activity Screen Opened',
|
||||||
WhatsNewViewed = `What's New Viewed`,
|
WhatsNewViewed = `What's New Viewed`,
|
||||||
WhatsNewClicked = `What's New Link Clicked`,
|
WhatsNewClicked = `What's New Link Clicked`,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
||||||
|
SnapInstalled = 'Snap Installed',
|
||||||
|
SnapUpdated = 'Snap Updated',
|
||||||
|
SnapExportUsed = 'Snap Export Used',
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum MetaMetricsEventAccountType {
|
export enum MetaMetricsEventAccountType {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user