Bug 1402005: Add telemetry for Learn More clicks. r=liuche draft
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 22 Sep 2017 17:32:03 -0700
changeset 669362 4803bd6eb9c97d0ae89b6322658e2cf0273e4e20
parent 669361 fea160fdf5cff0ee5bfb99604b0e5ebe59d86ffb
child 732939 a9a6da9adf2106cdbe651b6f1095cb1084960c42
push id81312
push usermichael.l.comella@gmail.com
push dateSat, 23 Sep 2017 00:32:23 +0000
reviewersliuche
bugs1402005
milestone58.0a1
Bug 1402005: Add telemetry for Learn More clicks. r=liuche MozReview-Commit-ID: GA4UBZ4fpK6
mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/LearnMoreRow.java
mobile/android/docs/activitystreamtelemetry.rst
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
@@ -30,16 +30,17 @@ public class ActivityStreamTelemetry {
         public final static String COUNT = "count";
         public final static String PAGE_NUMBER = "page_number";
         public final static String INTERACTION = "interaction";
 
         // Values
         public final static String TYPE_TOPSITES = "topsites";
         public final static String TYPE_HIGHLIGHTS = "highlights";
         public final static String TYPE_POCKET = "pocket";
+        public final static String TYPE_LEARN_MORE = "learn_more";
         public final static String SUBTYPE_PINNED = "pinned";
         public final static String SUBTYPE_SUGGESTED = "suggested";
         public final static String SUBTYPE_TOP = "top";
         public final static String SUBTYPE_VISITED = "visited";
         public final static String SUBTYPE_BOOKMARKED = "bookmarked";
         public final static String ITEM_SHARE = "share";
         public final static String ITEM_ADD_BOOKMARK = "add_bookmark";
         public final static String ITEM_REMOVE_BOOKMARK = "remove_bookmark";
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/LearnMoreRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/LearnMoreRow.java
@@ -5,16 +5,20 @@
 package org.mozilla.gecko.activitystream.homepanel.stream;
 
 import android.support.annotation.LayoutRes;
 import android.view.View;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tabs;
+import org.mozilla.gecko.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.activitystream.ActivityStream;
+import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 
 import java.util.Locale;
 
 /**
  * A row in Activity Stream with a link to SUMO so that new users to Activity Stream can read about how it works.
  *
  * We added this in FF57, when we switched to the new top sites layout, because we were concerned users would be
  * confused by the new layout or not be able to find new features (e.g. how to disable Pocket). We may remove it
@@ -39,18 +43,18 @@ public class LearnMoreRow extends Stream
 
     public LearnMoreRow(final View itemView) {
         super(itemView);
 
         final View learnMoreLink = itemView.findViewById(R.id.learn_more_link);
         learnMoreLink.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(final View v) {
-                // todo: add telemetry.
                 Tabs.getInstance().loadUrl(getLearnMoreURL());
+                sendOnClickTelemetry();
             }
         });
     }
 
     /**
      * Gets the URL to be opened when "Learn more" is clicked.
      *
      * The results of this method should not be cached because it retrieves a locale, which can change.
@@ -58,9 +62,19 @@ public class LearnMoreRow extends Stream
     private static String getLearnMoreURL() {
         // I figured out which values to use here from GeckoPreferences.
         final String VERSION = AppConstants.MOZ_APP_VERSION;
         final String OS = AppConstants.OS_TARGET;
         final String LOCALE = Locales.getLanguageTag(Locale.getDefault());
 
         return String.format(LEARN_MORE_URL_TEMPLATE, VERSION, OS, LOCALE);
     }
+
+    private static void sendOnClickTelemetry() {
+        ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder()
+                .set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, ActivityStreamTelemetry.Contract.TYPE_LEARN_MORE);
+
+        Telemetry.sendUIEvent(
+                TelemetryContract.Event.LOAD_URL,
+                TelemetryContract.Method.LIST_ITEM,
+                extras.build());
+    }
 }
--- a/mobile/android/docs/activitystreamtelemetry.rst
+++ b/mobile/android/docs/activitystreamtelemetry.rst
@@ -112,16 +112,28 @@ Possible values for "item" key (names of
 - "pin"
 - "unpin"
 - "copy"
 - "homescreen"
 - "newtab" (private tab actions are collapsed into "newtab" telemetry due to our privacy guidelines)
 - "dismiss"
 - "delete"
 
+Learn More interactions
+-----------------------
+A click on the "Learn more" link is recorded using: event="loadurl.1", method="listitem".
+
+In addition to the global extras, the following information is recorded:
+
+.. code-block:: js
+
+    extras: {
+        "source_type": "learn_more"
+    }
+
 Full Examples
 =============
 Following examples of events are here to provide a better feel for the overall shape of telemetry data being recorded.
 
 1) User with an active Firefox Account clicked on a menu item for a third highlight ("visited"):
     ::
 
         session="activitystream.1"