-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from team-haribo/feature/302-add-custom-event…
…-to-firebase-analytics 🔀 :: (#302) - add custom event to firebase analytics
- Loading branch information
Showing
31 changed files
with
250 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
id("goms.android.core") | ||
id("goms.android.hilt") | ||
id("goms.android.compose") | ||
} | ||
|
||
android { | ||
namespace = "com.goms.analytics" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.compose.runtime) | ||
|
||
implementation(platform(libs.firebase.bom)) | ||
implementation(libs.firebase.analytics) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
core/analytics/src/androidTest/java/com/goms/analytics/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.goms.analytics | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.goms.analytics.test", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
20 changes: 20 additions & 0 deletions
20
core/analytics/src/main/java/com/goms/analytics/AnalyticsEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.goms.analytics | ||
|
||
data class AnalyticsEvent( | ||
val type: String, | ||
val extras: List<Param> = emptyList(), | ||
) { | ||
class Types { | ||
companion object { | ||
const val SCREEN_VIEW = "screen_view" | ||
} | ||
} | ||
|
||
data class Param(val key: String, val value: String) | ||
|
||
class ParamKeys { | ||
companion object { | ||
const val SCREEN_NAME = "screen_name" | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/analytics/src/main/java/com/goms/analytics/AnalyticsHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.goms.analytics | ||
|
||
interface AnalyticsHelper { | ||
fun logEvent(event: AnalyticsEvent) | ||
} |
21 changes: 21 additions & 0 deletions
21
core/analytics/src/main/java/com/goms/analytics/FirebaseAnalyticsHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.goms.analytics | ||
|
||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import com.google.firebase.analytics.ktx.logEvent | ||
import javax.inject.Inject | ||
|
||
internal class FirebaseAnalyticsHelper @Inject constructor( | ||
private val firebaseAnalytics: FirebaseAnalytics, | ||
) : AnalyticsHelper { | ||
|
||
override fun logEvent(event: AnalyticsEvent) { | ||
firebaseAnalytics.logEvent(event.type) { | ||
for (extra in event.extras) { | ||
param( | ||
key = extra.key.take(40), | ||
value = extra.value.take(100), | ||
) | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/analytics/src/main/java/com/goms/analytics/NoOpAnalyticsHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.goms.analytics | ||
|
||
class NoOpAnalyticsHelper : AnalyticsHelper { | ||
override fun logEvent(event: AnalyticsEvent) = Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.goms.analytics | ||
|
||
import androidx.compose.runtime.staticCompositionLocalOf | ||
|
||
val LocalAnalyticsHelper = staticCompositionLocalOf<AnalyticsHelper> { | ||
NoOpAnalyticsHelper() | ||
} |
28 changes: 28 additions & 0 deletions
28
core/analytics/src/main/java/com/goms/analytics/di/AnalyticsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.goms.analytics.di | ||
|
||
import com.goms.analytics.AnalyticsHelper | ||
import com.goms.analytics.FirebaseAnalyticsHelper | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import com.google.firebase.analytics.ktx.analytics | ||
import com.google.firebase.ktx.Firebase | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal abstract class AnalyticsModule { | ||
@Binds | ||
abstract fun bindsAnalyticsHelper( | ||
analyticsHelperImpl: FirebaseAnalyticsHelper | ||
): AnalyticsHelper | ||
|
||
companion object { | ||
@Provides | ||
@Singleton | ||
fun provideFirebaseAnalytics(): FirebaseAnalytics = Firebase.analytics | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/analytics/src/test/java/com/goms/analytics/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.goms.analytics | ||
|
||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.goms.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import com.goms.analytics.AnalyticsEvent | ||
import com.goms.analytics.AnalyticsEvent.Types | ||
import com.goms.analytics.AnalyticsEvent.ParamKeys | ||
import com.goms.analytics.AnalyticsEvent.Param | ||
import com.goms.analytics.AnalyticsHelper | ||
import com.goms.analytics.LocalAnalyticsHelper | ||
|
||
fun AnalyticsHelper.logScreenView(screenName: String) { | ||
logEvent( | ||
AnalyticsEvent( | ||
type = Types.SCREEN_VIEW, | ||
extras = listOf( | ||
Param(ParamKeys.SCREEN_NAME, screenName), | ||
), | ||
), | ||
) | ||
} | ||
|
||
@Composable | ||
fun TrackScreenViewEvent( | ||
screenName: String, | ||
analyticsHelper: AnalyticsHelper = LocalAnalyticsHelper.current, | ||
) = DisposableEffect(Unit) { | ||
analyticsHelper.logScreenView(screenName) | ||
onDispose {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.