Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
fix(addon): #707 Provide more specific unload_reason other than navig…
Browse files Browse the repository at this point in the history
…ation

close #745
  • Loading branch information
ncloudioj committed May 27, 2016
1 parent 9297b76 commit a029fac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
6 changes: 3 additions & 3 deletions data_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ All `"activity_stream_session"` pings have the following basic shape. Some field

Here are different scenarios that cause a session end event to be sent and the corresponding `"unload_reason"` included in the ping:

1. After a search: `"navigation"`
2. Clicking on something (top site, highlight, activity feed item): `"navigation"`
1. After a search: `"search"`
2. Clicking on something (top site, highlight, activity feed item): `"click"`
3. Switching to another tab: `"unfocus"`
4. Closing the browser: `"unfocus"`
4. Closing the browser: `"close"`
5. Refreshing: `"refresh"`
6. Navigating to a new URL via the url bar: `"navigation"`
7 changes: 6 additions & 1 deletion lib/TabTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ TabTracker.prototype = {
payload.tab_id = tabs.activeTab.id;
this._setCommonProperties(payload, tabs.activeTab.url);
Services.obs.notifyObservers(null, ACTION_NOTIF, JSON.stringify(payload));
if (payload.event === "SEARCH" || payload.event === "CLICK") {
this._tabData.unload_reason = payload.event.toLowerCase();
}
},

handleRouteChange(tab, route) {
Expand All @@ -115,7 +118,9 @@ TabTracker.prototype = {
// we have to use the URL stored in this._openTabs object
this._setCommonProperties(this._tabData, this._openTabs[tab.id].url);
this._tabData.action = "activity_stream_session";
this._tabData.unload_reason = reason;
// unload_reason could be set in "handleUserEvent" for certain user events
// in order to provide the more sepcific reasons other than "navigation"
this._tabData.unload_reason = this._tabData.unload_reason || reason;

if (!this._tabData.tab_id) {
// We're navigating away from an activity streams page that
Expand Down
37 changes: 37 additions & 0 deletions test/test-TabTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,43 @@ exports.test_TabTracker_action_pings = function*(assert) {
assert.deepEqual(eventData.msg.data, pingData, "We receive the expected ping data.");
};

exports.test_TabTracker_unload_reason_with_user_action = function*(assert) {
let events = ["CLICK", "SEARCH"];
for (let event of events) {
tabs.open(ACTIVITY_STREAMS_URL);
let userEventPromise = new Promise(resolve => {
function observe(subject, topic, data) {
if (topic === "user-action-event") {
Services.obs.removeObserver(observe, "user-action-event");
resolve(JSON.parse(data));
}
}
Services.obs.addObserver(observe, "user-action-event");
});

let eventData = {
msg: {
data: {
source: "topsites",
action_position: 3,
event: event
}
}
};
app._handleUserEvent("NOTIFY_USER_EVENT", eventData);

let pingData = yield userEventPromise;
let additionalKeys = ["client_id", "addon_version", "locale", "action", "tab_id", "page"];
for (let key of additionalKeys) {
assert.ok(pingData[key], `The ping has the additional key ${key}`);
}
assert.deepEqual(eventData.msg.data, pingData, "We receive the expected ping data.");

pingData = yield waitForPageShowAndSessionComplete();
checkLoadUnloadReasons(assert, [pingData], ["newtab"], [event.toLowerCase()], false);
}
};

exports.test_TabTracker_handleRouteChange_FirstLoad = function(assert) {
assert.deepEqual(app.tabData, {}, "tabData starts out empty");
app._tabTracker.handleRouteChange({}, {isFirstLoad: true});
Expand Down

0 comments on commit a029fac

Please sign in to comment.