From f77151003e7ad12a4c265b1b95645d0e9a14211c Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 14 Aug 2020 19:15:21 -0300 Subject: [PATCH] Send web3 usage metrics once per origin/property (#9237) The usage metrics for the injected web3 instance were being sent upon each use, which exceeded the limits of our Matomo plan. These metrics are now only being sent upon the first usage, for each origin and property. --- app/scripts/lib/createMethodMiddleware.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/scripts/lib/createMethodMiddleware.js b/app/scripts/lib/createMethodMiddleware.js index 8224dbf33..7a98ce531 100644 --- a/app/scripts/lib/createMethodMiddleware.js +++ b/app/scripts/lib/createMethodMiddleware.js @@ -1,3 +1,6 @@ + +const recordedWeb3Usage = {} + /** * Returns a middleware that implements the following RPC methods: * - metamask_logInjectedWeb3Usage @@ -15,11 +18,17 @@ export default function createMethodMiddleware ({ origin, sendMetrics }) { const { action, name } = req.params[0] - sendMetrics({ - action, - name, - customVariables: { origin }, - }) + if (!recordedWeb3Usage[origin]) { + recordedWeb3Usage[origin] = {} + } + if (!recordedWeb3Usage[origin][name]) { + recordedWeb3Usage[origin][name] = true + sendMetrics({ + action, + name, + customVariables: { origin }, + }) + } res.result = true break