Bug 1412164 - add new column for onboarding telemetry;r=fischer,liuche draft
authorFred Lin <gasolin@gmail.com>
Fri, 27 Oct 2017 10:20:34 +0800
changeset 688535 ddec74036dc385ba158e4798d2621d967a7ee3e3
parent 688337 d3910b7628b8066d3f30d58b17b5824b05768854
child 738091 08746a598cdc6200e8ea9c791aef29f979ae3791
push id86772
push userbmo:gasolin@mozilla.com
push dateMon, 30 Oct 2017 07:27:04 +0000
reviewersfischer, liuche
bugs1412164
milestone58.0a1
Bug 1412164 - add new column for onboarding telemetry;r=fischer,liuche MozReview-Commit-ID: aqeoxjR7Tu
browser/extensions/onboarding/OnboardingTelemetry.jsm
browser/extensions/onboarding/content/onboarding.js
browser/extensions/onboarding/data_events.md
--- a/browser/extensions/onboarding/OnboardingTelemetry.jsm
+++ b/browser/extensions/onboarding/OnboardingTelemetry.jsm
@@ -49,58 +49,59 @@ const EVENT_WHITELIST = {
   "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_STATE_DEFAULT = "default";
 const ONBOARDING_ID = "onboarding";
 
 let OnboardingTelemetry = {
   sessionProbe: null,
   eventProbe: null,
   state: {
     sessions: {},
   },
 
   init(startupData) {
     this.sessionProbe = new PingCentre({topic: "firefox-onboarding-session"});
     this.eventProbe = new PingCentre({topic: "firefox-onboarding-event"});
     this.state.addon_version = startupData.version;
   },
 
   // register per tab session data
-  registerNewTelemetrySession(session_key, page) {
+  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) {
-      throw new Error("session_key and page url are required for onboarding-register-session");
+    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,
-      page,
+      tour_type,
     };
   },
 
   process(data) {
-    let { event, page, session_key } = data;
+    let { event, session_key } = data;
 
     let topic = EVENT_WHITELIST[event] && EVENT_WHITELIST[event].topic;
     if (!topic) {
       throw new Error(`ping-centre doesn't know ${event}, only knows ${Object.keys(EVENT_WHITELIST)}`);
     }
 
     if (event === "onboarding-register-session") {
-      this.registerNewTelemetrySession(session_key, page);
+      this.registerNewTelemetrySession(data);
     }
 
     if (!this.state.sessions[session_key]) {
       throw new Error(`should pass valid session_key`);
     }
 
     if (topic === "internal") {
       switch (event) {
@@ -130,18 +131,22 @@ let OnboardingTelemetry = {
       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 = 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}`);
             }
@@ -160,42 +165,43 @@ let OnboardingTelemetry = {
             if (!notification_session_begin) {
               throw new Error(`should fire notification-session-begin event before ${event}`);
             }
             event = "notification-session";
             session_begin = notification_session_begin;
             break;
         }
 
-        // 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
-        const tour_source = Services.prefs.getStringPref("browser.onboarding.state",
-          ONBOARDING_STATE_DEFAULT);
-        const session_end = Date.now();
+        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;
     }
   }
 };
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -396,16 +396,17 @@ class Onboarding {
     this._window.addEventListener("unload", () => this.destroy());
 
     this.uiInitialized = false;
     this._resizeTimerId =
       this._window.requestIdleCallback(() => this._resizeUI());
     registerNewTelemetrySession({
       page: this._window.location.href,
       session_key: this._session_key,
+      tour_type: Services.prefs.getStringPref("browser.onboarding.tour-type", "update"),
     });
     telemetry({
       event: "onboarding-session-begin",
       session_key: this._session_key,
     });
   }
 
   _resizeUI() {
--- a/browser/extensions/onboarding/data_events.md
+++ b/browser/extensions/onboarding/data_events.md
@@ -19,40 +19,44 @@ For reference, Onyx is a Mozilla owned s
   "category": ["overlay-interactions"|"notification-interactions"],
   "client_id": "374dc4d8-0cb2-4ac5-a3cf-c5a9bc3c602e",
   "locale": "en-US",
   "event": ["onboarding_session" | "overlay_session" | "notification_session"],
   "page": ["about:newtab" | "about:home"],
   "session_begin": 1505440017018,
   "session_end": 1505440021992,
   "session_id": "{12dasd-213asda-213dkakj}",
+  "tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset'
   "tour_source": ["default" | "watermark"],
-  "tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset'
+  "tour_type" ["new" | "update"],
 
   // These fields are generated on the server
   "date": "2016-03-07",
   "ip": "10.192.171.13",
   "ua": "python-requests/2.9.1",
   "receive_at": 1457396660000
 }
 ```
 
 # Example Onboarding `event` Log
 
 ```js
 {
   "addon_version": "1.0.0",
   "category": ["overlay-interactions"|"notification-interactions"],
   "client_id": "374dc4d8-0cb2-4ac5-a3cf-c5a9bc3c602e",
+  "timestamp": 1505440017019,
   "event": ["notification-cta-click" | "overlay-cta-click" | "overlay-nav-click" | "overlay-skip-tour"],
   "impression": [0-8],
   "locale": "en-US",
   "page": ["about:newtab" | "about:home"],
   "session_id": "{12dasd-213asda-213dkakj}",
   "tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset'
+  "tour_source": ["default" | "watermark"],
+  "tour_type" ["new" | "update"],
 
   // These fields are generated on the server
   "ip": "10.192.171.13",
   "ua": "python-requests/2.9.1",
   "receive_at": 1457396660000,
   "date": "2016-03-07",
 }
 ```
@@ -66,18 +70,20 @@ For reference, Onyx is a Mozilla owned s
 | `event` | [Required] The type of event. allowed event strings are defined in the below section | :one:
 | `impression` | [Optional] An integer to record how many times the current notification tour is shown to the user. Each Notification tour can show not more than 8 times. We put `-1` when this field is not relevant to this event | :one:
 | `ip` | [Auto populated by Onyx] The IP address of the client. Onyx does use (with the permission) the IP address to infer user's geo information so that it could prepare the corresponding tiles for the country she lives in. However, Ping-centre will NOT store IP address in the database, where only authorized Mozilla employees can access the telemetry data, and all the raw logs are being strictly managed by the Ops team and will expire according to the Mozilla's data retention policy.| :two:
 | `locale` | The browser chrome's language (eg. en-US). | :two:
 | `page` | [Required] One of ["about:newtab", "about:home"]| :one:
 | `session_begin` | Timestamp in (integer) milliseconds when onboarding/overlay/notification becoming visible. | :one:
 | `session_end` | Timestamp in (integer) milliseconds when onboarding/overlay/notification losing focus. | :one:
 | `session_id` | [Required] The unique identifier generated by `gUUIDGenerator` service to identify the specific user session when onboarding is inited/when overlay is opened/when notification is shown. | :one:
-| `tour_source` | Either ("default", "watermark") indicates the overlay is opened while in the default or the watermark state. Open from the notification bar is counted via 'notification-cta-click event'. | :two:
-| `tour_id` | id of the current tour. The number of open from notification can be retrieved via 'notification-cta-click event'. We put ` ` when this field is not relevant to this event | :two:
+| `timestamp` | Timestamp in (integer) milliseconds when the event triggered | :one:
+| `tour_id` | id of the current tour. The number of open from notification can be retrieved via 'notification-cta-click event'. We put ` ` when this field is not relevant to this event | :one:
+| `tour_source` | [Required] One of ["default", "watermark"] indicates the overlay is opened while in the default or the watermark state. Open from the notification bar is counted via 'notification-cta-click event'. | :one:
+| `tour_type` | [Required] One of ["new", "update"] indicates the user is a `new` user or the `update` user upgrade from the older version | :one:
 | `ua` | [Auto populated by Onyx] The user agent string. | :two:
 | `ver` | [Auto populated by Onyx] The version of the Onyx API the ping was sent to. | :one:
 
 **Where:**
 
 :one: Firefox data
 :two: HTTP protocol data