1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

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>
This commit is contained in:
Sam Gbafa 2023-02-08 07:16:17 -08:00 committed by GitHub
parent 3233f76041
commit 53205b6bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -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,

View File

@ -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',
},
};