From e346a45d99f4423e8549dcdde2f4a8c204b90099 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 4 Sep 2019 16:44:19 +1000 Subject: [PATCH 1/2] Set up Mixpanel --- build.gradle | 2 ++ .../thoughtcrime/securesms/ApplicationContext.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/build.gradle b/build.gradle index 3840b65dc5..5c5239bf7f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ buildscript { ext.kovenant_version = "3.3.0" ext.identicon_version = "v11" ext.rss_parser_version = "2.0.4" + ext.mixpanel_version = "5.+" repositories { google() @@ -184,6 +185,7 @@ dependencies { implementation "nl.komponents.kovenant:kovenant:$kovenant_version" implementation "com.github.lelloman:android-identicons:$identicon_version" implementation "com.prof.rssparser:rssparser:$rss_parser_version" + implementation "com.mixpanel.android:mixpanel-android:$mixpanel_version" } def canonicalVersionCode = 12 diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 58d0ee2f61..0baa851b1b 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -27,6 +27,7 @@ import android.support.annotation.NonNull; import android.support.multidex.MultiDexApplication; import com.google.android.gms.security.ProviderInstaller; +import com.mixpanel.android.mpmetrics.MixpanelAPI; import org.conscrypt.Conscrypt; import org.jetbrains.annotations.NotNull; @@ -85,15 +86,18 @@ import org.whispersystems.signalservice.loki.api.LokiLongPoller; import org.whispersystems.signalservice.loki.api.LokiP2PAPI; import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate; import org.whispersystems.signalservice.loki.api.LokiRSSFeed; +import org.whispersystems.signalservice.loki.utilities.Analytics; import java.security.Security; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; import dagger.ObjectGraph; import kotlin.Unit; +import kotlin.jvm.functions.Function1; import network.loki.messenger.BuildConfig; /** @@ -122,6 +126,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc private LokiRSSFeedPoller lokiNewsFeedPoller = null; private LokiRSSFeedPoller lokiMessengerUpdatesFeedPoller = null; public SignalCommunicationModule communicationModule; + public MixpanelAPI mixpanel; private volatile boolean isAppVisible; @@ -154,6 +159,15 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc ProcessLifecycleOwner.get().getLifecycle().addObserver(this); // Loki - Set up P2P API if needed setUpP2PAPI(); + // Loki - Set up beta analytics + mixpanel = MixpanelAPI.getInstance(this, "59040b6707e5a1725f3fb6730fefca92"); + Analytics.Companion.getShared().trackImplementation = (Function1) event -> { + HashMap properties = new HashMap(); + String configuration = BuildConfig.DEBUG ? "debug" : "production"; + properties.put("configuration", configuration); + mixpanel.trackMap(event, properties); + return Unit.INSTANCE; + }; } @Override From 6341ca0101289a726e1d913f48e877ef793aff10 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 5 Sep 2019 09:38:36 +1000 Subject: [PATCH 2/2] Add basic events --- .../securesms/conversation/ConversationActivity.java | 11 +++++++++++ .../securesms/loki/NewConversationActivity.kt | 3 +++ src/org/thoughtcrime/securesms/loki/SeedActivity.kt | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 4126f9f8f8..dae5b71a9a 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -226,6 +226,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; +import org.whispersystems.signalservice.loki.utilities.Analytics; import java.io.IOException; import java.text.SimpleDateFormat; @@ -392,6 +393,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity }); } }); + + if (this.recipient.isGroupRecipient()) { + if (this.recipient.getName().equals("Loki Public Chat")) { + Analytics.Companion.getShared().track("Loki Public Chat Opened"); + } else { + Analytics.Companion.getShared().track("RSS Feed Opened"); + } + } else { + Analytics.Companion.getShared().track("Conversation Opened"); + } } @Override diff --git a/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt b/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt index b4e218495d..e67efcdde7 100644 --- a/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt @@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.qr.ScanListener import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.DynamicTheme import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.signalservice.loki.utilities.Analytics import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListener { @@ -60,6 +61,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe } override fun onQrDataFound(hexEncodedPublicKey: String) { + Analytics.shared.track("QR Code Scanned") startNewConversationIfPossible(hexEncodedPublicKey) } @@ -75,6 +77,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe val existingThread = DatabaseFactory.getThreadDatabase(this).getThreadIdIfExistsFor(contact) intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, existingThread) intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT) + Analytics.shared.track("New Conversation Started") startActivity(intent) finish() } diff --git a/src/org/thoughtcrime/securesms/loki/SeedActivity.kt b/src/org/thoughtcrime/securesms/loki/SeedActivity.kt index b9475ea207..1522d9d2f7 100644 --- a/src/org/thoughtcrime/securesms/loki/SeedActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/SeedActivity.kt @@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.curve25519.Curve25519 import org.whispersystems.libsignal.util.KeyHelper import org.whispersystems.signalservice.loki.crypto.MnemonicCodec +import org.whispersystems.signalservice.loki.utilities.Analytics import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey import java.io.File import java.io.FileOutputStream @@ -162,6 +163,10 @@ class SeedActivity : BaseActionBarActivity() { val application = ApplicationContext.getInstance(this) application.setUpP2PAPI() application.startLongPollingIfNeeded() + when (mode) { + Mode.Register -> Analytics.shared.track("Seed Created") + Mode.Restore -> Analytics.shared.track("Seed Restored") + } startActivity(Intent(this, ConversationListActivity::class.java)) finish() }