Bug 1413830 - PART 3: send notification_state;r=fischer,francois draft
authorFred Lin <gasolin@gmail.com>
Fri, 10 Nov 2017 14:05:27 +0800
changeset 703622 a861f884c78b223d28fd8028ee7a7c5908749835
parent 703621 450732ee8726ff928e84b2e6e75aeacd5c07daf9
child 703623 678f8dcea68a436b8f0376ab9684819075db63b2
push id90891
push userbmo:gasolin@mozilla.com
push dateMon, 27 Nov 2017 07:51:07 +0000
reviewersfischer, francois
bugs1413830
milestone59.0a1
Bug 1413830 - PART 3: send notification_state;r=fischer,francois MozReview-Commit-ID: DD0YWuaNWsB
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
@@ -177,16 +177,20 @@ const EVENT_WHITELIST = {
       bubble_state: isValidBubbleState,
       current_tour_id: hasString,
       logo_state: isValidLogoState,
       notification_impression: isPositiveInteger,
       notification_state: isValidNotificationState,
       target_tour_id: hasString,
     }),
   },
+  // track when notification is finished
+  "notification-finished": {topic: "internal"},
+  // track when notification is hidden
+  "notification-hide": {topic: "internal"},
   // track the start and end time of the notification session
   "notification-session": {
     topic: "firefox-onboarding-session2",
     category: "notification-interactions",
     parent: "onboarding",
     validators: BASIC_SESSION_SCHEMA,
   },
   // track the start of a notification
@@ -194,16 +198,17 @@ const EVENT_WHITELIST = {
   // track the end of a notification
   "notification-session-end": {topic: "internal"},
   // track when a user clicks the Firefox logo
   "onboarding-logo-click": {
     topic: "firefox-onboarding-event2",
     category: "logo-interactions",
     parent: "onboarding",
     sendLogoState: true,
+    sendNotificationState: true,
     validators: Object.assign({}, BASIC_EVENT_SCHEMA, {
       bubble_state: isValidBubbleState,
       current_tour_id: isEmptyString,
       logo_state: isValidLogoState,
       notification_impression: isMinusOne,
       notification_state: isValidNotificationState,
       target_tour_id: isEmptyString,
     }),
@@ -428,16 +433,17 @@ let OnboardingTelemetry = {
     if (!session_key || !page || !tour_type) {
       throw new Error("session_key, page url, and tour_type are required for onboarding-register-session");
     }
     let onboarding_session_id = gUUIDGenerator.generateUUID().toString();
     this.state.sessions[session_key] = {
       onboarding_session_id,
       overlay_session_id: "",
       notification_session_id: "",
+      notification_state: "hide",
       page,
       tour_type,
     };
   },
 
   process(data) {
     if (NEW_TABLE) {
       this.processPings(data);
@@ -473,19 +479,26 @@ let OnboardingTelemetry = {
         case "overlay-session-begin":
           this.state.sessions[session_key].overlay_session_id = gUUIDGenerator.generateUUID().toString();
           this.state.sessions[session_key].overlay_session_begin = Date.now();
           break;
         case "overlay-session-end":
           data.event = "overlay-session";
           this._sendPing("firefox-onboarding-session2", data);
           break;
+        case "notification-finished":
+          this.state.sessions[session_key].notification_state = "finished";
+          break;
+        case "notification-hide":
+          this.state.sessions[session_key].notification_state = "hide";
+          break;
         case "notification-session-begin":
           this.state.sessions[session_key].notification_session_id = gUUIDGenerator.generateUUID().toString();
           this.state.sessions[session_key].notification_session_begin = Date.now();
+          this.state.sessions[session_key].notification_state = "show";
           break;
         case "notification-session-end":
           data.event = "notification-session";
           this._sendPing("firefox-onboarding-session2", data);
           break;
       }
     } else {
       this._sendPing(topic, data);
@@ -502,28 +515,30 @@ let OnboardingTelemetry = {
       event,
       session_key,
       target_tour_id = "",
       width,
     } = data;
     let {
       notification_session_begin,
       notification_session_id,
+      notification_state,
       onboarding_session_begin,
       onboarding_session_id,
       overlay_session_begin,
       overlay_session_id,
       page,
       tour_type,
     } = this.state.sessions[session_key];
     let {
       category,
       parent,
       sendLogoState,
       sendNotificationImpression,
+      sendNotificationState,
     } = EVENT_WHITELIST[event];
     let session_begin;
     let payload;
     let session_id;
     let root_session_id = onboarding_session_id;
     let parent_session_id = onboarding_session_id;
     switch (topic) {
       case "firefox-onboarding-session2":
@@ -602,16 +617,17 @@ let OnboardingTelemetry = {
         if (sendLogoState) {
           // 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 logo_state = Services.prefs.getStringPref("browser.onboarding.state", "default");
           payload.logo_state = logo_state === "default" ? "logo" : logo_state;
         } else {
           payload.logo_state = "";
         }
+        payload.notification_state = sendNotificationState ? notification_state : "";
         this._validatePayload(payload);
         this.eventProbe && this.eventProbe.sendPing(payload,
           {filter: ONBOARDING_ID});
         break;
     }
   },
 
   processOldPings(data) {
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -1043,21 +1043,29 @@ class Onboarding {
       session_key: this._session_key,
     });
 
     this.showNotification();
   }
 
   showNotification() {
     if (Services.prefs.getBoolPref("browser.onboarding.notification.finished", false)) {
+      telemetry({
+        event: "notification-finished",
+        session_key: this._session_key
+      });
       return;
     }
 
     let lastTime = this._getLastTourChangeTime();
     if (this._muteNotificationOnFirstSession(lastTime)) {
+      telemetry({
+        event: "notification-hide",
+        session_key: this._session_key
+      });
       return;
     }
     // After the notification mute on the 1st session,
     // we don't want to show the speech bubble by default
     this._overlayIcon.classList.remove("onboarding-speech-bubble");
 
     let queue = this._getNotificationQueue();
     let totalMaxTime = Services.prefs.getIntPref("browser.onboarding.notification.max-life-time-all-tours-ms");
--- a/browser/extensions/onboarding/data_events.md
+++ b/browser/extensions/onboarding/data_events.md
@@ -59,16 +59,17 @@ For reference, Onyx is a Mozilla owned s
 ```js
 {
   "addon_version": "1.0.0",
   "category": ["logo-interactions"|"overlay-interactions"|"notification-interactions"],
   "client_id": "374dc4d8-0cb2-4ac5-a3cf-c5a9bc3c602e",
   "locale": "en-US",
   "logo_state": ["logo" | "watermark"],
   "notification_impression": [1-8],
+  "notification_state": ["show" | "hide" | "finished"],
   "page": ["about:newtab" | "about:home"],
   "parent_session_id": "{45cddbeb-2bec-4f3a-bada-fb87d4b79a6c}",
   "root_session_id": "{45cddbeb-2bec-4f3a-bada-fb87d4b79a6c}",
   "current_tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset'
   "target_tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset',
   "tour_id": ["onboarding-tour-private-browsing" | "onboarding-tour-addons"|...], // tour ids defined in 'onboardingTourset'
   "timestamp": 1505440017019,
   "tour_type" ["new" | "update"],
@@ -89,16 +90,17 @@ For reference, Onyx is a Mozilla owned s
 | `addon_version` | [Required] The version of the Onboarding addon. | :one:
 | `category` | [Required] Either ("overlay-interactions", "notification-interactions") to identify which kind of the interaction | :one:
 | `client_id` | [Required] An identifier generated by [ClientID](https://github.com/mozilla/gecko-dev/blob/master/toolkit/modules/ClientID.jsm) module to provide an identifier for this device. This data is automatically appended by `ping-centre` module | :one:
 | `current_tour_id` | [Optional] 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:
 | `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 (e.g. en-US). | :two:
 | `logo_state` | [Optional] One of ["logo", "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:
 | `notification_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:
+| `notification_state` | [Optional] One of ["show", "hide", "finished"] indicates the current notification bar state. | :one:
 | `page` | [Required] One of ["about:newtab", "about:home"]| :one:
 | `parent_session_id` | [Required] The unique identifier generated by `gUUIDGenerator` service to identify this event belongs to which parent session. Events happen upon overlay will have the `overlay session uuid` as its `parent_session_id`. Events happen upon notification will have the `notification session uuid` as its `parent_session_id`. | :one:
 | `root_session_id` | [Required] The unique identifier generated by `gUUIDGenerator` service to identify this event belongs to which root session. Every event will have the same `onboarding session uuid` as its `root_session_id` when interact in the same tab. | :one:
 | `target_tour_id` | [Optional] id of the target switched 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:
 | `timestamp` | [Required] Timestamp in (integer) milliseconds when the event triggered | :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:
 | `type` | [Required] The type of event. Allowed event strings are defined in the below section | :one:
 | `ua` | [Auto populated by Onyx] The user agent string. | :two:
@@ -145,11 +147,13 @@ Here are all allowed event `type` string
 
 ### Notification events
 
 | EVENT | DESCRIPTION |
 |-----------|---------------------|
 | `notification-appear` | event is sent when a notification appears. |
 | `notification-close-button-click` | event is sent when a user clicks close notification button. |
 | `notification-cta-click` | event is sent when a user clicks the notification's Call-To-Action button. |
+| `notification-finished` | internal event triggered when `browser.onboarding.notification.finished` pref is set to `true`. |
+| `notification-hide` | internal event triggered when the notification is hidden. |
 | `notification-session` | event is sent when user closes the notification  to track the start and end time of the notification session. |
 | `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 a notification session ends. `notification-session` event is the actual event that send to the server. |