зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1419996 - remove NEW_TABLE flag and legacy code for the onboarding telemetry r=Fischer,francois
MozReview-Commit-ID: Lb8G8DXRdeh --HG-- extra : rebase_source : 50dcf42ac157efaca54f3d2e0cbc2d78323da562
This commit is contained in:
Родитель
52517c4e6d
Коммит
fd2cb7bd5b
|
@ -14,10 +14,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
|
||||
"@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");
|
||||
|
||||
// Flag to control if we want to send new/old telemetry
|
||||
// TODO: remove this flag and the legacy code in Bug 1419996
|
||||
const NEW_TABLE = true;
|
||||
|
||||
// Validate the content has non-empty string
|
||||
function hasString(str) {
|
||||
return typeof str == "string" && str.length > 0;
|
||||
|
@ -337,44 +333,6 @@ const EVENT_WHITELIST = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* We send 2 kinds (firefox-onboarding-event, firefox-onboarding-session) of pings to ping centre
|
||||
* server (they call it `topic`). The `internal` state in `topic` field means this event is used internaly to
|
||||
* track states and will not send out any message.
|
||||
*
|
||||
* To save server space and make query easier, we track session begin and end but only send pings
|
||||
* when session end. Therefore the server will get single "onboarding/overlay/notification-session"
|
||||
* event which includes both `session_begin` and `session_end` timestamp.
|
||||
*
|
||||
* We send `session_begin` and `session_end` timestamps instead of `session_duration` diff because
|
||||
* of analytics engineer's request.
|
||||
*/
|
||||
const OLD_EVENT_WHITELIST = {
|
||||
// track when click the notification close button
|
||||
"notification-close-button-click": {topic: "firefox-onboarding-event", category: "notification-interactions"},
|
||||
// track when click the notification Call-To-Action button
|
||||
"notification-cta-click": {topic: "firefox-onboarding-event", category: "notification-interactions"},
|
||||
// track when notification is shown
|
||||
"notification-session-begin": {topic: "internal"},
|
||||
// track when the notification closed
|
||||
"notification-session-end": {topic: "firefox-onboarding-session", category: "notification-interactions"},
|
||||
// init onboarding session with session_key and page url
|
||||
"onboarding-register-session": {topic: "internal"},
|
||||
// track when the onboarding script inited
|
||||
"onboarding-session-begin": {topic: "internal"},
|
||||
// track when the onboarding script destoryed
|
||||
"onboarding-session-end": {topic: "firefox-onboarding-session", category: "overlay-interactions"},
|
||||
// track when click the overlay Call-To-Action button
|
||||
"overlay-cta-click": {topic: "firefox-onboarding-event", category: "overlay-interactions"},
|
||||
// track when click or auto select the overlay navigate item
|
||||
"overlay-nav-click": {topic: "firefox-onboarding-event", category: "overlay-interactions"},
|
||||
// track when the overlay is shown
|
||||
"overlay-session-begin": {topic: "internal"},
|
||||
// track when the overlay is closed
|
||||
"overlay-session-end": {topic: "firefox-onboarding-session", category: "overlay-interactions"},
|
||||
// track when click the overlay "skip tour" button
|
||||
"overlay-skip-tour": {topic: "firefox-onboarding-event", category: "overlay-interactions"},
|
||||
};
|
||||
const ONBOARDING_ID = "onboarding";
|
||||
|
||||
let OnboardingTelemetry = {
|
||||
|
@ -385,34 +343,11 @@ let OnboardingTelemetry = {
|
|||
},
|
||||
|
||||
init(startupData) {
|
||||
if (NEW_TABLE) {
|
||||
this.sessionProbe = new PingCentre({topic: "firefox-onboarding-session2"});
|
||||
this.eventProbe = new PingCentre({topic: "firefox-onboarding-event2"});
|
||||
} else {
|
||||
this.sessionProbe = new PingCentre({topic: "firefox-onboarding-session"});
|
||||
this.eventProbe = new PingCentre({topic: "firefox-onboarding-event"});
|
||||
}
|
||||
this.sessionProbe = new PingCentre({topic: "firefox-onboarding-session2"});
|
||||
this.eventProbe = new PingCentre({topic: "firefox-onboarding-event2"});
|
||||
this.state.addon_version = startupData.version;
|
||||
},
|
||||
|
||||
// register per tab session data
|
||||
registerNewTelemetrySession(data) {
|
||||
let { page, session_key, tour_type } = data;
|
||||
if (this.state.sessions[session_key]) {
|
||||
return;
|
||||
}
|
||||
// session_key and page url are must have
|
||||
if (!session_key || !page || !tour_type) {
|
||||
throw new Error("session_key, page url, and tour_type are required for onboarding-register-session");
|
||||
}
|
||||
let session_id = gUUIDGenerator.generateUUID().toString();
|
||||
this.state.sessions[session_key] = {
|
||||
page,
|
||||
session_id,
|
||||
tour_type,
|
||||
};
|
||||
},
|
||||
|
||||
// register per tab session data
|
||||
registerNewOnboardingSession(data) {
|
||||
let { page, session_key, tour_type } = data;
|
||||
|
@ -434,14 +369,6 @@ let OnboardingTelemetry = {
|
|||
},
|
||||
|
||||
process(data) {
|
||||
if (NEW_TABLE) {
|
||||
this.processPings(data);
|
||||
} else {
|
||||
this.processOldPings(data);
|
||||
}
|
||||
},
|
||||
|
||||
processPings(data) {
|
||||
let { type, session_key } = data;
|
||||
if (type === "onboarding-register-session") {
|
||||
this.registerNewOnboardingSession(data);
|
||||
|
@ -619,123 +546,6 @@ let OnboardingTelemetry = {
|
|||
}
|
||||
},
|
||||
|
||||
processOldPings(data) {
|
||||
let { event, session_key } = data;
|
||||
let topic = OLD_EVENT_WHITELIST[event] && OLD_EVENT_WHITELIST[event].topic;
|
||||
if (!topic) {
|
||||
throw new Error(`ping-centre doesn't know ${event}, only knows ${Object.keys(OLD_EVENT_WHITELIST)}`);
|
||||
}
|
||||
|
||||
if (event === "onboarding-register-session") {
|
||||
this.registerNewTelemetrySession(data);
|
||||
}
|
||||
|
||||
if (!this.state.sessions[session_key]) {
|
||||
throw new Error(`should pass valid session_key`);
|
||||
}
|
||||
|
||||
if (topic === "internal") {
|
||||
switch (event) {
|
||||
case "onboarding-session-begin":
|
||||
this.state.sessions[session_key].onboarding_session_begin = Date.now();
|
||||
break;
|
||||
case "overlay-session-begin":
|
||||
this.state.sessions[session_key].overlay_session_begin = Date.now();
|
||||
break;
|
||||
case "notification-session-begin":
|
||||
this.state.sessions[session_key].notification_session_begin = Date.now();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this._sendOldPings(topic, data);
|
||||
}
|
||||
},
|
||||
|
||||
// send out pings by topic
|
||||
_sendOldPings(topic, data) {
|
||||
let {
|
||||
addon_version,
|
||||
} = this.state;
|
||||
let {
|
||||
event,
|
||||
tour_id = "",
|
||||
session_key,
|
||||
} = data;
|
||||
let {
|
||||
notification_session_begin,
|
||||
onboarding_session_begin,
|
||||
overlay_session_begin,
|
||||
page,
|
||||
session_id,
|
||||
tour_type,
|
||||
} = this.state.sessions[session_key];
|
||||
let category = OLD_EVENT_WHITELIST[event].category;
|
||||
// the field is used to identify how user open the overlay (through default logo or watermark),
|
||||
// the number of open from notification can be retrieved via `notification-cta-click` event
|
||||
let tour_source = Services.prefs.getStringPref("browser.onboarding.state", "default");
|
||||
let session_begin;
|
||||
switch (topic) {
|
||||
case "firefox-onboarding-session":
|
||||
switch (event) {
|
||||
case "onboarding-session-end":
|
||||
if (!onboarding_session_begin) {
|
||||
throw new Error(`should fire onboarding-session-begin event before ${event}`);
|
||||
}
|
||||
event = "onboarding-session";
|
||||
session_begin = onboarding_session_begin;
|
||||
delete this.state.sessions[session_key];
|
||||
break;
|
||||
case "overlay-session-end":
|
||||
if (!overlay_session_begin) {
|
||||
throw new Error(`should fire overlay-session-begin event before ${event}`);
|
||||
}
|
||||
event = "overlay-session";
|
||||
session_begin = overlay_session_begin;
|
||||
break;
|
||||
case "notification-session-end":
|
||||
if (!notification_session_begin) {
|
||||
throw new Error(`should fire notification-session-begin event before ${event}`);
|
||||
}
|
||||
event = "notification-session";
|
||||
session_begin = notification_session_begin;
|
||||
break;
|
||||
}
|
||||
|
||||
let session_end = Date.now();
|
||||
this.sessionProbe && this.sessionProbe.sendPing({
|
||||
addon_version,
|
||||
category,
|
||||
event,
|
||||
page,
|
||||
session_begin,
|
||||
session_end,
|
||||
session_id,
|
||||
tour_id,
|
||||
tour_source,
|
||||
tour_type,
|
||||
}, {filter: ONBOARDING_ID});
|
||||
break;
|
||||
case "firefox-onboarding-event":
|
||||
let impression = (event === "notification-close-button-click" ||
|
||||
event === "notification-cta-click") ?
|
||||
Services.prefs.getIntPref("browser.onboarding.notification.prompt-count", 0) : -1;
|
||||
let timestamp = Date.now();
|
||||
this.eventProbe && this.eventProbe.sendPing({
|
||||
addon_version,
|
||||
category,
|
||||
event,
|
||||
impression,
|
||||
page,
|
||||
session_id,
|
||||
timestamp,
|
||||
tour_id,
|
||||
tour_source,
|
||||
tour_type,
|
||||
}, {filter: ONBOARDING_ID});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// validate data sanitation and make sure correct ping params are sent
|
||||
_validatePayload(payload) {
|
||||
let type = payload.type;
|
||||
|
|
Загрузка…
Ссылка в новой задаче