Skip to content

Commit

Permalink
handling analytics differently for v2 in flask
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 committed Sep 18, 2023
1 parent 2c3f772 commit 25bf04d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ import { securityProviderCheck } from './lib/security-provider-helpers';
import { IndexedDBPPOMStorage } from './lib/ppom/indexed-db-backend';
///: END:ONLY_INCLUDE_IN
import { updateCurrentLocale } from './translate';
import { HandlerType } from '@metamask/snaps-utils';

export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
Expand Down Expand Up @@ -1911,7 +1912,14 @@ export default class MetamaskController extends EventEmitter {
* @returns The result of the JSON-RPC request.
*/
handleSnapRequest(args) {
this._trackSnapExportUsage(args.snapId, args.handler);
// we're not tracking at this point in flask because we eagerly fetch insights in v2
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
if (args.handler !== HandlerType.OnTransaction) {
///: END:ONLY_INCLUDE_IN
this._trackSnapExportUsage(args.snapId, args.handler);
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
}
///: END:ONLY_INCLUDE_IN

return this.controllerMessenger.call('SnapController:handleRequest', args);
}
Expand Down
20 changes: 18 additions & 2 deletions ui/components/app/confirm-page-container/snaps/snap-insight.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';

import { useSelector } from 'react-redux';
import {
useSelector,
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
useDispatch,
///: END:ONLY_INCLUDE_IN
} from 'react-redux';
import Preloader from '../../../ui/icon/preloader/preloader-icon.component';
import { Text } from '../../../component-library';
import {
Expand All @@ -20,6 +25,7 @@ import { DelineatorType } from '../../../../helpers/constants/snaps';
import { getSnapName } from '../../../../helpers/utils/util';
import { Copyable } from '../../snaps/copyable';
import { getTargetSubjectMetadata } from '../../../../selectors';
import { trackInsightSnapUsage } from '../../../../store/actions';

export const SnapInsight = ({ data, loading }) => {
const t = useI18nContext();
Expand All @@ -28,6 +34,16 @@ export const SnapInsight = ({ data, loading }) => {
snapId,
response: { content },
} = data;
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
const dispatch = useDispatch();

useEffect(() => {
const trackInsightUsage = async () => {
await dispatch(trackInsightSnapUsage(snapId));
};
trackInsightUsage();
}, [snapId, dispatch]);
///: END:ONLY_INCLUDE_IN

const targetSubjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, snapId),
Expand Down
9 changes: 9 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,15 @@ export function setSnapsInstallPrivacyWarningShownStatus(shown: boolean) {
);
};
}

export function trackInsightSnapUsage(snapId: string) {
return async () => {
await submitRequestToBackground('_trackSnapExportUsage', [
snapId,
HandlerType.OnTransaction,
]);
};
}
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps)
Expand Down

0 comments on commit 25bf04d

Please sign in to comment.