Skip to content

Commit

Permalink
Merge pull request #389 from mozilla/add-page-requests-metric-209
Browse files Browse the repository at this point in the history
WIP/DNM: Add page requests metric 209
  • Loading branch information
groovecoder authored Mar 30, 2017
2 parents 7de6ef5 + 5e94941 commit 9e1da08
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
14 changes: 13 additions & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ whether they are actively interacting with it.
* 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?)
* 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

Expand Down Expand Up @@ -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:

```lua
Expand All @@ -188,6 +199,7 @@ local schema = {
{"clickedContainerTabCount", "INTEGER", 255, nil, "Fields[payload.clickedContainerTabCount]"},
{"eventSource", "VARCHAR", 255, nil, "Fields[payload.eventSource]"},
{"event", "VARCHAR", 255, nil, "Fields[payload.event]"},
{"pageRequestCount", "INTEGER", 255, nil, "Fields[payload.pageRequestCount]"}
{"hiddenContainersCount", "INTEGER", 255, nil, "Fields[payload.hiddenContainersCount]"},
{"shownContainersCount", "INTEGER", 255, nil, "Fields[payload.shownContainersCount]"},
{"totalContainersCount", "INTEGER", 255, nil, "Fields[payload.totalContainersCount]"},
Expand Down
37 changes: 36 additions & 1 deletion webextension/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const themeManager = {
existingTheme: null,
init() {
Expand Down Expand Up @@ -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();
tabPageCounter.init();

browser.runtime.sendMessage({
method: "getPreference",
Expand Down
4 changes: 3 additions & 1 deletion webextension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

"permissions": [
"cookies",
"tabs"
"tabs",
"webRequest",
"<all_urls>"
],

"browser_action": {
Expand Down

0 comments on commit 9e1da08

Please sign in to comment.