From ad7d2bdbe56cc6e5854357aa868d66846e69b491 Mon Sep 17 00:00:00 2001 From: feilong Date: Sun, 29 Mar 2020 08:55:47 +0800 Subject: [PATCH] add firebase tracker for detail page. --- .../cimoc/ui/activity/DetailActivity.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/main/java/com/hiroshi/cimoc/ui/activity/DetailActivity.java b/app/src/main/java/com/hiroshi/cimoc/ui/activity/DetailActivity.java index 736be63c..684aa657 100644 --- a/app/src/main/java/com/hiroshi/cimoc/ui/activity/DetailActivity.java +++ b/app/src/main/java/com/hiroshi/cimoc/ui/activity/DetailActivity.java @@ -6,11 +6,15 @@ import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; + +import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.facebook.imagepipeline.core.ImagePipelineFactory; +import com.google.firebase.analytics.FirebaseAnalytics; +import com.hiroshi.cimoc.App; import com.hiroshi.cimoc.R; import com.hiroshi.cimoc.fresco.ControllerBuilderSupplierFactory; import com.hiroshi.cimoc.fresco.ImagePipelineFactoryBuilder; @@ -139,6 +143,14 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.detail_search_title: if (!StringUtils.isEmpty(mPresenter.getComic().getTitle())) { + if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) { + Bundle bundle = new Bundle(); + bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle()); + bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "byTitle"); + bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource()); + FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); + mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SEARCH, bundle); + } intent = ResultActivity.createIntent(this, mPresenter.getComic().getTitle(), null, ResultActivity.LAUNCH_MODE_SEARCH); startActivity(intent); } else { @@ -160,6 +172,15 @@ public boolean onOptionsItemSelected(MenuItem item) { intent.putExtra(Intent.EXTRA_TEXT, url); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, url)); + + // firebase analytics + if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) { + Bundle bundle = new Bundle(); + bundle.putString(FirebaseAnalytics.Param.CONTENT, url); + bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource()); + FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); + mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle); + } break; case R.id.detail_reverse_list: mDetailAdapter.reverse(); @@ -299,6 +320,15 @@ public void onComicLoadSuccess(Comic comic) { @Override public void onChapterLoadSuccess(List list) { hideProgressBar(); + if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) { + Bundle bundle = new Bundle(); + bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle()); + bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Title"); + bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource()); + bundle.putBoolean(FirebaseAnalytics.Param.SUCCESS, true); + FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); + mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle); + } if (mPresenter.getComic().getTitle() != null && mPresenter.getComic().getCover() != null) { mDetailAdapter.addAll(list); } @@ -306,6 +336,15 @@ public void onChapterLoadSuccess(List list) { @Override public void onParseError() { + if(App.getPreferenceManager().getBoolean(PreferenceManager.PREF_OTHER_FIREBASE_EVENT, true)) { + Bundle bundle = new Bundle(); + bundle.putString(FirebaseAnalytics.Param.CONTENT, mPresenter.getComic().getTitle()); + bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Title"); + bundle.putInt(FirebaseAnalytics.Param.SOURCE, mPresenter.getComic().getSource()); + bundle.putBoolean(FirebaseAnalytics.Param.SUCCESS, false); + FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); + mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle); + } hideProgressBar(); showSnackbar(R.string.common_parse_error); }