From a59ff2e0421c294ba9b41d0c178a1b07d711c060 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 13:17:43 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20countly=20general=20implementation=20fix?= =?UTF-8?q?es=20(WPB-14941)=20=F0=9F=8D=92=20(#3733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yamil Medina --- .../AnonymousAnalyticsManagerImpl.kt | 11 +++++++ .../AnonymousAnalyticsRecorderImpl.kt | 2 +- .../AnonymousAnalyticsManagerTest.kt | 33 ++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) 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/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( 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