-
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.
- Loading branch information
1 parent
cc648c6
commit 9235d4d
Showing
12 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
app/src/benchmark/kotlin/ru/pixnews/inject/NoOpAnalyticsModule.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,22 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.inject | ||
|
||
import com.squareup.anvil.annotations.ContributesTo | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.Reusable | ||
import ru.pixnews.foundation.analytics.Analytics | ||
import ru.pixnews.foundation.analytics.NoOpAnalytics | ||
import ru.pixnews.foundation.di.base.scopes.AppScope | ||
|
||
@ContributesTo(AppScope::class, replaces = [AnalyticsModule::class]) | ||
@Module | ||
object NoOpAnalyticsModule { | ||
@Provides | ||
@Reusable | ||
fun provideAnalytics(): Analytics = NoOpAnalytics | ||
} |
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
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/ru/pixnews/inject/analytics/FirebaseAnalytics.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,36 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.inject.analytics | ||
|
||
import androidx.core.os.bundleOf | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.analytics.analytics | ||
import ru.pixnews.foundation.analytics.Analytics | ||
|
||
object FirebaseAnalytics : Analytics { | ||
private val analytics = Firebase.analytics | ||
|
||
override fun setEnableAnalytics(enable: Boolean) { | ||
analytics.setAnalyticsCollectionEnabled(enable) | ||
} | ||
|
||
override fun setUserId(userId: String?) { | ||
analytics.setUserId(userId) | ||
} | ||
|
||
override fun setUserProperty(name: String, value: String) { | ||
analytics.setUserProperty(name, value) | ||
} | ||
|
||
override fun logEvent(name: String, params: Map<String, *>?) { | ||
val paramsBundle = if (params != null) { | ||
bundleOf(pairs = params.entries.map { it.key to it.value }.toTypedArray()) | ||
} else { | ||
null | ||
} | ||
analytics.logEvent(name, paramsBundle) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/kotlin/ru/pixnews/inject/analytics/LoggingAnalytics.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,31 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.inject.analytics | ||
|
||
import co.touchlab.kermit.Logger | ||
import ru.pixnews.foundation.analytics.Analytics | ||
import javax.inject.Inject | ||
|
||
class LoggingAnalytics @Inject constructor( | ||
logger: Logger, | ||
) : Analytics { | ||
private val log: Logger = logger.withTag("Analytics") | ||
override fun setEnableAnalytics(enable: Boolean) { | ||
log.i { "setEnableAnalytics($enable)" } | ||
} | ||
|
||
override fun setUserId(userId: String?) { | ||
log.i { "setUserId($userId)" } | ||
} | ||
|
||
override fun setUserProperty(name: String, value: String) { | ||
log.i { "setUserProperty($name, $value)" } | ||
} | ||
|
||
override fun logEvent(name: String, params: Map<String, *>?) { | ||
log.i { "Event `$name`: $params" } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/release/kotlin/ru/pixnews/app/inject/FirebaseAnalyticsModule.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,23 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.app.inject | ||
|
||
import com.squareup.anvil.annotations.ContributesTo | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.Reusable | ||
import ru.pixnews.foundation.analytics.Analytics | ||
import ru.pixnews.foundation.di.base.scopes.AppScope | ||
import ru.pixnews.inject.AnalyticsModule | ||
import ru.pixnews.inject.analytics.FirebaseAnalytics | ||
|
||
@ContributesTo(AppScope::class, replaces = [AnalyticsModule::class]) | ||
@Module | ||
public object FirebaseAnalyticsModule { | ||
@Provides | ||
@Reusable | ||
fun bindsAnalytics(): Analytics = FirebaseAnalytics | ||
} |
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,6 @@ | ||
#!/bin/sh | ||
|
||
adb shell setprop log.tag.FA VERBOSE | ||
adb shell setprop log.tag.FA-SVC VERBOSE | ||
adb shell setprop debug.firebase.analytics.app ru.pixnews.debug | ||
# adb logcat -v time -s FA FA-SVC |