Bug 1404460: Add POCKET_ENABLED_TO_LOCALE to asUserPrefs telemetry. r=liuche
After speaking with liuche, we decided it'd be better to add a bit to determine
this rather than combining it with the isPocketEnabled field (which would be
loss of data) or cross-referencing the locale of the submitted event when
checking the Pocket value during telemetry analysis (which is hard to get right
and likely to get out of date).
MozReview-Commit-ID: JKFrdEsEbyp
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStreamTelemetry.java
@@ -1,23 +1,25 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.activitystream;
+import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.R;
+import org.mozilla.gecko.activitystream.homepanel.ActivityStreamConfiguration;
import org.mozilla.gecko.activitystream.homepanel.ActivityStreamPanel;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.activitystream.homepanel.model.TopSite;
import java.util.HashMap;
/**
* Telemetry constants and an 'extras' builder specific to Activity Stream.
@@ -64,27 +66,32 @@ public class ActivityStreamTelemetry {
* AS_USER_PREFERENCES
*
* NB: Additional pref values should be (unique) powers of 2
* We skip 1 and 2 to be consistent with Desktop, because those prefs are not used in Firefox for Android.
**/
private final static int POCKET_ENABLED_VALUE = 4;
private final static int VISITED_ENABLED_VALUE = 8;
private final static int BOOKMARKED_ENABLED_VALUE = 16;
+ private final static int POCKET_ENABLED_BY_LOCALE = 32;
/**
* Calculates the bit-packed value of the user's Activity Stream preferences (e.g. enabled/disabled sections).
*
* @param sharedPreferences SharedPreferences of this profile
* @return bit-packed value of the user's AS preferences, which is the sum of the values of the enabled preferences.
*/
- public static int getASUserPreferencesValue(final SharedPreferences sharedPreferences, final Resources res) {
+ public static int getASUserPreferencesValue(final Context context, final SharedPreferences sharedPreferences) {
+ final Resources res = context.getResources();
int bitPackedPrefValue = 0;
- // todo: Add bit for isPocketAllowedByLocale.
+ if (ActivityStreamConfiguration.isPocketEnabledByLocale(context)) {
+ bitPackedPrefValue += POCKET_ENABLED_BY_LOCALE;
+ }
+
if (sharedPreferences.getBoolean(ActivityStreamPanel.PREF_POCKET_ENABLED, res.getBoolean(R.bool.pref_activitystream_pocket_enabled_default))) {
bitPackedPrefValue += POCKET_ENABLED_VALUE;
}
if (sharedPreferences.getBoolean(ActivityStreamPanel.PREF_VISITED_ENABLED, res.getBoolean(R.bool.pref_activitystream_visited_enabled_default))) {
bitPackedPrefValue += VISITED_ENABLED_VALUE;
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamHomeFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamHomeFragment.java
@@ -44,17 +44,17 @@ public class ActivityStreamHomeFragment
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
final boolean shouldReload = TextUtils.equals(s, ActivityStreamPanel.PREF_BOOKMARKS_ENABLED)
|| TextUtils.equals(s, ActivityStreamPanel.PREF_VISITED_ENABLED)
|| TextUtils.equals(s, ActivityStreamPanel.PREF_POCKET_ENABLED);
if (shouldReload) {
- activityStreamPanel.reload(getLoaderManager(), sharedPreferences, this.getResources());
+ activityStreamPanel.reload(getLoaderManager(), getContext(), sharedPreferences);
}
}
@Override
protected void load() {
activityStreamPanel.load(getLoaderManager());
}
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
@@ -86,23 +86,23 @@ public class ActivityStreamPanel extends
desiredTileWidth = resources.getDimensionPixelSize(R.dimen.activity_stream_desired_tile_width);
tileMargin = resources.getDimensionPixelSize(R.dimen.activity_stream_base_margin);
ActivityStreamTelemetry.Extras.setGlobal(
ActivityStreamTelemetry.Contract.FX_ACCOUNT_PRESENT,
FirefoxAccounts.firefoxAccountsExist(context)
);
- updateSharedPreferencesGlobalExtras(sharedPreferences, context.getResources());
+ updateSharedPreferencesGlobalExtras(context, sharedPreferences);
}
- private void updateSharedPreferencesGlobalExtras(final SharedPreferences sharedPreferences, final Resources res) {
+ private void updateSharedPreferencesGlobalExtras(final Context context, final SharedPreferences sharedPreferences) {
ActivityStreamTelemetry.Extras.setGlobal(
ActivityStreamTelemetry.Contract.AS_USER_PREFERENCES,
- ActivityStreamTelemetry.getASUserPreferencesValue(sharedPreferences, res)
+ ActivityStreamTelemetry.getASUserPreferencesValue(context, sharedPreferences)
);
}
void setOnUrlOpenListeners(HomePager.OnUrlOpenListener onUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
adapter.setOnUrlOpenListeners(onUrlOpenListener, onUrlOpenInBackgroundListener);
}
public void load(LoaderManager lm) {
@@ -119,20 +119,20 @@ public class ActivityStreamPanel extends
}
public void unload() {
adapter.swapHighlights(Collections.<Highlight>emptyList());
adapter.swapTopSitesCursor(null);
}
- public void reload(LoaderManager lm, SharedPreferences sharedPreferences, Resources res) {
+ public void reload(final LoaderManager lm, final Context context, final SharedPreferences sharedPreferences) {
adapter.clearAndInit();
- updateSharedPreferencesGlobalExtras(sharedPreferences, res);
+ updateSharedPreferencesGlobalExtras(context, sharedPreferences);
// Destroy loaders so they don't restart loading when returning.
lm.destroyLoader(LOADER_ID_HIGHLIGHTS);
lm.destroyLoader(LOADER_ID_POCKET);
load(lm);
}
--- a/mobile/android/docs/activitystreamtelemetry.rst
+++ b/mobile/android/docs/activitystreamtelemetry.rst
@@ -13,23 +13,32 @@ Activity Stream events are recorded as p
Global extras
=============
A concept of a "global" extra is meant to support recording certain context information with every event that is being sent, regardless of its type.
``fx_account_present``, values: true, false
Indicates if Firefox Account is currently enabled.
-``as_user_preferences``, values: (bit-packed) value of preferences enabled
+``as_user_preferences``, values: (bit-packed) value of preferences, and related settings, enabled
Each preference is assigned a value that is a unique power of 2, and value of as_user_preferences is the sum of all enabled preferences values.
-The SharedPreferences preferences measured (with their value) are:
-pref_activitystream_pocket_enabled: 4
-pref_activitystream_visited_enabled: 8
-pref_activitystream_recentbookmarks_enabled: 16
+Some values are taken directly from Android SharedPreferences: these are prefixed with "(SharedPrefs)"". All preferences
+measured (with their values) are:
+
+- (SharedPrefs) pref_activitystream_pocket_enabled: 4
+- (SharedPrefs) pref_activitystream_visited_enabled: 8
+- (SharedPrefs) pref_activitystream_recentbookmarks_enabled: 16
+- Is Pocket enabled in the user's current locale: 32
+
+**Important note on Pocket:** A user's ability to override ``pref_activitystream_pocket_enabled`` will be influenced by whether
+or not Pocket is shown so when checking that preference, it is also recommended to check whether Pocket is enabled in the user's
+current locale. We initially limited the locales that get Pocket recommendations in `bug 1404460`_.
+
+.. _bug 1404460: https://bugzilla.mozilla.org/show_bug.cgi?id=1404460
Extra information available for various event types
===================================================
Action position
---------------
Common to most recorded events is the 0-based ``action_position`` extra. For non-menu interactions it
indicates position of an item being interacted with. For example, click on a third top site of a
second page will have ``action_position = 6``, given that the first page had 4 top sites.