Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify desktop is paired in the metrics event #17892

Merged
merged 6 commits into from
Mar 2, 2023

Conversation

vinistevam
Copy link
Contributor

@vinistevam vinistevam commented Feb 24, 2023

Explanation

Adds the metrics code needed to support tracking usage of the MetaMask Desktop app.

The aim of this PR is to identify if the desktop app is paired with the extension on MetaMetrics to track key operations such as swaps, snaps, transfers, and interaction with dapps. It also includes desktop-related events.

Changes include:

  • metametrics: included desktop_enabled in traits to identify whenever the user pairs/unpairs the extension and the desktop app.
  • UI changes to emit desktop-related events whenever a button is clicked
    • Included a new event category DESKTOP

Manual Testing Steps

analytics.identify({
  userId: '0x',
  traits: {
    desktop_enabled: true,
  }
});

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2023

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@vinistevam vinistevam force-pushed the fix/549-add-metrics-mmd-paired branch from e396ade to e5d59e5 Compare February 24, 2023 11:48
@vinistevam
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@metamaskbot
Copy link
Collaborator

Builds ready [e5d59e5]
Page Load Metrics (1823 ± 85 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1031841342010
domContentLoaded15122124180317785
load15292124182317885
domInteractive15122124180317785
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 18 bytes

@vinistevam vinistevam marked this pull request as ready for review February 24, 2023 14:11
@vinistevam vinistevam requested a review from a team as a code owner February 24, 2023 14:11
@vinistevam vinistevam requested a review from chloeYue February 24, 2023 14:11
@brad-decker
Copy link
Contributor

@worldlyjohn have you been consulted on these changes?

Comment on lines 682 to 684
///: BEGIN:ONLY_INCLUDE_IN(desktop)
desktop_paired: this.getDesktopEnabled(),
///: END:ONLY_INCLUDE_IN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desktop_paired seems more like a user trait then a property we want on every event. @worldlyjohn thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing my PR 🙇
If more appropriate I can move it to user traits.

Comment on lines 48 to 52
if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.ERROR,
event: `Error: ${text}`,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we tracking errors in segment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here was to measure the errors while using the desktop app as a companion but you are right, It is already collected by Sentry and if necessary in Segment, it can be tracked by using the trackPage method. I will remove it and push the changes.

Comment on lines 78 to 93
if (onClick) {
onClick();
if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `${text} Button Clicked`,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types of dynamic event names are not acceptable....They end up creating variadic events that make it very hard to derive meaning from. @worldlyjohn will advise you on if we want this event or not and if so how to add properties to cover the use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One quick update on this case. I pushed some changes so that instead of using the text it uses the id of the button to determine the event name. In case, more properties need to be added it's possible to extend this function to also include specific properties for each event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id also not sufficient as it's easy for an element id to change and unintended consequence is the event is now changed too. usually when you want to do this, the best practice is a more generic event name and using this value as a property (though the id field should probably be validated that it matches one element in a predefined set)

@metamaskbot
Copy link
Collaborator

Builds ready [f436b74]
Page Load Metrics (1510 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint97137113116
domContentLoaded1244162414768742
load12441701151010450
domInteractive1244162414768742
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 18 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [0a8eacb]
Page Load Metrics (1479 ± 35 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint92138112147
domContentLoaded1236154914586832
load1314163414797235
domInteractive1236154914586832
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 18 bytes

@vinistevam vinistevam force-pushed the fix/549-add-metrics-mmd-paired branch from 0a8eacb to c7a1773 Compare February 28, 2023 11:30
@metamaskbot
Copy link
Collaborator

Builds ready [c7a1773]
Page Load Metrics (1748 ± 79 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1021991282512
domContentLoaded14792127171817283
load15702127174816579
domInteractive14792127171817283
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 18 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [3dee418]
Page Load Metrics (1618 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint99154118167
domContentLoaded1454177415829244
load14541895161810651
domInteractive1454177415829244
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 52 bytes

@@ -61,10 +74,57 @@ export function renderDesktopError({
);
};

const getEventNameById = (id) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of these events follow our naming conventions defined here: https://www.notion.so/Naming-Conventions-95bf27517033451888053f7ab654d327

if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `${getEventNameById(id)} Button Clicked`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using dynamic event names is frowned upon as it will create N new tables. can this be a single event name and use dynamic id (if truely necessary) as a property instead? (though even that is less than ideal, better if you run this through a defined list of possible values)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 Great thanks!
I changed it to a single event Desktop Button Clicked and also included an additional parameter in the renderCTA that will be the value of the property to identify the CTA performed by the user.

@@ -40,6 +43,10 @@ export default function DesktopEnableButton() {
if (desktopEnabled) {
await disableDesktop();
setDesktopEnabled(false);
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `Disable Desktop Button Clicked`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of separate events for enable/disabled, these should be properties of the same event. another option is that this is actually a setting change.

either of these works:

event name: Desktop Button Clicked
properties: {enabled: true|false}

or

event name: Settings Updated
properties: {desktop_enabled: true|false}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opted for the settings change as you suggested:

event name: Settings Updated
properties: {desktop_enabled: true|false}

@vinistevam vinistevam force-pushed the fix/549-add-metrics-mmd-paired branch from dd78de7 to 380f8b2 Compare March 1, 2023 12:21
@metamaskbot
Copy link
Collaborator

Builds ready [380f8b2]
Page Load Metrics (1667 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1012111302311
domContentLoaded14721871165110751
load14721872166711254
domInteractive14721871165110751
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 52 bytes

@vinistevam vinistevam force-pushed the fix/549-add-metrics-mmd-paired branch from 380f8b2 to ca1be4e Compare March 1, 2023 15:43
@vinistevam vinistevam force-pushed the fix/549-add-metrics-mmd-paired branch from ca1be4e to e98a6ee Compare March 1, 2023 18:51
@metamaskbot
Copy link
Collaborator

Builds ready [e98a6ee]
Page Load Metrics (1501 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint942041212612
domContentLoaded1344166014898842
load1344166015018742
domInteractive1344166014898842
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: 52 bytes

@worldlyjohn
Copy link
Contributor

works for me!

@brad-decker brad-decker merged commit e07ec9d into develop Mar 2, 2023
@brad-decker brad-decker deleted the fix/549-add-metrics-mmd-paired branch March 2, 2023 20:55
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants