Bug 1389424 - enable onboarding telemetry via ping-centre;r=emtwo,fischer,liuche draft
authorgasolin <gasolin@gmail.com>
Thu, 31 Aug 2017 10:19:04 +0800
changeset 675917 1a291b5d0da9b115da99308e24c78c16058d41bc
parent 675916 7cfafd690c1f0e32eecdbd846942607ab7fff5d6
child 734765 196721997f973b096770263107237629d3b7b92e
push id83302
push userbmo:gasolin@mozilla.com
push dateFri, 06 Oct 2017 07:51:49 +0000
reviewersemtwo, fischer, liuche
bugs1389424
milestone58.0a1
Bug 1389424 - enable onboarding telemetry via ping-centre;r=emtwo,fischer,liuche MozReview-Commit-ID: KWRCnD4lFh9
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
@@ -26,32 +26,32 @@ XPCOMUtils.defineLazyServiceGetter(this,
  * 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 EVENT_WHITELIST = {
   // track when click the notification CTA button
   "notification-cta-click": {topic: "firefox-onboarding-event", category: "notification-interactions"},
-  // track when the notification closed
-  "notification-session": {topic: "firefox-onboarding-session", category: "notification-interactions"},
   // track when notification is shown
   "notification-session-begin": {topic: "internal"},
-  // track when the onboarding script destoryed
-  "onboarding-session": {topic: "firefox-onboarding-session", category: "overlay-interactions"},
+  // track when the notification closed
+  "notification-session-end": {topic: "firefox-onboarding-session", category: "notification-interactions"},
   // 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 CTA 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 closed
-  "overlay-session": {topic: "firefox-onboarding-session", 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 ICON_STATE_DEFAULT = "default";
 const PROMPT_COUNT_PREF = "browser.onboarding.notification.prompt-count";
 const ONBOARDING_ID = "onboarding";
 
 var OnboardingTelemetry = {
@@ -122,24 +122,27 @@ var OnboardingTelemetry = {
       page,
       session_id,
     } = this.state.sessions[session_key];
     let category = EVENT_WHITELIST[event].category;
     let session_begin;
     switch (topic) {
       case "firefox-onboarding-session":
         switch (event) {
-          case "onboarding-session":
+          case "onboarding-session-end":
+            event = "onboarding-session";
             session_begin = onboarding_session_begin;
             delete this.state.sessions[session_key];
             break;
-          case "overlay-session":
+          case "overlay-session-end":
+            event = "overlay-session";
             session_begin = overlay_session_begin;
             break;
-          case "notification-session":
+          case "notification-session-end":
+            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", ICON_STATE_DEFAULT);
         const session_end = Date.now();
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -355,19 +355,18 @@ function telemetry (data) {
 class Onboarding {
   constructor(contentWindow) {
     this.init(contentWindow);
   }
 
   async init(contentWindow) {
     this._window = contentWindow;
     // session_key is used for telemetry to track the current tab.
-    // A large random number provides sparse ids.
     // The number will renew after reload the page.
-    this._session_key = Math.floor(Math.random() * 100000);
+    this._session_key = Date.now();
     this._tours = [];
     this._tourType = Services.prefs.getStringPref("browser.onboarding.tour-type", "update");
 
     let tourIds = this._getTourIDList();
     tourIds.forEach(tourId => {
       if (onboardingTourset[tourId]) {
         this._tours.push(onboardingTourset[tourId]);
       }
@@ -689,17 +688,17 @@ class Onboarding {
     this._overlayIcon.remove();
     this._overlay.remove();
     if (this._notificationBar) {
       this._notificationBar.remove();
     }
     this._tourItems = this._tourPages =
     this._overlayIcon = this._overlay = this._notificationBar = null;
     telemetry({
-      event: "onboarding-session",
+      event: "onboarding-session-end",
       session_key: this._session_key,
     });
   }
 
   _onIconStateChange(state) {
     switch (state) {
       case ICON_STATE_DEFAULT:
         this._overlayIcon.classList.remove("onboarding-watermark");
@@ -723,17 +722,17 @@ class Onboarding {
       event: "overlay-session-begin",
       session_key: this._session_key
     });
   }
 
   hideOverlay() {
     this.toggleModal(this._overlay.classList.toggle("onboarding-opened"));
     telemetry({
-      event: "overlay-session",
+      event: "overlay-session-end",
       session_key: this._session_key,
     });
   }
 
   /**
    * Set modal dialog state and properties for accessibility purposes.
    * @param  {Boolean} opened  whether the dialog is opened or closed.
    */
@@ -1051,17 +1050,17 @@ class Onboarding {
     });
   }
 
   hideNotification() {
     if (this._notificationBar) {
       if (this._notificationBar.classList.contains("onboarding-opened")) {
         this._notificationBar.classList.remove("onboarding-opened");
         telemetry({
-          event: "notification-session",
+          event: "notification-session-end",
           tour_id: this._notificationBar.dataset.targetTourId,
           session_key: this._session_key,
         });
       }
     }
   }
 
   _renderNotificationBar() {
--- a/browser/extensions/onboarding/data_events.md
+++ b/browser/extensions/onboarding/data_events.md
@@ -71,34 +71,44 @@ For reference, Onyx is a Mozilla owned s
 | `session_begin` | Time in (integer) milliseconds when onboarding/overlay/notification becoming visible. | :one:
 | `session_end` | Time 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` | Either ("default", "watermark") indicates how the overlay is triggered. The number of open from notification can be retrieved via 'notification-cta-click event'. | :two:
 | `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
+
 ## Events
 
 Here are all allowed `event` strings that defined in `OnboardingTelemetry::EVENT_WHITELIST`.
 ### Session events
 
-* `onboarding-session-begin` internal event triggered when the onboarding script is inited, will not send out any data.
-* `onboarding-session` event is sent when the onboarding script is destoryed
+| EVENT | DESCRIPTION |
+|-----------|---------------------|
+| `onboarding-session-begin` | internal event triggered when the onboarding script is inited, will not send out any data. |
+| `onboarding-session-end` | internal event triggered when the onboarding script is destoryed. `onboarding-session` event is sent to the server. |
+| `onboarding-session` | event is sent when the onboarding script is destoryed |
 
 ### Overlay events
 
-* `overlay-session-begin` internal event triggered when user open the overlay, will not send out any data.
-* `overlay-session` event is sent when user close the overlay
-* `overlay-nav-click` event is sent when click or auto select the overlay navigate item
-* `overlay-cta-click` event is sent when user click the overlay CTA button
-* `overlay-skip-tour` event is sent when click the overlay `skip tour` button
+| EVENT | DESCRIPTION |
+|-----------|---------------------|
+| `overlay-session-begin` | internal event triggered when user open the overlay, will not send out any data. |
+| `overlay-session-end` | internal event is triggered when user close the overlay. `overlay-session` event is sent to the server. |
+| `overlay-session` | event is sent when user close the overlay |
+| `overlay-nav-click` | event is sent when click or auto select the overlay navigate item |
+| `overlay-cta-click` | event is sent when user click the overlay CTA button |
+| `overlay-skip-tour` | event is sent when click the overlay `skip tour` button |
 
 ### Notification events
 
-* `notification-session-begin` internal event triggered when user open the notification, will not send out any data.
-* `notification-session` event is sent when user close the notification
-* `notification-cta-click`event is sent when click the notification CTA button
+| EVENT | DESCRIPTION |
+|-----------|---------------------|
+| `notification-session-begin` | internal event triggered when user open the notification, will not send out any data. |
+| `notification-session-end` | internal event is triggered when user close the notification. `notification-session` event is sent to the server. |
+| `notification-session` | event is sent when user close the notification |
+| `notification-cta-click` | event is sent when click the notification CTA button |
 
-**Where:**
-
-:one: Firefox data
-:two: HTTP protocol data