From 53205b6bff1ca64400b17c80c69e3b46d4251864 Mon Sep 17 00:00:00 2001 From: Sam Gbafa Date: Wed, 8 Feb 2023 07:16:17 -0800 Subject: [PATCH] Detect and track UI customizations on Personal Sign Requests (#16222) * detect and track ui customizations on personal sign requests * add feature flag check to metrics * clean up comments * get data only if it exists * updated with PR feedback * moved constants * lint * Apply suggestions from code review Co-authored-by: Ariella Vu <20778143+digiwand@users.noreply.github.com> --------- Co-authored-by: Ariella Vu <20778143+digiwand@users.noreply.github.com> --- .../lib/createRPCMethodTrackingMiddleware.js | 28 ++++++++++++++++++- shared/constants/metametrics.js | 16 +++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.js index 8829bf5e2..b1d4ffeae 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.js @@ -1,6 +1,12 @@ import { MESSAGE_TYPE, ORIGIN_METAMASK } from '../../../shared/constants/app'; -import { EVENT, EVENT_NAMES } from '../../../shared/constants/metametrics'; import { SECOND } from '../../../shared/constants/time'; +import { detectSIWE } from '../../../shared/modules/siwe'; +import { + EVENT, + EVENT_NAMES, + METAMETRIC_KEY_OPTIONS, + METAMETRIC_KEY, +} from '../../../shared/constants/metametrics'; /** * These types determine how the method tracking middleware handles incoming @@ -160,6 +166,16 @@ export default function createRPCMethodTrackingMiddleware({ properties.method = method; } + if (process.env.SIWE_V1 && method === MESSAGE_TYPE.PERSONAL_SIGN) { + const data = req?.params?.[0]; + const { isSIWEMessage } = detectSIWE({ data }); + if (isSIWEMessage) { + properties.ui_customizations = [ + METAMETRIC_KEY_OPTIONS[METAMETRIC_KEY.UI_CUSTOMIZATIONS].SIWE, + ]; + } + } + trackEvent({ event, category: EVENT.CATEGORIES.INPAGE_PROVIDER, @@ -192,6 +208,16 @@ export default function createRPCMethodTrackingMiddleware({ properties.method = method; } + if (process.env.SIWE_V1 && method === MESSAGE_TYPE.PERSONAL_SIGN) { + const data = req?.params?.[0]; + const { isSIWEMessage } = detectSIWE({ data }); + if (isSIWEMessage) { + properties.ui_customizations = [ + METAMETRIC_KEY_OPTIONS[METAMETRIC_KEY.UI_CUSTOMIZATIONS].SIWE, + ]; + } + } + trackEvent({ event, category: EVENT.CATEGORIES.INPAGE_PROVIDER, diff --git a/shared/constants/metametrics.js b/shared/constants/metametrics.js index 8f4cf4b5b..def6c6eaf 100644 --- a/shared/constants/metametrics.js +++ b/shared/constants/metametrics.js @@ -451,3 +451,19 @@ export const EVENT = { export const CONTEXT_PROPS = { PAGE_TITLE: 'location', }; + +/** + * These types correspond to the keys in the METAMETRIC_KEY_OPTIONS object + */ +export const METAMETRIC_KEY = { + UI_CUSTOMIZATIONS: `ui_customizations`, +}; + +/** + * This object maps a method name to a METAMETRIC_KEY + */ +export const METAMETRIC_KEY_OPTIONS = { + [METAMETRIC_KEY.UI_CUSTOMIZATIONS]: { + SIWE: 'sign_in_with_ethereum', + }, +};