From 25bf04da4c68f62e9b352474360adeec74952079 Mon Sep 17 00:00:00 2001 From: hmalik88 Date: Mon, 18 Sep 2023 12:08:27 -0400 Subject: [PATCH] handling analytics differently for v2 in flask --- app/scripts/metamask-controller.js | 10 +++++++++- .../snaps/snap-insight.js | 20 +++++++++++++++++-- ui/store/actions.ts | 9 +++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 42f6fd9a19e2..c37751085fc9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -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) @@ -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); } diff --git a/ui/components/app/confirm-page-container/snaps/snap-insight.js b/ui/components/app/confirm-page-container/snaps/snap-insight.js index 6ce2eb7f7cb0..9c04e776773c 100644 --- a/ui/components/app/confirm-page-container/snaps/snap-insight.js +++ b/ui/components/app/confirm-page-container/snaps/snap-insight.js @@ -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 { @@ -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(); @@ -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), diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 33585cf88f99..f8b5b8d5cbe4 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -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)