Bug 1374889 - Update Leanplum user attribute for Focus/Klar installation, Sync, and Default Browser. r=maliu
MozReview-Commit-ID: Fl3Q6S0cDLg
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -106,17 +106,17 @@ public class MmaDelegate {
final boolean inExperiment = SwitchBoard.isInExperiment(context, Experiments.LEANPLUM);
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
// if selected tab is null or private, mma should be disabled.
final boolean isInPrivateBrowsing = selectedTab == null || selectedTab.isPrivate();
return inExperiment && healthReport && isGeckoPrefOn && !isInPrivateBrowsing;
}
- private static boolean isDefaultBrowser(Context context) {
+ public static boolean isDefaultBrowser(Context context) {
final Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mozilla.org"));
final ResolveInfo info = context.getPackageManager().resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (info == null) {
// No default is set
return false;
}
final String packageName = info.activityInfo.packageName;
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -11,16 +11,17 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import com.leanplum.Leanplum;
import com.leanplum.LeanplumActivityHelper;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.MmaConstants;
+import org.mozilla.gecko.fxa.FirefoxAccounts;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class MmaLeanplumImp implements MmaInterface {
@@ -39,29 +40,49 @@ public class MmaLeanplumImp implements M
Leanplum.setAppIdForProductionMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
} else {
Leanplum.setAppIdForDevelopmentMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
}
Map<String, Object> attributes = new HashMap<>();
boolean installedFocus = isPackageInstalled(activity, "org.mozilla.focus");
boolean installedKlar = isPackageInstalled(activity, "org.mozilla.klar");
- if (installedFocus || installedKlar) {
- attributes.put("focus", true);
+ if (installedFocus) {
+ attributes.put("Focus Installed", true);
} else {
- attributes.put("focus", false);
+ attributes.put("Focus Installed", false);
}
+ if (installedKlar) {
+ attributes.put("Klar Installed", true);
+ } else {
+ attributes.put("Klar Installed", false);
+ }
+
final SharedPreferences sharedPreferences = activity.getPreferences(0);
String deviceId = sharedPreferences.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
if (deviceId == null) {
deviceId = UUID.randomUUID().toString();
sharedPreferences.edit().putString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, deviceId).apply();
}
Leanplum.setDeviceId(deviceId);
+ if (MmaDelegate.isDefaultBrowser(activity)) {
+ attributes.put("Default Browser", true);
+ } else {
+ attributes.put("Default Browser", false);
+ }
+
+ // In order to trigger the campaign lazily, you check the account existence as an attribute,
+ // not when account login success callback is invoked. Because the attribute update lazily when process start.
+ if (FirefoxAccounts.firefoxAccountsExist(activity)) {
+ attributes.put("Signed In Sync", true);
+ } else {
+ attributes.put("Signed In Sync", false);
+ }
+
Leanplum.start(activity, attributes);
// this is special to Leanplum. Since we defer LeanplumActivityHelper's onResume call till
// switchboard completes loading. We miss the call to LeanplumActivityHelper.onResume.
// So I manually call it here.
//
// There's a risk that if this is called after activity's onPause(Although I've
// tested it's seems okay). We should require their SDK to separate activity call back with