From 1f430a40159718859a5791922fb8728270faddcd Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 14 Mar 2024 11:25:44 +0100 Subject: [PATCH] Analytics tracker, support report custom properties not yet in schame --- .../im/vector/app/features/analytics/AnalyticsTracker.kt | 4 +++- .../app/features/analytics/impl/DefaultVectorAnalytics.kt | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt index 871782e473..669202dcbb 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt @@ -23,8 +23,10 @@ import im.vector.app.features.analytics.plan.UserProperties interface AnalyticsTracker { /** * Capture an Event. + * + * @param customProperties Some custom properties to attach to the event. */ - fun capture(event: VectorAnalyticsEvent) + fun capture(event: VectorAnalyticsEvent, customProperties: Map? = null) /** * Track a displayed screen. diff --git a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt index 2a7d0ac975..ff80c81ec7 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt @@ -171,11 +171,15 @@ class DefaultVectorAnalytics @Inject constructor( } } - override fun capture(event: VectorAnalyticsEvent) { + override fun capture(event: VectorAnalyticsEvent, customProperties: Map?) { Timber.tag(analyticsTag.value).d("capture($event)") posthog ?.takeIf { userConsent == true } - ?.capture(event.getName(), event.getProperties()?.toPostHogProperties()) + ?.capture( + event.getName(), + (customProperties.orEmpty() + + event.getProperties().orEmpty()).toPostHogProperties() + ) } override fun screen(screen: VectorAnalyticsScreen) {