Skip to content

Commit

Permalink
Add AppOpen analytics event
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylwester Zieliński committed Apr 13, 2022
1 parent 2d049cd commit 056f2bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ package no.nordicsemi.android.nrftoolbox

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import no.nordicsemi.android.analytics.AppAnalytics
import no.nordicsemi.android.analytics.AppOpenEvent
import javax.inject.Inject

@HiltAndroidApp
class NrfToolboxApplication : Application()
class NrfToolboxApplication : Application() {

@Inject
lateinit var analytics: AppAnalytics

override fun onCreate() {
super.onCreate()

analytics.logEvent(AppOpenEvent)
}
}
11 changes: 0 additions & 11 deletions lib_analytics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,3 @@ dependencies {
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics'
}

task copyGoogleIdValuesTask(type: Copy) {
from 'src/main/res/values/values.xml'
into "$project.buildDir/generated/res/google-services/release/values/"
}

import com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask

tasks.withType(UploadMappingFileTask).configureEach {
dependsOn(copyGoogleIdValuesTask)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package no.nordicsemi.android.analytics

import android.annotation.SuppressLint
import android.content.Context
import com.google.firebase.analytics.FirebaseAnalytics
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton

@SuppressLint("MissingPermission")
@Singleton
class AppAnalytics @Inject constructor(
@ApplicationContext
Expand All @@ -14,7 +16,7 @@ class AppAnalytics @Inject constructor(

private val firebase by lazy { FirebaseAnalytics.getInstance(context) }

fun logEvent(event: ProfileOpenEvent) {
firebase.logEvent(event.firebaseName, null)
fun logEvent(event: AppEvent) {
firebase.logEvent(event.eventName, null)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package no.nordicsemi.android.analytics

enum class ProfileOpenEvent(internal val firebaseName: String) {
sealed interface AppEvent {
val eventName: String
}

object AppOpenEvent : AppEvent {
override val eventName: String = "APP_OPEN"
}

enum class ProfileOpenEvent(override val eventName: String) : AppEvent {
BPS("BPS_PROFILE_OPEN"),
CGMS("CGMS_PROFILE_OPEN"),
CSC("CSC_PROFILE_OPEN"),
Expand Down

0 comments on commit 056f2bc

Please sign in to comment.