Skip to content

Commit

Permalink
Tune analytics logic
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed Apr 21, 2024
1 parent cb2ed1f commit 8ecb86e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.ktx.Firebase
import universe.constellation.orion.viewer.BuildConfig
import universe.constellation.orion.viewer.currentTimeMillis
import universe.constellation.orion.viewer.filemanager.FileChooserAdapter
import universe.constellation.orion.viewer.filemanager.fileExtension
import java.io.File

Expand All @@ -19,8 +20,6 @@ class FireBaseAnalytics : Analytics() {

private lateinit var analytics: FirebaseAnalytics

private var intentId = 0L

private var lastTime = System.currentTimeMillis()

override fun init(): Analytics {
Expand All @@ -32,9 +31,6 @@ class FireBaseAnalytics : Analytics() {

override fun onNewIntent(contentResolver: ContentResolver, intent: Intent, isUserIntent: Boolean, isNewUI: Boolean) {
lastTime = System.currentTimeMillis()
if (isUserIntent) {
intentId = lastTime
}

logEvent("onNewIntent") {
param("scheme", intent.scheme)
Expand Down Expand Up @@ -70,18 +66,23 @@ class FireBaseAnalytics : Analytics() {
param(key, value ?: "<null>")
}

override fun fileOpenedSuccessfully() {
fileInfo(true)
override fun fileOpenedSuccessfully(file: File) {
fileInfo(true) {
val hash = (file.length().hashCode().toLong() shl 32) + file.name.hashCode()
param("book_id", hash)
param("book_ext", file.name.fileExtension.takeIf { FileChooserAdapter.supportedExtensions.contains(it) } ?: "<unknown extension>")
}
}

override fun errorDuringInitialFileOpen() {
fileInfo(false)
}

private fun fileInfo(successful: Boolean) {
private inline fun fileInfo(successful: Boolean, crossinline block: ParametersBuilder.() -> Unit = {}) {
logEvent("fileOpened") {
param("time", currentTimeMillis() - lastTime)
param("state", successful.toString())
block()
}
}

Expand All @@ -108,7 +109,6 @@ class FireBaseAnalytics : Analytics() {
) {
analytics.logEvent(event) {
block()
param("id", intentId)
}
}
}
1 change: 1 addition & 0 deletions orion-viewer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />

<activity android:name=".OrionViewerActivity"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.ContentResolver
import android.content.Intent
import android.provider.Settings
import universe.constellation.orion.viewer.BuildConfig
import java.io.File

const val TAP_HELP_DIALOG = "TAPHELPDialog"
const val FALLBACK_DIALOG = "FALLBACK"
Expand All @@ -20,7 +21,7 @@ open class Analytics {

}

open fun fileOpenedSuccessfully() {
open fun fileOpenedSuccessfully(file: File) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class FileChooserAdapter(

companion object {

val supportedExtensions = setOf("cbz", "djvu", "djv", "pdf", "oxps", "tiff", "tif", "xps")
val supportedExtensions = setOf("cbz", "djvu", "djv", "pdf", "oxps", "xps", "tiff", "tif")

@JvmField
var DEFAULT_FILTER: FilenameFilter = FilenameFilter { dir, filename ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class OrionApplication : Application() {
override fun onCreate() {
logger = AndroidLogger
instance = this
super.onCreate()
analytics.onApplicationInit(options.isShowTapHelp)
super.onCreate()
updateLanguage(options.appLanguage)
logOrionAndDeviceInfo()
}
Expand Down

0 comments on commit 8ecb86e

Please sign in to comment.