From 2da9acd325c03c78a72de347de133d681316b7ab Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 2 Jul 2021 17:00:40 -0230 Subject: [PATCH] Add some metrics events to the 3box controller (#11447) --- app/scripts/controllers/threebox.js | 43 +++++++++++++++++++++++++++++ app/scripts/metamask-controller.js | 3 ++ 2 files changed, 46 insertions(+) diff --git a/app/scripts/controllers/threebox.js b/app/scripts/controllers/threebox.js index 8355fb4fe..10b231b38 100644 --- a/app/scripts/controllers/threebox.js +++ b/app/scripts/controllers/threebox.js @@ -25,6 +25,7 @@ export default class ThreeBoxController { addressBookController, version, getKeyringControllerState, + trackMetaMetricsEvent, } = opts; this.preferencesController = preferencesController; @@ -59,6 +60,7 @@ export default class ThreeBoxController { ); }, }); + this._trackMetaMetricsEvent = trackMetaMetricsEvent; const initState = { threeBoxSyncingAllowed: false, @@ -83,6 +85,12 @@ export default class ThreeBoxController { async init() { const accounts = await this.keyringController.getAccounts(); this.address = accounts[0]; + + this._trackMetaMetricsEvent({ + event: '3Box Initiated', + category: '3Box', + }); + if (this.address && !(this.box && this.store.getState().threeBoxSynced)) { await this.new3Box(); } @@ -140,8 +148,18 @@ export default class ThreeBoxController { backupExists = threeBoxConfig.spaces && threeBoxConfig.spaces.metamask; } catch (e) { if (e.message.match(/^Error: Invalid response \(404\)/u)) { + this._trackMetaMetricsEvent({ + event: '3Box Backup does not exist', + category: '3Box', + }); + backupExists = false; } else { + this._trackMetaMetricsEvent({ + event: '3Box Config Error', + category: '3Box', + }); + throw e; } } @@ -175,9 +193,19 @@ export default class ThreeBoxController { this.store.updateState(stateUpdate); log.debug('3Box space sync done'); + + this._trackMetaMetricsEvent({ + event: '3Box Synced', + category: '3Box', + }); }, }); } catch (e) { + this._trackMetaMetricsEvent({ + event: '3Box Initiation Error', + category: '3Box', + }); + console.error(e); throw e; } @@ -216,13 +244,28 @@ export default class ThreeBoxController { preferences && this.preferencesController.store.updateState(preferences); addressBook && this.addressBookController.update(addressBook, true); this.setShowRestorePromptToFalse(); + + this._trackMetaMetricsEvent({ + event: '3Box Restored Data', + category: '3Box', + }); } turnThreeBoxSyncingOn() { + this._trackMetaMetricsEvent({ + event: '3Box Sync Turned On', + category: '3Box', + }); + this._registerUpdates(); } turnThreeBoxSyncingOff() { + this._trackMetaMetricsEvent({ + event: '3Box Sync Turned Off', + category: '3Box', + }); + this.box.logout(); } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e0296ca32..76ac3a74e 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -315,6 +315,9 @@ export default class MetamaskController extends EventEmitter { this.keyringController.memStore, ), version, + trackMetaMetricsEvent: this.metaMetricsController.trackEvent.bind( + this.metaMetricsController, + ), }); this.txController = new TransactionController({