Bug 1400408 - Fill in basic documentation of existing Pocket telemetry. r?mcomella draft
authorChenxia Liu <liuche@mozilla.com>
Wed, 20 Sep 2017 17:11:37 -0700
changeset 667987 01f352f2680a91fae6690d0082e43cc36f77f81f
parent 667790 469eb992a9d166004f2601ce725786f671219054
child 667988 606e85bb2ec25335b338364b8f53c82ec3c1d590
child 668454 846f88b95d139f140e1c09914186ce4bf894a9f8
push id80912
push usercliu@mozilla.com
push dateThu, 21 Sep 2017 00:44:17 +0000
reviewersmcomella
bugs1400408
milestone57.0a1
Bug 1400408 - Fill in basic documentation of existing Pocket telemetry. r?mcomella MozReview-Commit-ID: FiZI6ebihD9
mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.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
@@ -139,19 +139,16 @@ public class ActivityStreamTelemetry {
             public Builder forHighlightSource(Utils.HighlightSource source) {
                 switch (source) {
                     case VISITED:
                         this.set(Contract.SOURCE_SUBTYPE, Contract.SUBTYPE_VISITED);
                         break;
                     case BOOKMARKED:
                         this.set(Contract.SOURCE_SUBTYPE, Contract.SUBTYPE_BOOKMARKED);
                         break;
-                    case POCKET:
-                        this.set(Contract.SOURCE_TYPE, Contract.TYPE_POCKET);
-                        break;
                     default:
                         throw new IllegalStateException("Unknown highlight source: " + source);
                 }
                 return this;
             }
 
             public Builder forTopSite(final TopSite topSite) {
                 this.set(
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -190,33 +190,33 @@ public class StreamRecyclerAdapter exten
         final WebpageRowModel model = (WebpageRowModel) recyclerViewModel.get(position);
 
         final String sourceType;
         final int actionPosition;
         final int size;
         final String referrerUri;
         final int viewType = getItemViewType(position);
 
+        final ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder();
         if (viewType == RowItemType.HIGHLIGHT_ITEM.getViewType()) {
+            extras.forHighlightSource(model.getSource());
             sourceType = ActivityStreamTelemetry.Contract.TYPE_HIGHLIGHTS;
             actionPosition = getHighlightsIndexFromAdapterPosition(position);
             size = getNumOfTypeShown(RowItemType.HIGHLIGHT_ITEM);
             referrerUri = null;
         } else {
             sourceType = ActivityStreamTelemetry.Contract.TYPE_POCKET;
             actionPosition = getTopStoriesIndexFromAdapterPosition(position);
             size = getNumOfTypeShown(RowItemType.TOP_STORIES_ITEM);
             referrerUri = PocketStoriesLoader.POCKET_REFERRER_URI;
         }
 
-        ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder()
-                .forHighlightSource(model.getSource())
-                .set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, sourceType)
-                .set(ActivityStreamTelemetry.Contract.ACTION_POSITION, actionPosition)
-                .set(ActivityStreamTelemetry.Contract.COUNT, size);
+        extras.set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, sourceType)
+              .set(ActivityStreamTelemetry.Contract.ACTION_POSITION, actionPosition)
+              .set(ActivityStreamTelemetry.Contract.COUNT, size);
 
         Telemetry.sendUIEvent(
                 TelemetryContract.Event.LOAD_URL,
                 TelemetryContract.Method.LIST_ITEM,
                 extras.build()
         );
 
         // NB: This is hacky. We need to process telemetry data first, otherwise we run a risk of
@@ -266,31 +266,31 @@ public class StreamRecyclerAdapter exten
     @Override
     public void openContextMenu(final WebpageItemRow webpageItemRow, final int position, @NonNull final String interactionExtra) {
         final WebpageRowModel model = (WebpageRowModel) recyclerViewModel.get(position);
 
         final String sourceType;
         final int actionPosition;
         final ActivityStreamContextMenu.MenuMode menuMode;
 
+        ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder();
         if (model.getRowItemType() == RowItemType.HIGHLIGHT_ITEM) {
+            extras.forHighlightSource(model.getSource());
             sourceType = ActivityStreamTelemetry.Contract.TYPE_HIGHLIGHTS;
             actionPosition = getHighlightsIndexFromAdapterPosition(position);
             menuMode = ActivityStreamContextMenu.MenuMode.HIGHLIGHT;
         } else {
             sourceType = ActivityStreamTelemetry.Contract.TYPE_POCKET;
             actionPosition = getTopStoriesIndexFromAdapterPosition(position);
             menuMode = ActivityStreamContextMenu.MenuMode.TOPSTORY;
         }
 
-        ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder()
-                .set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, sourceType)
-                .set(ActivityStreamTelemetry.Contract.ACTION_POSITION, actionPosition)
-                .set(ActivityStreamTelemetry.Contract.INTERACTION, interactionExtra)
-                .forHighlightSource(model.getSource());
+        extras.set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, sourceType)
+              .set(ActivityStreamTelemetry.Contract.ACTION_POSITION, actionPosition)
+              .set(ActivityStreamTelemetry.Contract.INTERACTION, interactionExtra);
 
         ActivityStreamContextMenu.show(webpageItemRow.itemView.getContext(),
                 webpageItemRow.getContextMenuAnchor(),
                 extras,
                 menuMode,
                 model,
                 /* shouldOverrideWithImageProvider */ true, // we use image providers in HighlightItem.pageIconLayout.
                 onUrlOpenListener, onUrlOpenInBackgroundListener,
--- a/mobile/android/docs/activitystreamtelemetry.rst
+++ b/mobile/android/docs/activitystreamtelemetry.rst
@@ -52,45 +52,71 @@ For each click event (1/2), in addition 
     }
 
 Subtype indicates a reason an item which is being interacted with appeared in the Top Sites:
 
 - "pinned": a pinned top site, specifically a non-positioned "Activity Stream pinned" site
 - "suggested": a suggested top site, one of the default ones displayed when there's not enough browsing history available
 - "top": a frecency-based top site, based on browsing history. Neither "pinned" nor "suggested".
 
+Top Stories (Pocket) interactions
+---------------------------------
+
+Two event types are recorded for row items (links):
+1) User clicked on a Story item: event="loadurl.1", method="listitem"
+2) User clicked on the menu button: event="show.1", method="contextmenu"
+
+For both event types, in addition to global extras, the following information is recorded:
+
+.. code-block:: js
+
+    extras: {
+        ...
+        "source_type": "pocket",
+        "action_position": number /* 0-based index of a story being interacted with */
+    }
+
+For "loadurl.1" event, the following extra information is also recorded:
+
+.. code-block:: js
+
+    extras: {
+        ...
+        "count": number, /* total number of stories displayed */
+    }
+
 Highlight interactions
 ----------------------
 Two event types are recorded:
 
 1) User clicked on a Highlight: event="loadurl.1", method="listitem"
 2) User clicked on the menu button: event="show.1", method="contextmenu"
 
 For both event types, in addition to global extras, the following information is recorded:
 
 .. code-block:: js
 
     extras: {
         ...
         "source_type": "highlights",
-        "source_subtype": "visited"/"bookmarked"
+        "source_subtype": "visited"/"bookmarked",
+        "action_position": number, /* 0-based index of a highlight being interacted with */
     }
 
 Subtype indicates reason an item being which is being interacted with appeared in the Highlights:
 - "visited": a website has been visited recently
 - "bookmarked": a website has been bookmarked recently
 
 For "loadurl.1" event, the following extra information is also recorded:
 
 .. code-block:: js
 
     extras: {
         ...
-        "action_position": number, /* 0-based index of a highlight being interacted with */
-        "count": number, /* total number of highlights displayed */
+        "count": number /* total number of highlights displayed */
     }
 
 Context Menu interactions
 -------------------------
 Every interaction with a context menu item is recorded using: event="action.1", method="contextmenu"
 
 For all interactions, in addition to global extras, the following information is recorded: