Browse Source

Improve ScreenTracker.

pull/2596/head
Benoit Marty 6 months ago committed by Benoit Marty
parent
commit
5a0e76677b
  1. 2
      features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsNode.kt
  2. 1
      services/analytics/api/build.gradle.kts
  3. 2
      services/analytics/api/src/main/kotlin/io/element/android/services/analytics/api/ScreenTracker.kt
  4. 1
      services/analytics/impl/build.gradle.kts
  5. 35
      services/analytics/impl/src/main/kotlin/io/element/android/services/analytics/impl/DefaultScreenTracker.kt

2
features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsNode.kt

@ -37,7 +37,7 @@ class TroubleshootNotificationsNode @AssistedInject constructor( @@ -37,7 +37,7 @@ class TroubleshootNotificationsNode @AssistedInject constructor(
) : Node(buildContext, plugins = plugins) {
@Composable
override fun View(modifier: Modifier) {
screenTracker.TrackScreen(this, MobileScreen.ScreenName.NotificationTroubleshoot)
screenTracker.TrackScreen(MobileScreen.ScreenName.NotificationTroubleshoot)
val state = presenter.present()
TroubleshootNotificationsView(
state = state,

1
services/analytics/api/build.gradle.kts

@ -24,7 +24,6 @@ android { @@ -24,7 +24,6 @@ android {
dependencies {
api(projects.services.analyticsproviders.api)
api(projects.services.toolbox.api)
api(libs.appyx.core)
implementation(libs.coroutines.core)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.core)

2
services/analytics/api/src/main/kotlin/io/element/android/services/analytics/api/ScreenTracker.kt

@ -17,13 +17,11 @@ @@ -17,13 +17,11 @@
package io.element.android.services.analytics.api
import androidx.compose.runtime.Composable
import com.bumble.appyx.core.node.Node
import im.vector.app.features.analytics.plan.MobileScreen
interface ScreenTracker {
@Composable
fun TrackScreen(
node: Node,
screen: MobileScreen.ScreenName,
)
}

1
services/analytics/impl/build.gradle.kts

@ -35,6 +35,7 @@ dependencies { @@ -35,6 +35,7 @@ dependencies {
implementation(projects.libraries.androidutils)
implementation(projects.libraries.core)
implementation(projects.libraries.architecture)
implementation(projects.libraries.designsystem)
implementation(projects.libraries.sessionStorage.api)
api(projects.services.analyticsproviders.api)

35
services/analytics/impl/src/main/kotlin/io/element/android/services/analytics/impl/DefaultScreenTracker.kt

@ -17,11 +17,14 @@ @@ -17,11 +17,14 @@
package io.element.android.services.analytics.impl
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import com.bumble.appyx.core.lifecycle.subscribe
import com.bumble.appyx.core.node.Node
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.lifecycle.Lifecycle
import com.squareup.anvil.annotations.ContributesBinding
import im.vector.app.features.analytics.plan.MobileScreen
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
import io.element.android.libraries.di.AppScope
import io.element.android.services.analytics.api.AnalyticsService
import io.element.android.services.analytics.api.ScreenTracker
@ -35,24 +38,22 @@ class DefaultScreenTracker @Inject constructor( @@ -35,24 +38,22 @@ class DefaultScreenTracker @Inject constructor(
) : ScreenTracker {
@Composable
override fun TrackScreen(
node: Node,
screen: MobileScreen.ScreenName,
) {
LaunchedEffect(Unit) {
var startTime = 0L
node.lifecycle.subscribe(
onResume = {
var startTime by remember { mutableLongStateOf(0L) }
OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
startTime = systemClock.epochMillis()
},
onPause = {
analyticsService.screen(
screen = MobileScreen(
durationMs = (systemClock.epochMillis() - startTime).toInt(),
screenName = screen
)
)
}
)
Lifecycle.Event.ON_PAUSE -> analyticsService.screen(
screen = MobileScreen(
durationMs = (systemClock.epochMillis() - startTime).toInt(),
screenName = screen
)
)
else -> Unit
}
}
}
}

Loading…
Cancel
Save