Skip to content

Commit

Permalink
Don't log to FirebaseAnalytics
Browse files Browse the repository at this point in the history
  • Loading branch information
yukuku committed May 10, 2024
1 parent 0689cc9 commit e8a4a2c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.analytics.FirebaseAnalytics
import java.util.Calendar
import java.util.Date
import java.util.GregorianCalendar
Expand Down Expand Up @@ -124,6 +123,7 @@ import yuku.alkitab.model.PericopeBlock
import yuku.alkitab.model.SingleChapterVerses
import yuku.alkitab.model.Version
import yuku.alkitab.ribka.RibkaReportActivity
import yuku.alkitab.tracking.Analytics
import yuku.alkitab.tracking.Tracker
import yuku.alkitab.util.Ari
import yuku.alkitab.util.IntArrayList
Expand Down Expand Up @@ -2115,9 +2115,9 @@ class IsiActivity : BaseLeftDrawerActivity(), LeftDrawer.Text.Listener {
private fun trackVersionSelect(mv: MVersion?, isSplit: Boolean) {
if (mv is MVersionDb) {
val preset_name = mv.preset_name
Tracker.trackEvent("versions_dialog_select", "is_split", isSplit, FirebaseAnalytics.Param.ITEM_NAME, preset_name ?: "no_preset_name")
Tracker.trackEvent("versions_dialog_select", "is_split", isSplit, Analytics.Param.ITEM_NAME, preset_name ?: "no_preset_name")
} else if (mv is MVersionInternal) {
Tracker.trackEvent("versions_dialog_select", "is_split", isSplit, FirebaseAnalytics.Param.ITEM_NAME, "internal")
Tracker.trackEvent("versions_dialog_select", "is_split", isSplit, Analytics.Param.ITEM_NAME, "internal")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import androidx.core.widget.NestedScrollView;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -51,6 +50,7 @@
import yuku.alkitab.base.widget.MaterialDialogJavaHelper;
import yuku.alkitab.base.widget.TwofingerLinearLayout;
import yuku.alkitab.debug.R;
import yuku.alkitab.tracking.Analytics;
import yuku.alkitab.tracking.Tracker;
import yuku.alkitab.util.Ari;
import yuku.alkitabintegration.display.Launcher;
Expand Down Expand Up @@ -250,7 +250,7 @@ public void handleMessage(@NonNull final Message msg) {
final String currentDate = yyyymmdd.get().format(ac.currentDate);
if (equals(startKind, ac.currentKind) && equals(startDate, currentDate)) {
AppLog.d(TAG, "Long read detected: now=[" + ac.currentKind + " " + currentDate + "]");
Tracker.trackEvent("devotion_longread", FirebaseAnalytics.Param.ITEM_NAME, startKind.name, FirebaseAnalytics.Param.START_DATE, yyyy_mm_dd.get().format(ac.currentDate));
Tracker.trackEvent("devotion_longread", Analytics.Param.ITEM_NAME, startKind.name, Analytics.Param.START_DATE, yyyy_mm_dd.get().format(ac.currentDate));
} else {
AppLog.d(TAG, "Not long enough for long read: previous=[" + startKind + " " + startDate + "] now=[" + ac.currentKind + " " + currentDate + "]");
}
Expand Down Expand Up @@ -434,7 +434,7 @@ void display() {
}

if (renderSucceeded) {
Tracker.trackEvent("devotion_render", FirebaseAnalytics.Param.ITEM_NAME, currentKind.name, FirebaseAnalytics.Param.START_DATE, yyyy_mm_dd.get().format(currentDate));
Tracker.trackEvent("devotion_render", Analytics.Param.ITEM_NAME, currentKind.name, Analytics.Param.START_DATE, yyyy_mm_dd.get().format(currentDate));
longReadChecker.start();
}
}
Expand Down
26 changes: 13 additions & 13 deletions Alkitab/src/main/java/yuku/alkitab/base/sync/SyncLoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import androidx.appcompat.widget.Toolbar;
import androidx.core.util.PatternsCompat;
import com.afollestad.materialdialogs.MaterialDialog;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import java.util.Locale;
import yuku.alkitab.base.App;
Expand All @@ -23,6 +22,7 @@
import yuku.alkitab.base.util.Background;
import yuku.alkitab.base.widget.MaterialDialogJavaHelper;
import yuku.alkitab.debug.R;
import yuku.alkitab.tracking.Analytics;
import yuku.alkitab.tracking.Tracker;

public class SyncLoginActivity extends BaseActivity {
Expand Down Expand Up @@ -115,9 +115,9 @@ protected void onCreate(final Bundle savedInstanceState) {
final Sync.LoginResponseJson response = Sync.register(form);

Tracker.trackEvent(
FirebaseAnalytics.Event.SIGN_UP,
FirebaseAnalytics.Param.METHOD, SIGNUP_METHOD,
FirebaseAnalytics.Param.SUCCESS, 1
Analytics.Event.SIGN_UP,
Analytics.Param.METHOD, SIGNUP_METHOD,
Analytics.Param.SUCCESS, 1
);

FirebaseCrashlytics.getInstance().setUserId(form.email);
Expand All @@ -128,9 +128,9 @@ protected void onCreate(final Bundle savedInstanceState) {
SyncRecorder.log(SyncRecorder.EventKind.register_failed, null, "email", email, "message", e.getMessage());

Tracker.trackEvent(
FirebaseAnalytics.Event.SIGN_UP,
FirebaseAnalytics.Param.METHOD, SIGNUP_METHOD,
FirebaseAnalytics.Param.SUCCESS, 0
Analytics.Event.SIGN_UP,
Analytics.Param.METHOD, SIGNUP_METHOD,
Analytics.Param.SUCCESS, 0
);

runOnUiThread(() -> MaterialDialogJavaHelper.showOkDialog(this, getString(R.string.sync_register_failed_with_reason, e.getMessage())));
Expand Down Expand Up @@ -169,9 +169,9 @@ protected void onCreate(final Bundle savedInstanceState) {
final Sync.LoginResponseJson response = Sync.login(email, password);

Tracker.trackEvent(
FirebaseAnalytics.Event.LOGIN,
FirebaseAnalytics.Param.METHOD, SIGNUP_METHOD,
FirebaseAnalytics.Param.SUCCESS, 1
Analytics.Event.LOGIN,
Analytics.Param.METHOD, SIGNUP_METHOD,
Analytics.Param.SUCCESS, 1
);

FirebaseCrashlytics.getInstance().setUserId(email);
Expand All @@ -182,9 +182,9 @@ protected void onCreate(final Bundle savedInstanceState) {
SyncRecorder.log(SyncRecorder.EventKind.login_failed, null, "email", email, "message", e.getMessage());

Tracker.trackEvent(
FirebaseAnalytics.Event.LOGIN,
FirebaseAnalytics.Param.METHOD, SIGNUP_METHOD,
FirebaseAnalytics.Param.SUCCESS, 0
Analytics.Event.LOGIN,
Analytics.Param.METHOD, SIGNUP_METHOD,
Analytics.Param.SUCCESS, 0
);

runOnUiThread(() -> MaterialDialogJavaHelper.showOkDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.util.HashMap;
import yuku.afw.storage.Preferences;
import yuku.alkitab.base.App;
import yuku.alkitab.base.S;
import yuku.alkitab.base.storage.Prefkey;
import yuku.alkitab.base.util.Sqlitil;
import yuku.alkitab.tracking.Analytics;
import yuku.alkitab.tracking.Tracker;

/**
Expand Down Expand Up @@ -66,7 +66,7 @@ public enum EventKind {
this.backgroundColor = backgroundColor;
}

static SparseArray<EventKind> codeIndex = new SparseArray<>();
static final SparseArray<EventKind> codeIndex = new SparseArray<>();

static {
for (final EventKind kind : values()) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public static void log(@NonNull final EventKind kind, @Nullable final String syn
}

S.getDb().insertSyncLog(Sqlitil.nowDateTime(), kind, syncSetName, params);
Tracker.trackEvent("sync", FirebaseAnalytics.Param.ITEM_NAME, kind.name());
Tracker.trackEvent("sync", Analytics.Param.ITEM_NAME, kind.name());
}

@Keep
Expand Down
16 changes: 8 additions & 8 deletions Alkitab/src/main/java/yuku/alkitab/songs/SongViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.drawerlayout.widget.DrawerLayout
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.analytics.FirebaseAnalytics
import java.io.IOException
import java.util.Locale
import yuku.afw.storage.Preferences
Expand All @@ -57,6 +56,7 @@ import yuku.alkitab.base.widget.MaterialDialogProgressHelper.progress
import yuku.alkitab.base.widget.TwofingerLinearLayout
import yuku.alkitab.debug.BuildConfig
import yuku.alkitab.debug.R
import yuku.alkitab.tracking.Analytics
import yuku.alkitab.tracking.Tracker
import yuku.alkitabintegration.display.Launcher
import yuku.kpri.model.Song
Expand Down Expand Up @@ -111,7 +111,7 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr
}

override fun onTwofingerScale(scale: Float) {
var newTextZoom = (textZoom * scale).toInt().coerceIn(50, 200)
val newTextZoom = (textZoom * scale).toInt().coerceIn(50, 200)

val f = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG_SONG)
if (f is SongFragment) {
Expand Down Expand Up @@ -172,9 +172,9 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr
if (currentBookName != null && currentSong != null) {
Tracker.trackEvent(
"song_playing",
FirebaseAnalytics.Param.ITEM_NAME, currentBookName + " " + currentSong.code,
FirebaseAnalytics.Param.ITEM_CATEGORY, currentBookName,
FirebaseAnalytics.Param.ITEM_VARIANT, currentSong.code
Analytics.Param.ITEM_NAME, currentBookName + " " + currentSong.code,
Analytics.Param.ITEM_CATEGORY, currentBookName,
Analytics.Param.ITEM_VARIANT, currentSong.code
)
}

Expand Down Expand Up @@ -1130,9 +1130,9 @@ class SongViewActivity : BaseLeftDrawerActivity(), SongFragment.ShouldOverrideUr
private fun trackSongSelect(bookName: String, code: String) {
Tracker.trackEvent(
"song_select",
FirebaseAnalytics.Param.ITEM_NAME, "$bookName $code",
FirebaseAnalytics.Param.ITEM_CATEGORY, bookName,
FirebaseAnalytics.Param.ITEM_VARIANT, code
Analytics.Param.ITEM_NAME, "$bookName $code",
Analytics.Param.ITEM_CATEGORY, bookName,
Analytics.Param.ITEM_VARIANT, code
)
}

Expand Down
28 changes: 28 additions & 0 deletions Alkitab/src/main/java/yuku/alkitab/tracking/Analytics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package yuku.alkitab.tracking;

import androidx.annotation.NonNull;

public final class Analytics {
public static class Param {
@NonNull
public static final String START_DATE = "start_date";
@NonNull
public static final String ITEM_CATEGORY = "item_category";
@NonNull
public static final String ITEM_NAME = "item_name";
@NonNull
public static final String METHOD = "method";
@NonNull
public static final String SUCCESS = "success";
@NonNull
public static final String ITEM_VARIANT = "item_variant";
}

public static class Event {
@NonNull
public static final String LOGIN = "login";
@NonNull
public static final String SIGN_UP = "sign_up";

}
}
34 changes: 3 additions & 31 deletions Alkitab/src/main/java/yuku/alkitab/tracking/Tracker.kt
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
package yuku.alkitab.tracking

import android.content.Context
import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
import java.util.concurrent.Executors
import yuku.alkitab.base.util.AppLog

object Tracker {
private lateinit var fa: FirebaseAnalytics

@JvmStatic
fun init(context: Context) {
if (!::fa.isInitialized) {
fa = FirebaseAnalytics.getInstance(context)
}
}
private const val TAG = "Tracker"

@JvmStatic
fun trackEvent(category: String, vararg paramPairs: Any) {
var bundle: Bundle? = null
if (paramPairs.isNotEmpty()) {
if (paramPairs.size % 2 != 0) {
throw IllegalArgumentException("Param pairs should have even number of elements. Got: $paramPairs")
}

bundle = Bundle()
for (i in paramPairs.indices step 2) {
val key = paramPairs[i] as String
when (val value = paramPairs[i + 1]) {
is Int -> bundle.putInt(key, value)
is Double -> bundle.putDouble(key, value)
is Float -> bundle.putDouble(key, value.toDouble())
else -> bundle.putString(key, value.toString())
}
}
}

fa.logEvent(category, bundle)
AppLog.d(TAG, "$category: $paramPairs")
}
}

0 comments on commit e8a4a2c

Please sign in to comment.