From 9c2c9a9c7a83b7f929a73743d858fbe51ae463c4 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Wed, 11 Dec 2024 16:40:46 +0100 Subject: [PATCH 1/2] feat: disable countly view tracking --- .../AnonymousAnalyticsManagerImpl.kt | 11 +++++++ .../AnonymousAnalyticsManagerTest.kt | 33 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerImpl.kt b/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerImpl.kt index 7e78362974f..0eba82a61ae 100644 --- a/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerImpl.kt +++ b/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerImpl.kt @@ -42,6 +42,9 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager { private val mutex = Mutex() private lateinit var coroutineScope: CoroutineScope + // TODO: Sync with product, when we want to enable view tracking, var for testing purposes + internal var VIEW_TRACKING_ENABLED: Boolean = false + override fun init( context: Context, analyticsSettings: AnalyticsSettings, @@ -172,6 +175,10 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager { } override fun recordView(screen: String) { + if (!VIEW_TRACKING_ENABLED) { + Log.d(TAG, "View tracking is disabled for this build.") + return + } coroutineScope.launch { mutex.withLock { if (!isAnonymousUsageDataEnabled) return@withLock @@ -181,6 +188,10 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager { } override fun stopView(screen: String) { + if (!VIEW_TRACKING_ENABLED) { + Log.d(TAG, "View tracking is disabled for this build.") + return + } coroutineScope.launch { mutex.withLock { if (!isAnonymousUsageDataEnabled) return@withLock diff --git a/core/analytics-enabled/src/test/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerTest.kt b/core/analytics-enabled/src/test/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerTest.kt index ec45685727f..691810ab5a3 100644 --- a/core/analytics-enabled/src/test/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerTest.kt +++ b/core/analytics-enabled/src/test/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsManagerTest.kt @@ -294,6 +294,37 @@ class AnonymousAnalyticsManagerTest { } } + @Test + fun givenManagerInitialized_whenRecordingViewAndFlagDisabled_thenScreenIsNOTRecorded() = runTest(dispatcher) { + // given + val (arrangement, manager) = Arrangement() + .withAnonymousAnalyticsRecorderConfigure() + .arrange(shouldTrackViews = false) + + val screen = "screen" + arrangement.withAnalyticsResult(Arrangement.existingIdentifierResult) + + // when + manager.init( + context = arrangement.context, + analyticsSettings = Arrangement.analyticsSettings, + analyticsResultFlow = arrangement.analyticsResultChannel.consumeAsFlow(), + anonymousAnalyticsRecorder = arrangement.anonymousAnalyticsRecorder, + migrationHandler = arrangement.migrationHandler, + propagationHandler = arrangement.propagationHandler, + dispatcher = dispatcher + ) + advanceUntilIdle() + + manager.recordView(screen) + advanceUntilIdle() + + // then + verify(exactly = 0) { + arrangement.anonymousAnalyticsRecorder.recordView(eq(screen)) + } + } + @Test fun givenManagerInitialized_whenStoppingView_thenScreenIsStoppedToRecord() = runTest(dispatcher) { // given @@ -387,7 +418,7 @@ class AnonymousAnalyticsManagerTest { AnonymousAnalyticsManagerImpl } - fun arrange() = this to manager + fun arrange(shouldTrackViews: Boolean = true) = this to manager.apply { VIEW_TRACKING_ENABLED = shouldTrackViews } fun withAnonymousAnalyticsRecorderConfigure() = apply { every { anonymousAnalyticsRecorder.configure(any(), any()) } returns Unit From 3bed9e1ac14e59b7e236c4d82cf4fe0dbbd493c4 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Wed, 11 Dec 2024 17:29:53 +0100 Subject: [PATCH 2/2] fix: use removeconsenAll instead of halt --- .../android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt b/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt index bee5ab38855..0bb72c5545d 100644 --- a/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt +++ b/core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt @@ -85,7 +85,7 @@ class AnonymousAnalyticsRecorderImpl : AnonymousAnalyticsRecorder { override fun halt() { isConfigured = false - Countly.sharedInstance().halt() + Countly.sharedInstance().consent().removeConsentAll() } override suspend fun setTrackingIdentifierWithMerge(