Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 35 additions & 41 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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`

Expand All @@ -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:
Expand All @@ -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`
44 changes: 29 additions & 15 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand All @@ -182,6 +195,7 @@ browser.browserAction.onClicked.addListener((e) => {
browser.sidebarAction.open();
} else {
addonIsClosedForWindow[e.id] = true;
closeUI = 'sidebarButton';
browser.sidebarAction.close();
}
});
4 changes: 4 additions & 0 deletions src/sidebar/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down