Bug 1412255 - PART 1: send notification_state; draft
authorFred Lin <gasolin@gmail.com>
Fri, 10 Nov 2017 14:05:27 +0800
changeset 701804 2a324715bb6a3667bd197fc4dc33fbfa28538bf4
parent 701783 98db469b126e342bc56d22fca8b4ba56df3f3724
child 701805 2388d3f7a864860ccc60754de76edff4651e4470
push id90289
push userbmo:gasolin@mozilla.com
push dateWed, 22 Nov 2017 09:39:17 +0000
bugs1412255
milestone59.0a1
Bug 1412255 - PART 1: send notification_state; 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
@@ -176,16 +176,20 @@ const EVENT_WHITELIST = {
       notification_impression: isPositiveInteger,
       notification_state: isEmptyString,
       target_tour_id: hasString,
       width: isPositiveInteger,
     }),
     sendImpression: true,
     sendLogoState: true,
   },
+  // track when notification is finished
+  "notification-finished": {topic: "internal"},
+  // track when notification is hidden
+  "notification-hide": {topic: "internal"},
   // The real event name send to the server, alias of notification-session-end
   "notification-session": {
     topic: "firefox-onboarding-session2",
     category: "notification-interactions",
     parent: "onboarding",
     validators: Object.assign({}, BASIC_SESSION_SCHEMA, {
       category: isValidCategory,
     }),
@@ -204,16 +208,17 @@ const EVENT_WHITELIST = {
       current_tour_id: isEmptyString,
       logo_state: isValidLogoState,
       notification_impression: isMinusOne,
       notification_state: isValidNotificationState,
       target_tour_id: isEmptyString,
       width: isPositiveInteger,
     }),
     sendLogoState: true,
+    sendNotificationState: true,
   },
   // init onboarding session with session_key and page url
   "onboarding-register-session": {topic: "internal"},
   // The real event name send to the server, alias of onboarding-session-end
   "onboarding-session": {
     topic: "firefox-onboarding-session2",
     category: "",
     validators: Object.assign({}, BASIC_SESSION_SCHEMA, {
@@ -404,16 +409,17 @@ let OnboardingTelemetry = {
       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] = {
       page,
       onboarding_session_id,
       overlay_session_id: "",
       notification_session_id: "",
+      notification_state: "hide",
       tour_type,
     };
   },
 
   process(data) {
     if (NEW_TABLE) {
       this.processPings(data);
     } else {
@@ -448,19 +454,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);
@@ -477,28 +490,30 @@ let OnboardingTelemetry = {
       event,
       session_key,
       target_tour_id = "",
       width = -1,
     } = 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,
       sendImpression,
       sendLogoState,
+      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":
@@ -576,16 +591,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
@@ -1027,21 +1027,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
@@ -60,16 +60,17 @@ sessions for onboarding telemetry;r=fisc
 ```js
 {
   "addon_version": "1.0.0",
   "category": ["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"],
@@ -90,16 +91,17 @@ sessions for onboarding telemetry;r=fisc
 | `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 belong to which parent session. | :one:
 | `root_session_id` | [Required] The unique identifier generated by `gUUIDGenerator` service to identify this event belong to which root session. | :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:
@@ -143,13 +145,15 @@ Here are all allowed `event` strings tha
 | `overlay-session` | event is sent when close the overlay. |
 | `overlay-skip-tour` | event is sent when clicking the overlay `skip tour` button. |
 
 ### Notification events
 
 | EVENT | DESCRIPTION |
 |-----------|---------------------|
 | `notification-appear` | event is sent when one notification appears. |
+| `notification-finished` | internal event triggered when notification is finished. |
+| `notification-hide` | internal event triggered when notification is hidden. |
 | `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 closes the notification. `notification-session` event is the actual event that send to the server.|
 | `notification-session` | event is sent when user closes the notification. |
 | `notification-close-button-click` | event is sent when clicking the notification close button. |
 | `notification-cta-click` | event is sent when clicking the notification CTA button. |