From 5af4d2028ff4e7d61dc0b127e7272601dfc8c3eb Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 29 Oct 2022 22:03:39 -0600 Subject: [PATCH] Replace Firebase analytics with Plausible --- app/build.gradle | 5 +++-- .../simplemarkdown/utility/AnalyticsHelper.kt | 19 ------------------- .../simplemarkdown/utility/AnalyticsHelper.kt | 8 -------- .../view/activity/MainActivity.kt | 18 +++++++++--------- .../view/fragment/MainFragment.kt | 9 ++++----- .../view/fragment/MarkdownInfoFragment.kt | 4 ++-- .../fragment/SettingsContainerFragment.kt | 5 ++--- .../view/fragment/SupportFragment.kt | 5 ++--- app/src/main/res/values/strings.xml | 2 ++ .../utility/FirebaseAnalyticsHelper.kt | 19 ------------------- 10 files changed, 24 insertions(+), 70 deletions(-) delete mode 100644 app/src/free/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt delete mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt delete mode 100644 app/src/play/java/com/wbrawner/simplemarkdown/utility/FirebaseAnalyticsHelper.kt diff --git a/app/build.gradle b/app/build.gradle index b067413..1b8e8b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { versionName "0.8.13" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "boolean", "ENABLE_CUSTOM_CSS", "false" + buildConfigField "boolean", "ENABLE_CUSTOM_CSS", "true" } signingConfigs { playRelease { @@ -106,6 +106,7 @@ dependencies { androidTestUtil "androidx.test:orchestrator:1.4.1" androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' + implementation 'com.wbrawner.plausible:plausible-android:0.1.0' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'androidx.preference:preference-ktx:1.2.0' implementation "androidx.fragment:fragment-ktx:1.5.4" @@ -117,7 +118,6 @@ dependencies { playImplementation 'com.android.billingclient:billing:5.0.0' playImplementation 'com.google.android.play:core-ktx:1.8.1' playImplementation 'com.google.firebase:firebase-crashlytics:18.3.1' - playImplementation 'com.google.firebase:firebase-analytics:21.2.0' implementation "androidx.core:core-ktx:1.9.0" implementation 'androidx.browser:browser:1.4.0' def coroutines_version = "1.6.4" @@ -137,6 +137,7 @@ android.productFlavors.each { flavor -> } repositories { mavenCentral() + mavenLocal() } jacoco { diff --git a/app/src/free/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt b/app/src/free/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt deleted file mode 100644 index d332bcc..0000000 --- a/app/src/free/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.wbrawner.simplemarkdown.utility - -import android.content.Context -import com.wbrawner.simplemarkdown.BuildConfig -import timber.log.Timber - -class NoopAnalyticsHelper(context: Context): AnalyticsHelper() { - override fun setUserProperty(name: String, value: String) { - if (BuildConfig.DEBUG) { - Timber.tag("NoopAnalyticsHelper").d("setting user property $name to $value") - } - } - - override fun trackPageView(name: String) { - Timber.tag("NoopAnalyticsHelper").d("user viewed $name page") - } -} - -fun AnalyticsHelper.Companion.init(context: Context) = NoopAnalyticsHelper(context) diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt b/app/src/main/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt deleted file mode 100644 index cba8d70..0000000 --- a/app/src/main/java/com/wbrawner/simplemarkdown/utility/AnalyticsHelper.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.wbrawner.simplemarkdown.utility - -abstract class AnalyticsHelper { - abstract fun setUserProperty(name: String, value: String) - abstract fun trackPageView(name: String) - - companion object -} diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt index 01a3a74..44f5cfd 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt @@ -7,24 +7,24 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.navigation.findNavController import androidx.preference.PreferenceManager +import com.wbrawner.plausible.android.Plausible import com.wbrawner.simplemarkdown.R -import com.wbrawner.simplemarkdown.utility.AnalyticsHelper -import com.wbrawner.simplemarkdown.utility.init class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsResultCallback { - private val analyticsHelper = AnalyticsHelper.init(this) - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) - analyticsHelper.setUserProperty("autosave", sharedPreferences.getBoolean("autosave", true).toString()) + val preferences = mutableMapOf() + preferences["Autosave"] = sharedPreferences.getBoolean("autosave", true).toString() val usingCustomCss = !getStringPref(R.string.pref_custom_css, null).isNullOrBlank() - analyticsHelper.setUserProperty("using_custom_css", usingCustomCss.toString()) + preferences["Custom CSS"] = usingCustomCss.toString() val darkModeSetting = getStringPref(R.string.pref_key_dark_mode, "auto").toString() - analyticsHelper.setUserProperty("dark_mode", darkModeSetting) - analyticsHelper.setUserProperty("error_reports_enabled", getBooleanPref(R.string.pref_key_error_reports_enabled, true).toString()) - analyticsHelper.setUserProperty("readability_enabled", getBooleanPref(R.string.readability_enabled, false).toString()) + preferences["Dark Mode"] = darkModeSetting + preferences["Error Reports"] = + getBooleanPref(R.string.pref_key_error_reports_enabled, true).toString() + preferences["Readability"] = getBooleanPref(R.string.readability_enabled, false).toString() + Plausible.event("settings", props = preferences, url = "/") } override fun onBackPressed() { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MainFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MainFragment.kt index 2185fb4..de5e2c9 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MainFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MainFragment.kt @@ -22,11 +22,10 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager +import com.wbrawner.plausible.android.Plausible import com.wbrawner.simplemarkdown.R -import com.wbrawner.simplemarkdown.utility.AnalyticsHelper import com.wbrawner.simplemarkdown.utility.ErrorHandler import com.wbrawner.simplemarkdown.utility.errorHandlerImpl -import com.wbrawner.simplemarkdown.utility.init import com.wbrawner.simplemarkdown.view.adapter.EditPagerAdapter import com.wbrawner.simplemarkdown.viewmodel.MarkdownViewModel import kotlinx.android.synthetic.main.fragment_main.* @@ -82,9 +81,9 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba tabLayout!!.visibility = View.GONE } @Suppress("CAST_NEVER_SUCCEEDS") - viewModel.fileName.observe(viewLifecycleOwner, { + viewModel.fileName.observe(viewLifecycleOwner) { toolbar?.title = it - }) + } } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -146,7 +145,7 @@ class MainFragment : Fragment(), ActivityCompat.OnRequestPermissionsResultCallba override fun onStart() { super.onStart() - AnalyticsHelper.init(requireContext()).trackPageView("Edit") + Plausible.pageView("") lifecycleScope.launch { withContext(Dispatchers.IO) { val enableErrorReports = PreferenceManager.getDefaultSharedPreferences(requireContext()) diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MarkdownInfoFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MarkdownInfoFragment.kt index 5355aae..52a8041 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MarkdownInfoFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/MarkdownInfoFragment.kt @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.navigation.ui.setupWithNavController +import com.wbrawner.plausible.android.Plausible import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.utility.* import kotlinx.android.synthetic.main.fragment_markdown_info.* @@ -19,7 +20,6 @@ import kotlinx.coroutines.launch class MarkdownInfoFragment : Fragment() { private val errorHandler: ErrorHandler by errorHandlerImpl() - private lateinit var analyticsHelper: AnalyticsHelper override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -75,7 +75,7 @@ class MarkdownInfoFragment : Fragment() { override fun onStart() { super.onStart() arguments?.getString(EXTRA_FILE)?.let { - AnalyticsHelper.init(requireContext()).trackPageView(it) + Plausible.pageView(it) } } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsContainerFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsContainerFragment.kt index db40e3e..d9188d7 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsContainerFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsContainerFragment.kt @@ -8,9 +8,8 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import androidx.navigation.ui.setupWithNavController +import com.wbrawner.plausible.android.Plausible import com.wbrawner.simplemarkdown.R -import com.wbrawner.simplemarkdown.utility.AnalyticsHelper -import com.wbrawner.simplemarkdown.utility.init import kotlinx.android.synthetic.main.fragment_settings.* class SettingsContainerFragment : Fragment() { @@ -30,6 +29,6 @@ class SettingsContainerFragment : Fragment() { override fun onStart() { super.onStart() - AnalyticsHelper.init(requireContext()).trackPageView("Settings") + Plausible.pageView("Settings") } } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SupportFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SupportFragment.kt index ffd9a8b..1bef766 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SupportFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SupportFragment.kt @@ -12,10 +12,9 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController import androidx.navigation.ui.setupWithNavController +import com.wbrawner.plausible.android.Plausible import com.wbrawner.simplemarkdown.R -import com.wbrawner.simplemarkdown.utility.AnalyticsHelper import com.wbrawner.simplemarkdown.utility.SupportLinkProvider -import com.wbrawner.simplemarkdown.utility.init import kotlinx.android.synthetic.main.fragment_support.* class SupportFragment : Fragment() { @@ -55,7 +54,7 @@ class SupportFragment : Fragment() { override fun onStart() { super.onStart() - AnalyticsHelper.init(requireContext()).trackPageView("Support") + Plausible.pageView("Support") } // override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d45b3f1..a621eb6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,4 +86,6 @@ @string/pref_key_dark_mode_dark @string/pref_key_dark_mode_auto + https://plausible.wbrawner.com + simplemarkdown.android.wbrawner.com diff --git a/app/src/play/java/com/wbrawner/simplemarkdown/utility/FirebaseAnalyticsHelper.kt b/app/src/play/java/com/wbrawner/simplemarkdown/utility/FirebaseAnalyticsHelper.kt deleted file mode 100644 index 6493226..0000000 --- a/app/src/play/java/com/wbrawner/simplemarkdown/utility/FirebaseAnalyticsHelper.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.wbrawner.simplemarkdown.utility - -import android.content.Context -import android.os.Bundle -import com.google.firebase.analytics.FirebaseAnalytics - -class FirebaseAnalyticsHelper(context: Context): AnalyticsHelper() { - private val firebaseAnalytics = FirebaseAnalytics.getInstance(context) - - override fun setUserProperty(name: String, value: String) { - firebaseAnalytics.setUserProperty(name, value) - } - - override fun trackPageView(name: String) { - firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, Bundle().apply { putString(FirebaseAnalytics.Param.SCREEN_NAME, name) }) - } -} - -fun AnalyticsHelper.Companion.init(context: Context) = FirebaseAnalyticsHelper(context)