1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/docs/creating-metrics-events.md
Jenny Pollack e00982aa58
add version dimension to metrics event (#8419)
* add version dimension to metrics event

* mock global.platform.getVersion

Co-authored-by: Erik Marks <rekmarks@protonmail.com>
2020-05-05 15:40:36 +02:00

2.2 KiB

Creating Metrics Events

The metricsEvent method is made available to all components via context. This is done in metamask-extension/ui/app/helpers/higher-order-components/metametrics/metametrics.provider.js. As such, it can be called in all components by first adding it to the context proptypes:

static contextTypes = {
  t: PropTypes.func,
  metricsEvent: PropTypes.func,
}

and then accessing it on this.context.

Below is an example of a metrics event call:

this.context.metricsEvent({
  eventOpts: {
    category: 'Navigation',
    action: 'Main Menu',
    name: 'Switched Account',
  },
})

Base Schema

Every metricsEvent call is passed an object that must have an eventOpts property. This property is an object that itself must have three properties:

  • category: categorizes events according to the schema we have set up in our matomo.org instance
  • action: usually describes the page on which the event takes place, or sometimes a significant subsections of a page
  • name: a very specific descriptor of the event

Implicit properties

All metrics events send the following data when called:

  • network
  • environmentType
  • activeCurrency
  • accountType
  • numberOfTokens
  • numberOfAccounts
  • version

These are added to the metrics event via the metametrics provider.

Custom Variables

Metrics events can include custom variables. These are included within the customVariables property that is a first-level property within first param passed to metricsEvent.

For example:

this.context.metricsEvent({
  eventOpts: {
    category: 'Settings',
    action: 'Custom RPC',
    name: 'Error',
  },
  customVariables: {
    networkId: newRpc,
    chainId,
  },
})

Custom variables can have custom property names and values can be strings or numbers.

To include a custom variable, there are a set of necessary steps you must take.

  1. First you must declare a constant equal to the desired name of the custom variable property in metamask-extension/ui/app/helpers/utils/metametrics.util.js under //Custom Variable Declarations
  2. Then you must add that name to the customVariableNameIdMap declaration
    1. The id must be between 1 and 5
    2. There can be no more than 5 custom variables assigned ids on a given url