Use Segment for web3 usage metrics; fix background Segment bugs (#9525)

* Use segment for window.web3 usage metrics
* Add Segment referrer information
* Fix track segment event bug
* Fix missing category bug in tx segment event

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent a301ce92d8
commit 7870d6d194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/controllers/transactions/index.js
  2. 8
      app/scripts/lib/rpc-method-middleware/handlers/log-web3-usage.js
  3. 8
      app/scripts/lib/segment.js
  4. 4
      app/scripts/lib/setupWeb3.js
  5. 4
      app/scripts/metamask-controller.js

@ -861,6 +861,7 @@ export default class TransactionController extends EventEmitter {
this._trackSegmentEvent({
event: 'Swap Completed',
category: 'swaps',
properties: {
...txMeta.swapMetaData,
token_to_amount_received: tokensReceived,

@ -45,10 +45,12 @@ function logWeb3UsageHandler (
}
if (!recordedWeb3Usage[origin][name]) {
recordedWeb3Usage[origin][name] = true
sendMetrics({
action,
name,
customVariables: { origin },
event: `Website Accessed window.web3`,
category: 'inpage_provider',
properties: { action, web3Property: name },
referrerUrl: origin,
})
}

@ -64,6 +64,7 @@ export function getTrackSegmentEvent (
* @param {string} event - The event name.
* @param {string} category - The event category.
* @param {Object} [properties] - The event properties.
* @param {string} [referrerUrl] - The event's referrer URL, if relevant.
* @param {boolean} [excludeMetaMetricsId] - `true` if the user's MetaMetrics id should
* not be included, and `false` otherwise. Default: `true`
*/
@ -72,6 +73,7 @@ export function getTrackSegmentEvent (
category,
properties = {},
excludeMetaMetricsId = true,
referrerUrl,
}) {
if (!event || !category) {
throw new Error('Must specify event and category.')
@ -99,6 +101,12 @@ export function getTrackSegmentEvent (
trackOptions.userId = metaMetricsId
}
if (referrerUrl) {
trackOptions.context.referrer = {
url: referrerUrl,
}
}
segment.track(trackOptions)
}
}

@ -47,7 +47,7 @@ export default function setupWeb3 (log) {
const name = stringifyKey(key)
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 get', name }],
params: [{ action: 'get', name }],
})
}
@ -59,7 +59,7 @@ export default function setupWeb3 (log) {
if (shouldLogUsage) {
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 set', name }],
params: [{ action: 'set', name }],
})
}

@ -123,7 +123,7 @@ export default class MetamaskController extends EventEmitter {
const {
currentLocale,
metaMetricsId,
} = this.preferencesController.getState()
} = this.preferencesController.store.getState()
return { currentLocale, metaMetricsId }
},
)
@ -1672,7 +1672,7 @@ export default class MetamaskController extends EventEmitter {
}))
engine.push(createMethodMiddleware({
origin,
sendMetrics: this.sendBackgroundMetaMetrics.bind(this),
sendMetrics: this.trackSegmentEvent,
}))
// filter and subscription polyfills
engine.push(filterMiddleware)

Loading…
Cancel
Save