Add web3 usage metrics, prepare for web3 removal (#9144)
* add web3 usage metrics * move web3 metrics method to new middleware * rename some methods, files, and exportsfeature/default_network_editable
parent
d59fc79e0f
commit
e5cb63eea2
@ -1,13 +1,13 @@ |
|||||||
import { getBackgroundMetaMetricState } from '../../../ui/app/selectors' |
import { getBackgroundMetaMetricState } from '../../../ui/app/selectors' |
||||||
import { sendMetaMetricsEvent } from '../../../ui/app/helpers/utils/metametrics.util' |
import { sendMetaMetricsEvent } from '../../../ui/app/helpers/utils/metametrics.util' |
||||||
|
|
||||||
export default function backEndMetaMetricsEvent (metaMaskState, eventData) { |
export default function backgroundMetaMetricsEvent (metaMaskState, eventData) { |
||||||
const stateEventData = getBackgroundMetaMetricState({ metamask: metaMaskState }) |
const stateEventData = getBackgroundMetaMetricState({ metamask: metaMaskState }) |
||||||
|
|
||||||
if (stateEventData.participateInMetaMetrics) { |
if (stateEventData.participateInMetaMetrics) { |
||||||
sendMetaMetricsEvent({ |
sendMetaMetricsEvent({ |
||||||
...stateEventData, |
...stateEventData, |
||||||
...eventData, |
...eventData, |
||||||
|
category: 'Background', |
||||||
currentPath: '/background', |
currentPath: '/background', |
||||||
}) |
}) |
||||||
} |
} |
@ -0,0 +1,32 @@ |
|||||||
|
/** |
||||||
|
* Returns a middleware that implements the following RPC methods: |
||||||
|
* - metamask_logInjectedWeb3Usage |
||||||
|
* |
||||||
|
* @param {Object} opts - The middleware options |
||||||
|
* @param {string} opts.origin - The origin for the middleware stack |
||||||
|
* @param {Function} opts.sendMetrics - A function for sending a metrics event |
||||||
|
* @returns {(req: any, res: any, next: Function, end: Function) => void} |
||||||
|
*/ |
||||||
|
export default function createMethodMiddleware ({ origin, sendMetrics }) { |
||||||
|
return function methodMiddleware (req, res, next, end) { |
||||||
|
switch (req.method) { |
||||||
|
|
||||||
|
case 'metamask_logInjectedWeb3Usage': |
||||||
|
|
||||||
|
const { action, name } = req.params[0] |
||||||
|
|
||||||
|
sendMetrics({ |
||||||
|
action, |
||||||
|
name, |
||||||
|
customVariables: { origin }, |
||||||
|
}) |
||||||
|
|
||||||
|
res.result = true |
||||||
|
break |
||||||
|
|
||||||
|
default: |
||||||
|
return next() |
||||||
|
} |
||||||
|
return end() |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue