From f9ba5086a537c4849ba331fbcb345373b583a1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Tue, 23 Jan 2018 15:06:14 +0100 Subject: [PATCH] Upgrading metrics. Fixes #596 --- docs/metrics.md | 76 ++++++++++++++++++++----------------------- src/background.js | 44 ++++++++++++++++--------- src/sidebar/editor.js | 4 +++ 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/docs/metrics.md b/docs/metrics.md index 0cb027219..fa1d139a5 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -34,6 +34,7 @@ Data will be collected with Google Analytics and follow [Test Pilot standards](h - `cd6` - whether the user has, anywhere in their notepad, a list. One of `true` or `false`. - `cd7` - the UI element used to open or close the notepad. Possible values TBD, but may include `closeButton`, `sidebarButton`, and `sidebarSwitcher`. - `cd8` - the reason an editing session ended. One of `timeout` or `closed`. +- `cd9` - whether the user was able to load the note panel or not. One of `true` or `false`. ### Events @@ -42,12 +43,15 @@ An event fired when the user actively navigates to the Notes sidebar. Includes: - `ec` - `notes` - `ea` - `open` +- `cd9` #### `close` An event fired when the user actively navigates away from the Notes sidebar. Includes: - `ec` - `notes` - `ea` - `close` +- `cd7` +- `cd8` #### `changed` An event fired when the user completes a change of the content of the notepad. It prospectively begins when a user focuses on the notepad's editable area, and ends when the user either 1) closes the sidebar, or 2) does not make any changes in 20 seconds. Includes: @@ -63,8 +67,6 @@ An event fired when the user completes a change of the content of the notepad. I - `cd4` - `cd5` - `cd6` -- `cd7` -- `cd8` #### `drag-n-drop` @@ -81,8 +83,6 @@ An event fired when the user tries to drag or drop a content into the notepad. - `cd4` - `cd5` - `cd6` -- `cd7` -- `cd8` #### `sync-started` An event fired whenever the user attempts to login to sync. Includes: @@ -98,62 +98,56 @@ An event fired whenever the user attempts to login to sync. Includes: - `cd5` - `cd6` -#### `sync-enabled` -An event fired whenever the user enables sync. Includes: +#### `login-success` +An event fired whenever the user enables sync successfully. Includes: - `ec` - `notes` -- `ea` - `sync-enabled` -- `cm1` -- `cm2` -- `cd1` -- `cd2` -- `cd3` -- `cd4` -- `cd5` -- `cd6` +- `ea` - `login-success` -#### `sync-disabled` -An event fired whenever the user disables sync. Includes: +#### `login-failed` +An event fired whenever the user enables sync but the FxA login fails. Includes: - `ec` - `notes` -- `ea` - `sync-disabled` -- `cm1` -- `cm2` -- `cd1` -- `cd2` -- `cd3` -- `cd4` -- `cd5` -- `cd6` +- `ea` - `login-failed` #### `theme-changed` An event fired whenever the user changes the theme. Includes: - `ec` - `notes` - `ea` - `theme-changed` -- `cm1` -- `cm2` -- `cd1` -- `cd2` -- `cd3` -- `cd4` -- `cd5` -- `cd6` - -#### `login-success` -An event fired when FxA login succeeds - -#### `login-failed` -An event fired when FxA login fails #### `webext-button-authenticate` An event fired when user presses the sync button +- `ec` - `notes` +- `ea` - `webext-button-authenticate` + #### `webext-button-disconnect` An event fired when user logs out of sync +- `ec` - `notes` +- `ea` - `webext-button-disconnect` + #### `handle-conflict` An event fired when sync resolved a sync conflict +- `ec` - `notes` +- `ea` - `handle-conflict` + #### `reconnect-sync` -An event fired when user loses sync due to a password reset or change +An event fired when user closes sync due to a password reset or change + +- `ec` - `notes` +- `ea` - `reconnect-sync` + +#### `metrics-migrated` +An event fired when the user migrate from Quill.JS to CKEditor + +- `ec` - `notes` +- `ea` - `metrics-migrated` + +#### `metrics-migrated-before` +An event fired when the migration from Quill.JS to CKEditor already happened + +- `ec` - `notes` +- `ea` - `metrics-migrated-before` diff --git a/src/background.js b/src/background.js index 9974b2ae3..30c9561d6 100644 --- a/src/background.js +++ b/src/background.js @@ -11,6 +11,7 @@ const FXA_OAUTH_SERVER = 'https://oauth.accounts.firefox.com/v1'; const FXA_PROFILE_SERVER = 'https://profile.accounts.firefox.com/v1'; const FXA_SCOPES = ['profile', 'https://identity.mozilla.com/apps/notes']; const timeouts = {}; +let closeUI = null; // Kinto sync and encryption @@ -31,19 +32,28 @@ function sendMetrics(event, context = {}) { const later = function() { timeouts[event] = null; - return analytics.sendEvent('notes', event, { - cm1: context.characters, - cm2: context.lineBreaks, - cm3: null, // Size of the change - cd1: context.syncEnabled, - cd2: context.usesSize, - cd3: context.usesBold, - cd4: context.usesItalics, - cd5: context.usesStrikethrough, - cd6: context.usesList, - cd7: null, // Firefox UI used to open, close notepad - cd8: null, // reason editing session ended - }); + let metrics = {}; + + if (event === 'open') { + metrics.cd9 = context.loaded === false ? false : true; + } else if (event === 'close') { + metrics.cd7 = context.closeUI; + metrics.cd8 = null; // reason editing session ended + } else if (event === 'changed' || event === 'drag-n-drop') { // Editing + metrics = { + cm1: context.characters, + cm2: context.lineBreaks, + cm3: null, // Size of the change + cd1: context.syncEnabled, + cd2: context.usesSize, + cd3: context.usesBold, + cd4: context.usesItalics, + cd5: context.usesStrikethrough, + cd6: context.usesList, + }; + } + + return analytics.sendEvent('notes', event, metrics); }; clearTimeout(timeouts[event]); timeouts[event] = setTimeout(later, 20000); @@ -118,6 +128,8 @@ browser.runtime.onMessage.addListener(function(eventData) { data: result && typeof result.data !== 'undefined' ? result.data.content : null, last_modified: result && typeof result.data !== 'undefined' && typeof result.data.last_modified !== 'undefined' ? result.data.last_modified : null, }); + }).catch(() => { + sendMetrics('open', {loaded: false}); }); break; case 'kinto-sync': @@ -154,10 +166,11 @@ const addonIsClosedForWindow = {}; // Handle opening and closing the add-on. function connected(p) { - sendMetrics('open'); + sendMetrics('open', {loaded: true}); + closeUI = 'closeButton'; p.onDisconnect.addListener(() => { - sendMetrics('close'); + sendMetrics('close', {'closeUI': closeUI}); }); } browser.runtime.onConnect.addListener(connected); @@ -182,6 +195,7 @@ browser.browserAction.onClicked.addListener((e) => { browser.sidebarAction.open(); } else { addonIsClosedForWindow[e.id] = true; + closeUI = 'sidebarButton'; browser.sidebarAction.close(); } }); diff --git a/src/sidebar/editor.js b/src/sidebar/editor.js index 3290b1b4d..b9a139bd4 100644 --- a/src/sidebar/editor.js +++ b/src/sidebar/editor.js @@ -29,6 +29,10 @@ function customizeEditor(editor) { document.addEventListener('drop', () => { editor.fire('changesDone'); mainEditor.classList.remove('drag-n-drop-focus'); + browser.runtime.sendMessage({ + action: 'metrics-drag-n-drop', + context: getPadStats(editor) + }); }); localizeEditorButtons();