for #117: start telemetry with testpilot-metrics

and first sort-tabs event
This commit is contained in:
groovecoder 2017-02-09 10:59:29 -06:00
parent 37b2adeb4b
commit 18b3a3ad63
3 changed files with 70 additions and 2 deletions

1
.eslintignore Normal file
View file

@ -0,0 +1 @@
testpilot-metrics.js

View file

@ -34,6 +34,7 @@ const PREFS = [
const { attachTo, detachFrom } = require("sdk/content/mod"); const { attachTo, detachFrom } = require("sdk/content/mod");
const { ContextualIdentityService } = require("resource://gre/modules/ContextualIdentityService.jsm"); const { ContextualIdentityService } = require("resource://gre/modules/ContextualIdentityService.jsm");
const { getFavicon } = require("sdk/places/favicon"); const { getFavicon } = require("sdk/places/favicon");
const Metrics = require("./testpilot-metrics");
const { modelFor } = require("sdk/model/core"); const { modelFor } = require("sdk/model/core");
const prefService = require("sdk/preferences/service"); const prefService = require("sdk/preferences/service");
const self = require("sdk/self"); const self = require("sdk/self");
@ -41,11 +42,13 @@ const ss = require("sdk/simple-storage");
const { Style } = require("sdk/stylesheet/style"); const { Style } = require("sdk/stylesheet/style");
const tabs = require("sdk/tabs"); const tabs = require("sdk/tabs");
const tabsUtils = require("sdk/tabs/utils"); const tabsUtils = require("sdk/tabs/utils");
const uuid = require("sdk/util/uuid");
const { viewFor } = require("sdk/view/core"); const { viewFor } = require("sdk/view/core");
const webExtension = require("sdk/webextension"); const webExtension = require("sdk/webextension");
const windows = require("sdk/windows"); const windows = require("sdk/windows");
const windowUtils = require("sdk/window/utils"); const windowUtils = require("sdk/window/utils");
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ContainerService // ContainerService
@ -60,13 +63,16 @@ const ContainerService = {
if (installation) { if (installation) {
const object = { const object = {
version: 1, version: 1,
prefs: {} prefs: {},
metricsUUID: null
}; };
PREFS.forEach(pref => { PREFS.forEach(pref => {
object.prefs[pref[0]] = prefService.get(pref[0]); object.prefs[pref[0]] = prefService.get(pref[0]);
}); });
object.metricsUUID = uuid.uuid().toString();
ss.storage.savedConfiguration = object; ss.storage.savedConfiguration = object;
} }
@ -76,6 +82,15 @@ const ContainerService = {
prefService.set(pref[0], pref[1]); prefService.set(pref[0], pref[1]);
}); });
if (ss.storage.savedConfiguration.hasOwnProperty("metricsUUID")) {
this._metricsUUID = ss.storage.savedConfiguration.metricsUUID;
} else {
// The add-on was installed before metricsUUID was added, create one
this._metricsUUID = uuid.uuid().toString();
ss.storage.savedConfiguration["metricsUUID"] = this._metricsUUID;
}
// Message routing // Message routing
// only these methods are allowed. We have a 1:1 mapping between messages // only these methods are allowed. We have a 1:1 mapping between messages
@ -158,10 +173,55 @@ const ContainerService = {
}).catch(() => { }).catch(() => {
throw new Error("WebExtension startup failed. Unable to continue."); throw new Error("WebExtension startup failed. Unable to continue.");
}); });
this._sendEvent = new Metrics({
type: "sdk",
id: self.id,
version: self.version
}).sendEvent;
this._sendTelemetryPayload = function(params = {}) {
let payload = { // eslint-disable-line prefer-const
"uuid": this._metricsUUID
};
Object.assign(payload, params);
this._sendEvent(payload);
};
}, },
// utility methods // utility methods
_totalContainerTabsCount() {
let totalContainerTabsCount = 0;
for (const userContextId in this._identitiesState) {
totalContainerTabsCount += this._identitiesState[userContextId].openTabs;
}
return totalContainerTabsCount;
},
_totalNonContainerTabsCount() {
let totalNonContainerTabsCount = 0;
for (const tab of tabs) {
if (this._getUserContextIdFromTab(tab) === 0) {
++totalNonContainerTabsCount;
}
}
return totalNonContainerTabsCount;
},
_shownContainersCount() {
let shownContainersCount = 0;
for (const userContextId in this._identitiesState) {
if (this._identitiesState[userContextId].openTabs > 0) {
++shownContainersCount;
continue;
}
}
return shownContainersCount;
},
_convert(identity) { _convert(identity) {
// Let's convert the known colors to their color names. // Let's convert the known colors to their color names.
return { return {
@ -350,6 +410,12 @@ const ContainerService = {
}, },
sortTabs() { sortTabs() {
this._sendTelemetryPayload({
"event": "sort-tabs",
"shownContainersCount": this._shownContainersCount(),
"totalContainerTabsCount": this._totalContainerTabsCount(),
"totalNonContainerTabsCount": this._totalNonContainerTabsCount()
});
return new Promise(resolve => { return new Promise(resolve => {
for (let window of windows.browserWindows) { // eslint-disable-line prefer-const for (let window of windows.browserWindows) { // eslint-disable-line prefer-const
// First the pinned tabs, then the normal ones. // First the pinned tabs, then the normal ones.

View file

@ -16,7 +16,8 @@
"jpm": "^1.2.2", "jpm": "^1.2.2",
"npm-run-all": "^4.0.0", "npm-run-all": "^4.0.0",
"stylelint": "^7.7.1", "stylelint": "^7.7.1",
"stylelint-config-standard": "^15.0.1" "stylelint-config-standard": "^15.0.1",
"testpilot-metrics": "^2.1.0"
}, },
"engines": { "engines": {
"firefox": ">=50.0" "firefox": ">=50.0"