Updated on 2026-08-14
This commit is contained in:
parent
9e948f7703
commit
147625bda1
40 changed files with 254 additions and 131 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.core.analytics
|
|||
|
||||
import com.tangem.core.analytics.api.*
|
||||
import com.tangem.core.analytics.models.AnalyticsEvent
|
||||
import com.tangem.core.analytics.models.ExceptionAnalyticsEvent
|
||||
import com.tangem.utils.coroutines.FeatureCoroutineExceptionHandler
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
|
|
@ -16,7 +17,9 @@ interface GlobalAnalyticsEventHandler :
|
|||
AnalyticsEventHandler,
|
||||
AnalyticsHandlerHolder,
|
||||
AnalyticsFilterHolder,
|
||||
ParamsInterceptorHolder
|
||||
ParamsInterceptorHolder,
|
||||
AnalyticsErrorHandler,
|
||||
AnalyticsExceptionHandler
|
||||
|
||||
object Analytics : GlobalAnalyticsEventHandler {
|
||||
|
||||
|
|
@ -72,6 +75,25 @@ object Analytics : GlobalAnalyticsEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
override fun sendErrorEvent(event: AnalyticsEvent) {
|
||||
analyticsScope.launch {
|
||||
event.params = applyParamsInterceptors(event)
|
||||
analyticsMutex.withLock {
|
||||
analyticsHandlers.filterIsInstance<AnalyticsErrorHandler>()
|
||||
.forEach { handler -> handler.sendErrorEvent(event) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendException(event: ExceptionAnalyticsEvent) {
|
||||
analyticsScope.launch {
|
||||
analyticsMutex.withLock {
|
||||
analyticsHandlers.filterIsInstance<AnalyticsExceptionHandler>()
|
||||
.forEach { it.sendException(event) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun applyParamsInterceptors(event: AnalyticsEvent): MutableMap<String, String> {
|
||||
val interceptedParams = event.params.toMutableMap()
|
||||
analyticsMutex.withLock {
|
||||
|
|
|
|||
|
|
@ -8,5 +8,9 @@ interface EventLogger {
|
|||
}
|
||||
|
||||
interface ErrorEventLogger {
|
||||
fun logErrorEvent(error: Throwable, params: Map<String, String> = emptyMap())
|
||||
fun logErrorEvent(event: String, params: Map<String, String> = emptyMap())
|
||||
}
|
||||
|
||||
interface ExceptionLogger {
|
||||
fun logException(error: Throwable, params: Map<String, String> = emptyMap())
|
||||
}
|
||||
|
|
@ -1,15 +1,25 @@
|
|||
package com.tangem.core.analytics.api
|
||||
|
||||
import com.tangem.core.analytics.models.AnalyticsEvent
|
||||
import com.tangem.core.analytics.models.ExceptionAnalyticsEvent
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
* Sends usual analytics events
|
||||
*/
|
||||
interface AnalyticsEventHandler {
|
||||
fun send(event: AnalyticsEvent)
|
||||
}
|
||||
|
||||
interface AnalyticsErrorHandler {
|
||||
fun sendErrorEvent(event: AnalyticsEvent)
|
||||
}
|
||||
|
||||
interface AnalyticsExceptionHandler {
|
||||
fun sendException(event: ExceptionAnalyticsEvent)
|
||||
}
|
||||
|
||||
interface AnalyticsHandler : AnalyticsEventHandler {
|
||||
|
||||
fun id(): String
|
||||
|
||||
fun send(eventId: String, params: Map<String, String> = emptyMap())
|
||||
|
|
@ -19,10 +29,6 @@ interface AnalyticsHandler : AnalyticsEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
interface ErrorEventHandler {
|
||||
fun send(error: Throwable, params: Map<String, String> = emptyMap())
|
||||
}
|
||||
|
||||
interface AnalyticsHandlerHolder {
|
||||
fun addHandler(name: String, handler: AnalyticsHandler)
|
||||
fun removeHandler(name: String): AnalyticsHandler?
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.tangem.core.analytics.di
|
||||
|
||||
import com.tangem.core.analytics.Analytics
|
||||
import com.tangem.core.analytics.api.AnalyticsErrorHandler
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.core.analytics.api.AnalyticsExceptionHandler
|
||||
import com.tangem.core.analytics.api.ParamsInterceptorHolder
|
||||
import com.tangem.core.analytics.filter.OneTimeEventFilter
|
||||
import com.tangem.domain.analytics.repository.AnalyticsRepository
|
||||
|
|
@ -21,6 +23,18 @@ internal object AnalyticsModule {
|
|||
return Analytics // todo replace after refactoring calling Analytics in whole project
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideAnalyticsErrorHandler(): AnalyticsErrorHandler {
|
||||
return Analytics
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideAnalyticsExceptionHandler(): AnalyticsExceptionHandler {
|
||||
return Analytics
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideParamsInterceptorHolder(): ParamsInterceptorHolder {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue