From 62bd87916835a6035c18963fa33853f71a7eb5f7 Mon Sep 17 00:00:00 2001 From: Allison Naaktgeboren Date: Tue, 15 Sep 2015 18:58:52 -0700 Subject: [PATCH] Bug 1202196 Add UI Telemetry for search history items.r=mfinkle --- mobile/android/base/home/SearchEngineRow.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mobile/android/base/home/SearchEngineRow.java b/mobile/android/base/home/SearchEngineRow.java index dc0bf2528d3..994c031aee0 100644 --- a/mobile/android/base/home/SearchEngineRow.java +++ b/mobile/android/base/home/SearchEngineRow.java @@ -98,8 +98,7 @@ class SearchEngineRow extends AnimatedHeightLayout { 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); } @@ -184,7 +183,7 @@ class SearchEngineRow extends AnimatedHeightLayout { 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. @@ -197,8 +196,7 @@ class SearchEngineRow extends AnimatedHeightLayout { 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); } @@ -227,9 +225,13 @@ class SearchEngineRow extends AnimatedHeightLayout { 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()); } @@ -266,12 +268,13 @@ class SearchEngineRow extends AnimatedHeightLayout { } } 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; }