for #321: only send activity page counts for tabs that were activated
This commit is contained in:
parent
f2a82cb6be
commit
6282201b2c
1 changed files with 28 additions and 22 deletions
|
@ -283,10 +283,10 @@ const messageHandler = {
|
|||
browser.idle.onStateChanged.addListener((newState) => {
|
||||
browser.tabs.query({}).then(tabs => {
|
||||
for (let tab of tabs) { // eslint-disable-line prefer-const
|
||||
if (newState === "idle" || newState === "locked") {
|
||||
if (newState === "idle") {
|
||||
tabPageCounter.sendTabCountAndDelete(tab.id, "user-went-idle");
|
||||
} else if (newState === "active") {
|
||||
tabPageCounter.initTabCounter(tab, "user-became-active");
|
||||
} else if (newState === "active" && tab.active) {
|
||||
tabPageCounter.initTabCounter(tab);
|
||||
}
|
||||
}
|
||||
}).catch(e => {
|
||||
|
@ -349,19 +349,21 @@ const themeManager = {
|
|||
const tabPageCounter = {
|
||||
counters: {},
|
||||
|
||||
initTabCounter(tab, why = "user-activated-tab") {
|
||||
// When the user becomes active,
|
||||
// we ONLY need to initialize the activity counter
|
||||
if (tab.id in this.counters && why === "user-became-active") {
|
||||
initTabCounter(tab) {
|
||||
if (tab.id in this.counters) {
|
||||
if (!("activity" in this.counters[tab.id])) {
|
||||
this.counters[tab.id].activity = {
|
||||
"cookieStoreId": tab.cookieStoreId,
|
||||
"pageRequests": 0
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (tab.id in this.counters) {
|
||||
return;
|
||||
if (!("tab" in this.counters[tab.id])) {
|
||||
this.counters[tab.id].tab = {
|
||||
"cookieStoreId": tab.cookieStoreId,
|
||||
"pageRequests": 0
|
||||
};
|
||||
}
|
||||
} else {
|
||||
this.counters[tab.id] = {};
|
||||
this.counters[tab.id].tab = {
|
||||
"cookieStoreId": tab.cookieStoreId,
|
||||
|
@ -371,10 +373,14 @@ const tabPageCounter = {
|
|||
"cookieStoreId": tab.cookieStoreId,
|
||||
"pageRequests": 0
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
sendTabCountAndDelete(tabId, why = "user-closed-tab") {
|
||||
if (why === "user-closed-tab") {
|
||||
if (!(this.counters[tabId])) {
|
||||
return;
|
||||
}
|
||||
if (why === "user-closed-tab" && this.counters[tabId].tab) {
|
||||
browser.runtime.sendMessage({
|
||||
method: "sendTelemetryPayload",
|
||||
event: "page-requests-completed-per-tab",
|
||||
|
@ -384,7 +390,7 @@ const tabPageCounter = {
|
|||
// When we send the ping because the user closed the tab,
|
||||
// delete both the 'tab' and 'activity' counters
|
||||
delete this.counters[tabId];
|
||||
} else if (why === "user-went-idle") {
|
||||
} else if (why === "user-went-idle" && this.counters[tabId].activity) {
|
||||
browser.runtime.sendMessage({
|
||||
method: "sendTelemetryPayload",
|
||||
event: "page-requests-completed-per-activity",
|
||||
|
|
Loading…
Add table
Reference in a new issue