Bug 1202196 Add UI Telemetry for search history items.r=mfinkle
authorAllison Naaktgeboren <ally@mozilla.com>
Tue, 15 Sep 2015 18:58:52 -0700
changeset 295251 2a5e16abd240fbca1ba65b96644e2d3f8a9aa671
parent 295250 ff72c4a3db5a3088d5edce319a91cb55168811cd
child 295252 4e622cceae4c46745effddf30849c5a304ceb838
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1202196
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1202196 Add UI Telemetry for search history items.r=mfinkle
mobile/android/base/home/SearchEngineRow.java
--- a/mobile/android/base/home/SearchEngineRow.java
+++ b/mobile/android/base/home/SearchEngineRow.java
@@ -93,18 +93,17 @@ class SearchEngineRow extends AnimatedHe
                         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.SUGGESTION, "url");
 
                         mUrlOpenListener.onUrlOpen(suggestion, EnumSet.noneOf(OnUrlOpenListener.Flags.class));
                     }
                 } else if (mSearchListener != null) {
                     if (v == mUserEnteredView) {
                         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.SUGGESTION, "user");
                     } else {
-                        final String extras = "engine." + (String) v.getTag();
-                        Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.SUGGESTION, extras);
+                        Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.SUGGESTION, (String) v.getTag());
                     }
                     mSearchListener.onSearch(mSearchEngine, suggestion);
                 }
             }
         };
 
         mLongClickListener = new OnLongClickListener() {
             @Override
@@ -179,31 +178,30 @@ class SearchEngineRow extends AnimatedHe
     public void setOnSearchListener(OnSearchListener listener) {
         mSearchListener = listener;
     }
 
     public void setOnEditSuggestionListener(OnEditSuggestionListener listener) {
         mEditSuggestionListener = listener;
     }
 
-    private void bindSuggestionView(String suggestion, boolean animate, int recycledSuggestionCount, Integer previousSuggestionChildIndex, boolean isUserSavedSearch){
+    private void bindSuggestionView(String suggestion, boolean animate, int recycledSuggestionCount, Integer previousSuggestionChildIndex, boolean isUserSavedSearch, String telemetryTag){
         final View suggestionItem;
 
         // Reuse suggestion views from recycled view, if possible.
         if (previousSuggestionChildIndex + 1 < recycledSuggestionCount) {
             suggestionItem = mSuggestionView.getChildAt(previousSuggestionChildIndex + 1);
             suggestionItem.setVisibility(View.VISIBLE);
         } else {
             suggestionItem = mInflater.inflate(R.layout.suggestion_item, null);
 
             suggestionItem.setOnClickListener(mClickListener);
             suggestionItem.setOnLongClickListener(mLongClickListener);
 
-            // Store the position of the suggestion for telemetry.
-            suggestionItem.setTag(String.valueOf(previousSuggestionChildIndex));
+            suggestionItem.setTag(telemetryTag);
 
             mSuggestionView.addView(suggestionItem);
         }
 
         setSuggestionOnView(suggestionItem, suggestion, isUserSavedSearch);
 
         if (animate) {
             AlphaAnimation anim = new AlphaAnimation(0, 1);
@@ -222,19 +220,23 @@ class SearchEngineRow extends AnimatedHe
 
     private void updateFromSavedSearches(Cursor c, boolean animate, int suggestionCounter, int recycledSuggestionCount) {
         if (c == null) {
             return;
         }
         try {
             if (c.moveToFirst()) {
                 final int searchColumn = c.getColumnIndexOrThrow(SearchHistory.QUERY);
+                final int historyStartIndex = suggestionCounter;
                 do {
                     final String savedSearch = c.getString(searchColumn);
-                    bindSuggestionView(savedSearch, animate, recycledSuggestionCount, suggestionCounter, true);
+                    // suggestionCounter counts all suggestions (from history and the search engine)
+                    // but we want the relative position of the history item in telemetry
+                    String telemetryTag = "history." + (suggestionCounter - historyStartIndex);
+                    bindSuggestionView(savedSearch, animate, recycledSuggestionCount, suggestionCounter, true, telemetryTag);
                     ++suggestionCounter;
                 } while (c.moveToNext());
             }
         } finally {
             c.close();
         }
         hideRecycledSuggestions(suggestionCounter, recycledSuggestionCount);
     }
@@ -261,22 +263,23 @@ class SearchEngineRow extends AnimatedHe
         if (AppConstants.NIGHTLY_BUILD) {
             limit = isTablet ? TABLET_MAX : PHONE_MAX;
             // If there are less than max saved searches on phones, fill the space with more search engine suggestions
             if (!isTablet && savedCount < PHONE_MAX) {
                     limit += PHONE_MAX - savedCount;
             }
         }
         int suggestionCounter = 0;
-        // Apply Search Engine's suggestions
         for (String suggestion : mSearchEngine.getSuggestions()) {
             if (suggestionCounter == limit) {
                 break;
             }
-            bindSuggestionView(suggestion, animate, recycledSuggestionCount, suggestionCounter, false);
+            // Since the search engine suggestions are listed first, we can use suggestionCounter to get their relative positions for telemetry
+            String telemetryTag = "engine." + suggestionCounter;
+            bindSuggestionView(suggestion, animate, recycledSuggestionCount, suggestionCounter, false, telemetryTag);
             ++suggestionCounter;
         }
 
         hideRecycledSuggestions(suggestionCounter, recycledSuggestionCount);
 
         // Make sure mSelectedView is still valid.
         if (mSelectedView >= mSuggestionView.getChildCount()) {
             mSelectedView = mSuggestionView.getChildCount() - 1;