Skip to content

Commit

Permalink
fix: Conversations and Profile Views are reported individually
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Jan 9, 2025
1 parent eaa35af commit e3f9399
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
17 changes: 13 additions & 4 deletions app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,26 @@ class CurrentScreenManager @Inject constructor(
}

override fun onDestinationChanged(controller: NavController, destination: NavDestination, arguments: Bundle?) {
val currentView = currentScreenState.value.toString()
AnonymousAnalyticsManagerImpl.stopView(currentView)
val currentView = currentScreenState.value
handleViewAction(currentView) { screenName ->
AnonymousAnalyticsManagerImpl.stopView(screenName)
}
val currentItem = destination.toDestination()
currentScreenState.value = CurrentScreen.fromDestination(
currentItem,
arguments,
isApplicationVisibleFlow.value
)

val newView = currentScreenState.value.toString()
AnonymousAnalyticsManagerImpl.recordView(newView)
val newView = currentScreenState.value
handleViewAction(newView) { screenName ->
AnonymousAnalyticsManagerImpl.recordView(screenName)
}
}

private fun handleViewAction(screen: CurrentScreen, action: (String) -> Unit) {
val screenName = (screen as? CurrentScreen.SomeOther)?.route ?: screen.javaClass.simpleName
action(screenName)
}

override fun onCreate(owner: LifecycleOwner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager {
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
internal var VIEW_TRACKING_ENABLED: Boolean = true

override fun <T> init(
context: Context,
Expand Down Expand Up @@ -182,7 +182,7 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager {
coroutineScope.launch {
mutex.withLock {
if (!isAnonymousUsageDataEnabled) return@withLock
anonymousAnalyticsRecorder?.recordView(screen)
anonymousAnalyticsRecorder?.recordView(screen.convertToCamelCase())
}
}
}
Expand All @@ -195,7 +195,7 @@ object AnonymousAnalyticsManagerImpl : AnonymousAnalyticsManager {
coroutineScope.launch {
mutex.withLock {
if (!isAnonymousUsageDataEnabled) return@withLock
anonymousAnalyticsRecorder?.stopView(screen)
anonymousAnalyticsRecorder?.stopView(screen.convertToCamelCase())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Wire
* Copyright (C) 2025 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.feature.analytics

/**
* Converts a snake_case string to camelCase.
*/
fun String.convertToCamelCase(): String {
return this
.split('_')
.joinToString("") { it.replaceFirstChar { char -> char.uppercase() } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Wire
* Copyright (C) 2025 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.feature.analytics

import org.junit.Assert.assertEquals
import org.junit.Test

class StringExtTest {

@Test
fun `given single word string when converted then same string`() {
assertEquals("Username", "username".convertToCamelCase())
}

@Test
fun `given string with multiple underscores when converted then camel case string`() {
assertEquals("ThisIsATestCase", ("this_is_a_test_case").convertToCamelCase())
}

@Test
fun `given empty string when converted then empty string`() {
assertEquals("", ("").convertToCamelCase())
}

@Test
fun `given string with leading and trailing underscores when converted then camel case string`() {
assertEquals("LeadingAndTrailing", ("_leading_and_trailing_").convertToCamelCase())
}

@Test
fun `given string with numbers when converted then camel case string`() {
assertEquals("User123Name", ("user_123_name").convertToCamelCase())
}
}

0 comments on commit e3f9399

Please sign in to comment.