fix #209: page-requests-completed-per-tab metric

This commit is contained in:
groovecoder 2017-03-16 13:46:51 -05:00
parent 52ceef8586
commit 5e94941377
3 changed files with 52 additions and 3 deletions

View file

@ -49,7 +49,7 @@ whether they are actively interacting with it.
* Average number of container tabs when new window was clicked * Average number of container tabs when new window was clicked
* How many containers do users have hidden at the same time? (when should we measure this? each time a container is hidden?) * How many containers do users have hidden at the same time? (when should we measure this? each time a container is hidden?)
* Do users pin container tabs? (do we have existing Telemetry for pinning?) * Do users pin container tabs? (do we have existing Telemetry for pinning?)
* Do users change URLs in a container tab? (sounds like it could be a flood unless we only record the first URL change?) * Do users visit more pages in container tabs than non-container tabs?
### Follow-up Questions ### Follow-up Questions
@ -178,6 +178,17 @@ of a `testpilottest` telemetry ping for each scenario.
} }
``` ```
* The user closes a tab
```js
{
"uuid": <uuid>,
"userContextId": <userContextId>,
"event": "page-requests-completed-per-tab",
"pageRequestCount": <pageRequestCount>
}
```
### A Redshift schema for the payload: ### A Redshift schema for the payload:
```lua ```lua
@ -188,6 +199,7 @@ local schema = {
{"clickedContainerTabCount", "INTEGER", 255, nil, "Fields[payload.clickedContainerTabCount]"}, {"clickedContainerTabCount", "INTEGER", 255, nil, "Fields[payload.clickedContainerTabCount]"},
{"eventSource", "VARCHAR", 255, nil, "Fields[payload.eventSource]"}, {"eventSource", "VARCHAR", 255, nil, "Fields[payload.eventSource]"},
{"event", "VARCHAR", 255, nil, "Fields[payload.event]"}, {"event", "VARCHAR", 255, nil, "Fields[payload.event]"},
{"pageRequestCount", "INTEGER", 255, nil, "Fields[payload.pageRequestCount]"}
{"hiddenContainersCount", "INTEGER", 255, nil, "Fields[payload.hiddenContainersCount]"}, {"hiddenContainersCount", "INTEGER", 255, nil, "Fields[payload.hiddenContainersCount]"},
{"shownContainersCount", "INTEGER", 255, nil, "Fields[payload.shownContainersCount]"}, {"shownContainersCount", "INTEGER", 255, nil, "Fields[payload.shownContainersCount]"},
{"totalContainersCount", "INTEGER", 255, nil, "Fields[payload.totalContainersCount]"}, {"totalContainersCount", "INTEGER", 255, nil, "Fields[payload.totalContainersCount]"},

View file

@ -1,4 +1,3 @@
const themeManager = { const themeManager = {
existingTheme: null, existingTheme: null,
init() { init() {
@ -43,7 +42,43 @@ const themeManager = {
} }
}; };
const tabPageCounter = {
counter: {},
init() {
browser.tabs.onCreated.addListener(this.initTabCounter.bind(this));
browser.tabs.onRemoved.addListener(this.sendTabCountAndDelete.bind(this));
browser.webRequest.onCompleted.addListener(this.incrementTabCount.bind(this), {urls: ["<all_urls>"], types: ["main_frame"]});
},
initTabCounter(tab) {
this.counter[tab.id] = {
"cookieStoreId": tab.cookieStoreId,
"pageRequests": 0
};
},
sendTabCountAndDelete(tab) {
browser.runtime.sendMessage({
method: "sendTelemetryPayload",
event: "page-requests-completed-per-tab",
userContextId: this.counter[tab].cookieStoreId,
pageRequestCount: this.counter[tab].pageRequests
});
delete this.counter[tab.id];
},
incrementTabCount(details) {
browser.tabs.get(details.tabId).then(tab => {
this.counter[tab.id].pageRequests++;
}).catch(e => {
throw e;
});
}
};
themeManager.init(); themeManager.init();
tabPageCounter.init();
browser.runtime.sendMessage({ browser.runtime.sendMessage({
method: "getPreference", method: "getPreference",

View file

@ -20,7 +20,9 @@
"permissions": [ "permissions": [
"cookies", "cookies",
"tabs" "tabs",
"webRequest",
"<all_urls>"
], ],
"browser_action": { "browser_action": {