diff options
author | Dan J Miller <danjm.com@gmail.com> | 2019-04-29 14:18:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-29 14:18:40 +0800 |
commit | 4fea9d0cc2ec9c6914931d5e310665aca8e273b6 (patch) | |
tree | c2ff2c9bdb90179c5583cd59a1e77631c25f3a35 /app | |
parent | 00958894087a9af845f3746de6698130facd7654 (diff) | |
download | tangerine-wallet-browser-4fea9d0cc2ec9c6914931d5e310665aca8e273b6.tar.gz tangerine-wallet-browser-4fea9d0cc2ec9c6914931d5e310665aca8e273b6.tar.zst tangerine-wallet-browser-4fea9d0cc2ec9c6914931d5e310665aca8e273b6.zip |
Send metrics event from backend for on chain transaction failures (#6500)
* Send metrics event from backend for on chain transaction failures
* Passes state object to backEndMetaMetricsEvent, and adds getMetaMetricState selector
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/controllers/preferences.js | 8 | ||||
-rw-r--r-- | app/scripts/lib/backend-metametrics.js | 26 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 19 |
3 files changed, 52 insertions, 1 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 737411890..9fe8bee4b 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -117,6 +117,14 @@ class PreferencesController { return metaMetricsId } + getMetaMetricsId () { + return this.store.getState().metaMetricsId + } + + getParticipateInMetaMetrics () { + return this.store.getState().participateInMetaMetrics + } + setMetaMetricsSendCount (val) { this.store.updateState({ metaMetricsSendCount: val }) } diff --git a/app/scripts/lib/backend-metametrics.js b/app/scripts/lib/backend-metametrics.js new file mode 100644 index 000000000..e3c163c1a --- /dev/null +++ b/app/scripts/lib/backend-metametrics.js @@ -0,0 +1,26 @@ +const { + getMetaMetricState, +} = require('../../../ui/app/selectors/selectors') +const { + sendMetaMetricsEvent, +} = require('../../../ui/app/helpers/utils/metametrics.util') + +const inDevelopment = process.env.NODE_ENV === 'development' + +const METAMETRICS_TRACKING_URL = inDevelopment + ? 'http://www.metamask.io/metametrics' + : 'http://www.metamask.io/metametrics-prod' + +function backEndMetaMetricsEvent (metaMaskState, eventData) { + const stateEventData = getMetaMetricState({ metamask: metaMaskState }) + + if (stateEventData.participateInMetaMetrics) { + sendMetaMetricsEvent({ + ...stateEventData, + ...eventData, + url: METAMETRICS_TRACKING_URL + '/backend', + }) + } +} + +module.exports = backEndMetaMetricsEvent diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 0506e3116..be2090f63 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -54,6 +54,7 @@ const EthQuery = require('eth-query') const ethUtil = require('ethereumjs-util') const sigUtil = require('eth-sig-util') const { AddressBookController } = require('gaba') +const backEndMetaMetricsEvent = require('./lib/backend-metametrics') module.exports = class MetamaskController extends EventEmitter { @@ -190,10 +191,26 @@ module.exports = class MetamaskController extends EventEmitter { }) this.txController.on('newUnapprovedTx', () => opts.showUnapprovedTx()) - this.txController.on(`tx:status-update`, (txId, status) => { + this.txController.on(`tx:status-update`, async (txId, status) => { if (status === 'confirmed' || status === 'failed') { const txMeta = this.txController.txStateManager.getTx(txId) this.platform.showTransactionNotification(txMeta) + + const { txReceipt } = txMeta + const participateInMetaMetrics = this.preferencesController.getParticipateInMetaMetrics() + if (txReceipt && txReceipt.status === '0x0' && participateInMetaMetrics) { + const metamaskState = await this.getState() + backEndMetaMetricsEvent(metamaskState, { + customVariables: { + errorMessage: txMeta.simulationFails.reason, + }, + eventOpts: { + category: 'backend', + action: 'Transactions', + name: 'On Chain Failure', + }, + }) + } } }) |