Bug 1419996 - remove NEW_TABLE flag and legacy code for the onboarding telemetry r=Fischer draft
authorMichael Kohler <me@michaelkohler.info>
Wed, 31 Jan 2018 19:48:56 +0100
changeset 749576 7edf117d5f2a58d346ca81a6792b45decc8b6dc9
parent 748403 117e0c0d1ebe2cf5bdffc3474744add2416fc511
push id97447
push userbmo:me@michaelkohler.info
push dateWed, 31 Jan 2018 18:53:42 +0000
reviewersFischer
bugs1419996
milestone60.0a1
Bug 1419996 - remove NEW_TABLE flag and legacy code for the onboarding telemetry r=Fischer MozReview-Commit-ID: Lb8G8DXRdeh
browser/extensions/onboarding/OnboardingTelemetry.jsm
--- a/browser/extensions/onboarding/OnboardingTelemetry.jsm
+++ b/browser/extensions/onboarding/OnboardingTelemetry.jsm
@@ -11,20 +11,16 @@ const {utils: Cu} = Components;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetters(this, {
   PingCentre: "resource:///modules/PingCentre.jsm",
   Services: "resource://gre/modules/Services.jsm",
 });
 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;
 }
 
 // Validate the content is an empty string
 function isEmptyString(str) {
   return typeof str == "string" && str === "";
@@ -334,93 +330,32 @@ const EVENT_WHITELIST = {
       logo_state: isEmptyString,
       notification_impression: isMinusOne,
       notification_state: isEmptyString,
       target_tour_id: isEmptyString,
     }),
   },
 };
 
-/**
- * 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 = {
   sessionProbe: null,
   eventProbe: null,
   state: {
     sessions: {},
   },
 
   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;
     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");
@@ -431,24 +366,16 @@ let OnboardingTelemetry = {
       overlay_session_id: "",
       notification_session_id: "",
       page,
       tour_type,
     };
   },
 
   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);
       return;
     }
 
     if (!this.state.sessions[session_key]) {
       throw new Error(`${type} should pass valid session_key`);
@@ -616,133 +543,16 @@ let OnboardingTelemetry = {
         };
         this._validatePayload(payload);
         this.eventProbe && this.eventProbe.sendPing(payload,
           {filter: ONBOARDING_ID});
         break;
     }
   },
 
-  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;
     let { validators } = EVENT_WHITELIST[type];
     if (!validators) {
       throw new Error(`Event ${type} without validators should not be sent.`);
     }
     let validatorKeys = Object.keys(validators);