Bug 1301468 - Add activity stream session for new tab panel. r?ahunt draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 23 Nov 2016 17:24:31 +0100
changeset 443013 51c8716902d0df2d2e1edd1b1962699a7d7ff793
parent 442957 07a61d0a6de451d38ff9b44e9f6a881d7adbf093
child 537946 2d1c170b35ef5af48a751da8f93831ebcfaf7054
push id36878
push users.kaspari@gmail.com
push dateWed, 23 Nov 2016 16:26:34 +0000
reviewersahunt
bugs1301468
milestone53.0a1
Bug 1301468 - Add activity stream session for new tab panel. r?ahunt MozReview-Commit-ID: 45yMkb3bJfS
mobile/android/base/java/org/mozilla/gecko/TelemetryContract.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStreamHomeFragment.java
--- a/mobile/android/base/java/org/mozilla/gecko/TelemetryContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/TelemetryContract.java
@@ -226,16 +226,20 @@ public interface TelemetryContract {
 
     /**
      * Holds session names. Intended for use with
      * Telemetry.startUISession() as the "sessionName" parameter.
      *
      * Please keep this list sorted.
      */
     public enum Session {
+        // Started whenever the activity stream panel is visible. Stopped as soon as the panel is
+        // not visible anymore.
+        ACTIVITY_STREAM("activitystream.1"),
+
         // Awesomescreen (including frecency search) is active.
         AWESOMESCREEN("awesomescreen.1"),
 
         // Used to tag experiments being run.
         EXPERIMENT("experiment.1"),
 
         // Started the very first time we believe the application has been launched.
         FIRSTRUN("firstrun.1"),
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStreamHomeFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStreamHomeFragment.java
@@ -6,16 +6,18 @@ package org.mozilla.gecko.home.activitys
 
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.home.HomeFragment;
 
 /**
  * Simple wrapper around the ActivityStream view that allows embedding as a HomePager panel.
  */
 public class ActivityStreamHomeFragment
         extends HomeFragment {
     private ActivityStream activityStream;
@@ -31,9 +33,34 @@ public class ActivityStreamHomeFragment
                              @Nullable Bundle savedInstanceState) {
         if (activityStream == null) {
             activityStream = (ActivityStream) inflater.inflate(R.layout.activity_stream, container, false);
             activityStream.setOnUrlOpenListeners(mUrlOpenListener, mUrlOpenInBackgroundListener);
         }
 
         return activityStream;
     }
+
+    @Override
+    public void setUserVisibleHint(boolean isVisibleToUser) {
+        super.setUserVisibleHint(isVisibleToUser);
+
+        if (isVisibleToUser) {
+            Telemetry.startUISession(TelemetryContract.Session.ACTIVITY_STREAM, "newtab");
+
+            Telemetry.sendUIEvent(TelemetryContract.Event.SHOW, TelemetryContract.Method.PANEL, "as_newtab");
+        } else {
+            Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.PANEL, "as_newtab");
+
+            Telemetry.stopUISession(TelemetryContract.Session.ACTIVITY_STREAM, "newtab");
+        }
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+
+        Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.PANEL, "as_newtab");
+
+        // User is navigating away from activity (to other app or settings). Stop the session.
+        Telemetry.stopUISession(TelemetryContract.Session.ACTIVITY_STREAM, "newtab");
+    }
 }