Dbrant has uploaded a new change for review.
https://gerrit.wikimedia.org/r/176735
Change subject: Implement Search event logging.
......................................................................
Implement Search event logging.
Conflicts:
wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
Change-Id: I2ec689e5dde98c5e886a1236974c423741e8ce0b
---
A wikipedia/src/main/java/org/wikipedia/analytics/SearchFunnel.java
M wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
M wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
4 files changed, 122 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/35/176735/1
diff --git a/wikipedia/src/main/java/org/wikipedia/analytics/SearchFunnel.java
b/wikipedia/src/main/java/org/wikipedia/analytics/SearchFunnel.java
new file mode 100644
index 0000000..535b939
--- /dev/null
+++ b/wikipedia/src/main/java/org/wikipedia/analytics/SearchFunnel.java
@@ -0,0 +1,96 @@
+package org.wikipedia.analytics;
+
+import org.wikipedia.WikipediaApp;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class SearchFunnel extends Funnel {
+ private static final String SCHEMA_NAME = "MobileWikiAppSearch";
+ private static final int REVISION = 10633564;
+
+ private final String appInstallID;
+
+ public SearchFunnel(WikipediaApp app) {
+ super(app, SCHEMA_NAME, REVISION);
+ //Retrieve this app installation's unique ID, used to record unique
users of features
+ appInstallID = app.getAppInstallID();
+ }
+
+ protected void log(Object... params) {
+ final int defaultSampleRate = 100;
+
+ //get our sampling rate from remote config
+ int sampleRate =
WikipediaApp.getInstance().getRemoteConfig().getConfig()
+ .optInt("searchLogSampleRate",
defaultSampleRate);
+
+ if (sampleRate != 0) {
+ //take the last 4 hex digits of the uuid, modulo the sampling
coefficient.
+ //if the result is 0, then we're one of the Chosen.
+ final int uuidSubstrLen = 4;
+ final int hexBase = 16;
+ boolean chosen =
Integer.parseInt(appInstallID.substring(appInstallID.length() - uuidSubstrLen),
hexBase) % sampleRate == 0;
+
+ if (chosen) {
+ super.log(getApp().getPrimarySite(), params);
+ }
+ }
+ }
+
+ @Override
+ protected JSONObject preprocessData(JSONObject eventData) {
+ try {
+ eventData.put("appInstallID", appInstallID);
+ } catch (JSONException e) {
+ // This isn't happening
+ throw new RuntimeException(e);
+ }
+ return eventData;
+ }
+
+ public void searchStart() {
+ log(
+ "action", "start"
+ );
+ }
+
+ public void searchCancel() {
+ log(
+ "action", "cancel"
+ );
+ }
+
+ public void searchClick() {
+ log(
+ "action", "click"
+ );
+ }
+
+ public void searchAutoSwitch() {
+ log(
+ "action", "autoswitch"
+ );
+ }
+
+ public void searchDidYouMean() {
+ log(
+ "action", "didyoumean"
+ );
+ }
+
+ public void searchResults(boolean fullText, int numResults, int
delayMillis) {
+ log(
+ "action", "results",
+ "typeOfSearch", fullText ? "full" : "prefix",
+ "numberOfResults", numResults,
+ "timeToDisplayResults", delayMillis
+ );
+ }
+
+ public void searchError(boolean fullText, int delayMillis) {
+ log(
+ "action", "error",
+ "typeOfSearch", fullText ? "full" : "prefix",
+ "timeToDisplayResults", delayMillis
+ );
+ }
+}
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
index fda5370..de8c854 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/FullSearchFragment.java
@@ -91,6 +91,7 @@
public void onClick(View view) {
String suggestion = (String) searchSuggestion.getTag();
if (suggestion != null) {
+ searchFragment.getFunnel().searchDidYouMean();
searchFragment.setSearchText(suggestion);
startSearch(suggestion, true);
}
@@ -169,11 +170,13 @@
private void doSearch(final String searchTerm, final int continueOffset) {
(new FullSearchArticlesTask(app.getAPIForSite(app.getPrimarySite()),
app.getPrimarySite(), searchTerm, continueOffset) {
+ final long startMillis = System.currentTimeMillis();
@Override
public void onFinish(FullSearchResults results) {
if (!isAdded()) {
return;
}
+ searchFragment.getFunnel().searchResults(true,
results.getResults().size(), (int)(System.currentTimeMillis() - startMillis));
lastResults = results;
totalResults.addAll(lastResults.getResults());
@@ -215,6 +218,7 @@
if (!isAdded()) {
return;
}
+ searchFragment.getFunnel().searchError(true,
(int)(System.currentTimeMillis() - startMillis));
((PageActivity)getActivity()).updateProgressBar(false, true,
0);
if (continueOffset == 0) {
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
index 0a8ab2c..a9296c4 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java
@@ -4,6 +4,7 @@
import org.wikipedia.R;
import org.wikipedia.Utils;
import org.wikipedia.WikipediaApp;
+import org.wikipedia.analytics.SearchFunnel;
import org.wikipedia.concurrency.SaneAsyncTask;
import org.wikipedia.events.NewWikiPageNavigationEvent;
import org.wikipedia.events.WikipediaZeroStateChangeEvent;
@@ -37,6 +38,10 @@
private WikipediaApp app;
private SearchView searchView;
+ private SearchFunnel funnel;
+ public SearchFunnel getFunnel() {
+ return funnel;
+ }
/**
* Whether the Search fragment is currently showing.
@@ -89,6 +94,12 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = WikipediaApp.getInstance();
+ funnel = new SearchFunnel(WikipediaApp.getInstance());
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}
@@ -153,6 +164,7 @@
//automatically switch to full-text search!
showPanel(PANEL_FULL_SEARCH);
startSearch(lastSearchedText, true);
+ funnel.searchAutoSwitch();
}
});
@@ -293,6 +305,7 @@
* Activate the Search fragment.
*/
public void openSearch() {
+ funnel.searchStart();
isSearchActive = true;
// invalidate our activity's ActionBar, so that we'll have a chance to
inject our
// SearchView into it.
@@ -346,6 +359,7 @@
public boolean onBackPressed() {
if (isSearchActive) {
closeSearch();
+ funnel.searchCancel();
return true;
}
return false;
@@ -461,6 +475,7 @@
@Override
public boolean onClose() {
closeSearch();
+ funnel.searchCancel();
return false;
}
};
@@ -470,6 +485,10 @@
}
public void navigateToTitle(PageTitle title) {
+ if (!isAdded()) {
+ return;
+ }
+ funnel.searchClick();
HistoryEntry historyEntry = new HistoryEntry(title,
HistoryEntry.SOURCE_SEARCH);
Utils.hideSoftKeyboard(getActivity());
closeSearch();
diff --git
a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
index 2990e72..00c1367 100644
--- a/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
+++ b/wikipedia/src/main/java/org/wikipedia/search/TitleSearchFragment.java
@@ -261,6 +261,7 @@
@Override
public boolean handleMessage(Message msg) {
final String mySearchTerm = (String) msg.obj;
+ final long startMillis = System.currentTimeMillis();
TitleSearchTask searchTask = new TitleSearchTask(app,
app.getAPIForSite(app.getPrimarySite()), app.getPrimarySite(), mySearchTerm) {
@Override
public void onBeforeExecute() {
@@ -272,6 +273,7 @@
if (!isAdded()) {
return;
}
+ searchFragment.getFunnel().searchResults(false,
result.size(), (int)(System.currentTimeMillis() - startMillis));
((PageActivity)getActivity()).updateProgressBar(false,
true, 0);
searchNetworkError.setVisibility(View.GONE);
displayResults(result);
@@ -295,6 +297,7 @@
if (!isAdded()) {
return;
}
+ searchFragment.getFunnel().searchError(false,
(int)(System.currentTimeMillis() - startMillis));
((PageActivity)getActivity()).updateProgressBar(false,
true, 0);
searchNetworkError.setVisibility(View.VISIBLE);
searchResultsList.setVisibility(View.GONE);
--
To view, visit https://gerrit.wikimedia.org/r/176735
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ec689e5dde98c5e886a1236974c423741e8ce0b
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits