Create addUserData method in the analytics providers
This allows us to globally add arbitrary data to the events and transactions
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
8057bda977
commit
367bbc7e4b
@@ -149,6 +149,12 @@ class DefaultAnalyticsService(
|
||||
}
|
||||
}
|
||||
|
||||
override fun addUserData(key: String, value: String) {
|
||||
if (userConsent.get()) {
|
||||
analyticsProviders.onEach { it.addUserData(key, value) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun startTransaction(name: String, operation: String?): AnalyticsTransaction {
|
||||
return if (userConsent.get()) {
|
||||
analyticsProviders.firstNotNullOfOrNull { it.startTransaction(name, operation) }
|
||||
|
||||
@@ -35,6 +35,11 @@ interface AnalyticsTracker {
|
||||
* Super properties are added to any tracked event automatically.
|
||||
*/
|
||||
fun updateSuperProperties(updatedProperties: SuperProperties)
|
||||
|
||||
/**
|
||||
* Adds user data that will be sent with every event.
|
||||
*/
|
||||
fun addUserData(key: String, value: String) {}
|
||||
}
|
||||
|
||||
fun AnalyticsTracker.captureInteraction(name: Interaction.Name, type: Interaction.InteractionType? = null) {
|
||||
|
||||
@@ -86,6 +86,10 @@ class SentryAnalyticsProvider(
|
||||
override fun updateSuperProperties(updatedProperties: SuperProperties) {
|
||||
}
|
||||
|
||||
override fun addUserData(key: String, value: String) {
|
||||
Sentry.setExtra(key, value)
|
||||
}
|
||||
|
||||
override fun trackError(throwable: Throwable) {
|
||||
Sentry.captureException(throwable)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user