-
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 #107 from azrael8576/feat/core-analytics
- Loading branch information
Showing
28 changed files
with
411 additions
and
7 deletions.
There are no files selected for viewing
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,86 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "YourProjectId", | ||
"project_id": "abc", | ||
"storage_bucket": "abc" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "Your:App:Id", | ||
"android_client_info": { | ||
"package_name": "com.wei.picquest" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "Your:App:Id", | ||
"android_client_info": { | ||
"package_name": "com.wei.picquest.debug" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "Your:App:Id", | ||
"android_client_info": { | ||
"package_name": "com.wei.picquest.demo" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "Your:App:Id", | ||
"android_client_info": { | ||
"package_name": "com.wei.picquest.demo.debug" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
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
38 changes: 38 additions & 0 deletions
38
build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.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,38 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension | ||
import com.wei.picquest.libs | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
|
||
class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.google.gms.google-services") | ||
apply("com.google.firebase.firebase-perf") | ||
apply("com.google.firebase.crashlytics") | ||
} | ||
|
||
dependencies { | ||
val bom = libs.findLibrary("firebase-bom").get() | ||
add("implementation", platform(bom)) | ||
"implementation"(libs.findLibrary("firebase.analytics").get()) | ||
"implementation"(libs.findLibrary("firebase.performance").get()) | ||
"implementation"(libs.findLibrary("firebase.crashlytics").get()) | ||
} | ||
|
||
extensions.configure<ApplicationExtension> { | ||
buildTypes.configureEach { | ||
// Disable the Crashlytics mapping file upload. This feature should only be | ||
// enabled if a Firebase backend is available and configured in | ||
// google-services.json. | ||
configure<CrashlyticsExtension> { | ||
mappingFileUploadEnabled = false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,16 @@ | ||
plugins { | ||
alias(libs.plugins.pq.android.library) | ||
alias(libs.plugins.pq.android.library.compose) | ||
alias(libs.plugins.pq.android.hilt) | ||
} | ||
|
||
android { | ||
namespace = "com.wei.picquest.core.analytics" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.compose.runtime) | ||
|
||
prodImplementation(platform(libs.firebase.bom)) | ||
prodImplementation(libs.firebase.analytics) | ||
} |
13 changes: 13 additions & 0 deletions
13
core/analytics/src/demo/java/com/wei/picquest/core/analytics/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,13 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal abstract class AnalyticsModule { | ||
@Binds | ||
abstract fun bindsAnalyticsHelper(analyticsHelperImpl: StubAnalyticsHelper): AnalyticsHelper | ||
} |
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> |
42 changes: 42 additions & 0 deletions
42
core/analytics/src/main/java/com/wei/picquest/core/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,42 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
/** | ||
* Represents an analytics event. | ||
* | ||
* @param type - the event type. Wherever possible use one of the standard | ||
* event `Types`, however, if there is no suitable event type already defined, a custom event can be | ||
* defined as long as it is configured in your backend analytics system (for example, by creating a | ||
* Firebase Analytics custom event). | ||
* | ||
* @param extras - list of parameters which supply additional context to the event. See `Param`. | ||
*/ | ||
data class AnalyticsEvent( | ||
val type: String, | ||
val extras: List<Param> = emptyList(), | ||
) { | ||
// Standard analytics types. | ||
class Types { | ||
companion object { | ||
const val SCREEN_VIEW = "screen_view" // (extras: SCREEN_NAME) | ||
} | ||
} | ||
|
||
/** | ||
* A key-value pair used to supply extra context to an analytics event. | ||
* | ||
* @param key - the parameter key. Wherever possible use one of the standard `ParamKeys`, | ||
* however, if no suitable key is available you can define your own as long as it is configured | ||
* in your backend analytics system (for example, by creating a Firebase Analytics custom | ||
* parameter). | ||
* | ||
* @param value - the parameter value. | ||
*/ | ||
data class Param(val key: String, val value: String) | ||
|
||
// Standard parameter keys. | ||
class ParamKeys { | ||
companion object { | ||
const val SCREEN_NAME = "screen_name" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
core/analytics/src/main/java/com/wei/picquest/core/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,9 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
/** | ||
* Interface for logging analytics events. See `FirebaseAnalyticsHelper` and | ||
* `StubAnalyticsHelper` for implementations. | ||
*/ | ||
interface AnalyticsHelper { | ||
fun logEvent(event: AnalyticsEvent) | ||
} |
8 changes: 8 additions & 0 deletions
8
core/analytics/src/main/java/com/wei/picquest/core/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,8 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
/** | ||
* Implementation of AnalyticsHelper which does nothing. Useful for tests and previews. | ||
*/ | ||
class NoOpAnalyticsHelper : AnalyticsHelper { | ||
override fun logEvent(event: AnalyticsEvent) = Unit | ||
} |
18 changes: 18 additions & 0 deletions
18
core/analytics/src/main/java/com/wei/picquest/core/analytics/StubAnalyticsHelper.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,18 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
import timber.log.Timber | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* An implementation of AnalyticsHelper just writes the events to logcat. Used in builds where no | ||
* analytics events should be sent to a backend. | ||
*/ | ||
@Singleton | ||
internal class StubAnalyticsHelper | ||
@Inject | ||
constructor() : AnalyticsHelper { | ||
override fun logEvent(event: AnalyticsEvent) { | ||
Timber.d("StubAnalyticsHelper, Received analytics event: $event") | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/analytics/src/main/java/com/wei/picquest/core/analytics/UiHelpers.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,13 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
import androidx.compose.runtime.staticCompositionLocalOf | ||
|
||
/** | ||
* Global key used to obtain access to the AnalyticsHelper through a CompositionLocal. | ||
*/ | ||
val LocalAnalyticsHelper = | ||
staticCompositionLocalOf<AnalyticsHelper> { | ||
// Provide a default AnalyticsHelper which does nothing. This is so that tests and previews | ||
// do not have to provide one. For real app builds provide a different implementation. | ||
NoOpAnalyticsHelper() | ||
} |
26 changes: 26 additions & 0 deletions
26
core/analytics/src/prod/java/com/wei/picquest/core/analytics/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,26 @@ | ||
package com.wei.picquest.core.analytics | ||
|
||
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 { | ||
return Firebase.analytics | ||
} | ||
} | ||
} |
Oops, something went wrong.