Improve ScreenTracker.
This commit is contained in:
parent
f11dd23327
commit
37c41131ea
5 changed files with 20 additions and 21 deletions
|
|
@ -37,7 +37,7 @@ class TroubleshootNotificationsNode @AssistedInject constructor(
|
||||||
) : Node(buildContext, plugins = plugins) {
|
) : Node(buildContext, plugins = plugins) {
|
||||||
@Composable
|
@Composable
|
||||||
override fun View(modifier: Modifier) {
|
override fun View(modifier: Modifier) {
|
||||||
screenTracker.TrackScreen(this, MobileScreen.ScreenName.NotificationTroubleshoot)
|
screenTracker.TrackScreen(MobileScreen.ScreenName.NotificationTroubleshoot)
|
||||||
val state = presenter.present()
|
val state = presenter.present()
|
||||||
TroubleshootNotificationsView(
|
TroubleshootNotificationsView(
|
||||||
state = state,
|
state = state,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
api(projects.services.analyticsproviders.api)
|
api(projects.services.analyticsproviders.api)
|
||||||
api(projects.services.toolbox.api)
|
api(projects.services.toolbox.api)
|
||||||
api(libs.appyx.core)
|
|
||||||
implementation(libs.coroutines.core)
|
implementation(libs.coroutines.core)
|
||||||
implementation(projects.libraries.matrix.api)
|
implementation(projects.libraries.matrix.api)
|
||||||
implementation(projects.libraries.core)
|
implementation(projects.libraries.core)
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,11 @@
|
||||||
package io.element.android.services.analytics.api
|
package io.element.android.services.analytics.api
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import com.bumble.appyx.core.node.Node
|
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
import im.vector.app.features.analytics.plan.MobileScreen
|
||||||
|
|
||||||
interface ScreenTracker {
|
interface ScreenTracker {
|
||||||
@Composable
|
@Composable
|
||||||
fun TrackScreen(
|
fun TrackScreen(
|
||||||
node: Node,
|
|
||||||
screen: MobileScreen.ScreenName,
|
screen: MobileScreen.ScreenName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ dependencies {
|
||||||
implementation(projects.libraries.androidutils)
|
implementation(projects.libraries.androidutils)
|
||||||
implementation(projects.libraries.core)
|
implementation(projects.libraries.core)
|
||||||
implementation(projects.libraries.architecture)
|
implementation(projects.libraries.architecture)
|
||||||
|
implementation(projects.libraries.designsystem)
|
||||||
implementation(projects.libraries.sessionStorage.api)
|
implementation(projects.libraries.sessionStorage.api)
|
||||||
|
|
||||||
api(projects.services.analyticsproviders.api)
|
api(projects.services.analyticsproviders.api)
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,14 @@
|
||||||
package io.element.android.services.analytics.impl
|
package io.element.android.services.analytics.impl
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.getValue
|
||||||
import com.bumble.appyx.core.lifecycle.subscribe
|
import androidx.compose.runtime.mutableLongStateOf
|
||||||
import com.bumble.appyx.core.node.Node
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import com.squareup.anvil.annotations.ContributesBinding
|
import com.squareup.anvil.annotations.ContributesBinding
|
||||||
import im.vector.app.features.analytics.plan.MobileScreen
|
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.libraries.di.AppScope
|
||||||
import io.element.android.services.analytics.api.AnalyticsService
|
import io.element.android.services.analytics.api.AnalyticsService
|
||||||
import io.element.android.services.analytics.api.ScreenTracker
|
import io.element.android.services.analytics.api.ScreenTracker
|
||||||
|
|
@ -35,24 +38,22 @@ class DefaultScreenTracker @Inject constructor(
|
||||||
) : ScreenTracker {
|
) : ScreenTracker {
|
||||||
@Composable
|
@Composable
|
||||||
override fun TrackScreen(
|
override fun TrackScreen(
|
||||||
node: Node,
|
|
||||||
screen: MobileScreen.ScreenName,
|
screen: MobileScreen.ScreenName,
|
||||||
) {
|
) {
|
||||||
LaunchedEffect(Unit) {
|
var startTime by remember { mutableLongStateOf(0L) }
|
||||||
var startTime = 0L
|
OnLifecycleEvent { _, event ->
|
||||||
node.lifecycle.subscribe(
|
when (event) {
|
||||||
onResume = {
|
Lifecycle.Event.ON_RESUME -> {
|
||||||
startTime = systemClock.epochMillis()
|
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…
Add table
Add a link
Reference in a new issue