Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: countly general implementation fixes (WPB-14941) #3732

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> init(
context: Context,
analyticsSettings: AnalyticsSettings,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AnonymousAnalyticsRecorderImpl : AnonymousAnalyticsRecorder {

override fun halt() {
isConfigured = false
Countly.sharedInstance().halt()
Countly.sharedInstance().consent().removeConsentAll()
}

override suspend fun setTrackingIdentifierWithMerge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading