1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 13:57:10 +09:00

DROID-3226 Analytics | Enhancement | Add analytics for the new navigation flow (#2078)

This commit is contained in:
Evgenii Kozlov 2025-02-10 13:23:00 +01:00 committed by Evgenii Kozlov
parent a8e00b3f62
commit cf36b0b1a1
9 changed files with 126 additions and 30 deletions

View file

@ -265,6 +265,7 @@ import com.anytypeio.anytype.presentation.extension.getObjRelationsViews
import com.anytypeio.anytype.presentation.extension.getRecommendedRelations
import com.anytypeio.anytype.presentation.extension.getUrlForFileContent
import com.anytypeio.anytype.presentation.navigation.NavPanelState
import com.anytypeio.anytype.presentation.navigation.leftButtonClickAnalytics
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
import com.anytypeio.anytype.presentation.objects.getObjectTypeViewsForSBPage
import com.anytypeio.anytype.presentation.objects.getProperType
@ -297,6 +298,7 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
@ -1208,12 +1210,14 @@ class EditorViewModel(
}
fun onShareButtonClicked() {
proceedWithLeftButtonAnalytics()
dispatch(
Command.OpenShareScreen(vmParams.space)
)
}
fun onHomeButtonClicked() {
proceedWithLeftButtonAnalytics()
Timber.d("onHomeButtonClicked, ")
if (stateData.value == ViewState.NotExist) {
exitToSpaceHome()
@ -1226,6 +1230,12 @@ class EditorViewModel(
exitBack()
}
private fun proceedWithLeftButtonAnalytics() {
viewModelScope.launch {
navPanelState.firstOrNull()?.leftButtonClickAnalytics(analytics)
}
}
private fun exitBack() {
when (session.value) {
Session.ERROR -> navigate(EventWrapper(AppNavigation.Command.Exit))

View file

@ -91,6 +91,7 @@ import com.anytypeio.anytype.presentation.home.Command.ChangeWidgetType.Companio
import com.anytypeio.anytype.presentation.navigation.DeepLinkToObjectDelegate
import com.anytypeio.anytype.presentation.navigation.NavPanelState
import com.anytypeio.anytype.presentation.navigation.NavigationViewModel
import com.anytypeio.anytype.presentation.navigation.leftButtonClickAnalytics
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
import com.anytypeio.anytype.presentation.search.Subscriptions
import com.anytypeio.anytype.presentation.sets.prefillNewObjectDetails
@ -1764,7 +1765,7 @@ class HomeScreenViewModel(
}
}
fun onSpaceShareIconClicked(spaceView: ObjectWrapper.SpaceView) {
fun onSpaceWidgetShareIconClicked(spaceView: ObjectWrapper.SpaceView) {
viewModelScope.launch {
val space = spaceView.targetSpaceId
if (space != null) {
@ -1775,19 +1776,20 @@ class HomeScreenViewModel(
}
}
fun onSpaceShareIconClicked() {
fun onNavBarShareIconClicked() {
viewModelScope.launch {
commands.emit(
Command.ShareSpace(SpaceId(spaceManager.get()))
)
navPanelState.value.leftButtonClickAnalytics(analytics)
}
viewModelScope.launch {
commands.emit(Command.ShareSpace(SpaceId(spaceManager.get())))
}
}
fun onHomeButtonClicked() {
// Do nothing
// Do nothing, as home button is not visible on space home screen.
}
fun onSpaceSettingsClicked() {
fun onSpaceWidgetClicked() {
viewModelScope.launch {
commands.emit(
Command.OpenSpaceSettings(
@ -1825,10 +1827,6 @@ class HomeScreenViewModel(
}
}
fun onBackLongClicked() {
navigate(destination = Navigation.OpenSpaceSwitcher)
}
override fun onCleared() {
super.onCleared()
Timber.d("onCleared")

View file

@ -1,5 +1,10 @@
package com.anytypeio.anytype.presentation.navigation
import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.analytics.base.EventsDictionary
import com.anytypeio.anytype.analytics.base.EventsPropertiesKey
import com.anytypeio.anytype.analytics.base.sendEvent
import com.anytypeio.anytype.analytics.props.Props
import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions
sealed class NavPanelState {
@ -68,4 +73,46 @@ sealed class NavPanelState {
}
}
}
}
suspend fun NavPanelState.leftButtonClickAnalytics(analytics: Analytics) {
when (val state = this) {
is NavPanelState.Default -> {
when (state.leftButtonState) {
is NavPanelState.LeftButtonState.AddMembers -> {
analytics.sendEvent(
eventName = EventsDictionary.screenSettingsSpaceShare,
props = Props(
mapOf(
EventsPropertiesKey.route to EventsDictionary.Routes.navigation
)
)
)
}
is NavPanelState.LeftButtonState.Comment -> {
analytics.sendEvent(eventName = EventsDictionary.clickQuote)
}
NavPanelState.LeftButtonState.Home -> {
// Do nothing.
}
NavPanelState.LeftButtonState.ViewMembers -> {
analytics.sendEvent(
eventName = EventsDictionary.screenSettingsSpaceMembers,
props = Props(
mapOf(
EventsPropertiesKey.route to EventsDictionary.Routes.navigation
)
)
)
}
}
}
NavPanelState.Init -> {
// Do nothing.
}
}
}

View file

@ -78,6 +78,7 @@ import com.anytypeio.anytype.core_models.SupportedLayouts
import com.anytypeio.anytype.core_models.TimeInMillis
import com.anytypeio.anytype.presentation.extension.getObject
import com.anytypeio.anytype.presentation.navigation.NavPanelState
import com.anytypeio.anytype.presentation.navigation.leftButtonClickAnalytics
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
import com.anytypeio.anytype.presentation.objects.isCreateObjectAllowed
import com.anytypeio.anytype.presentation.objects.isTemplatesAllowed
@ -126,6 +127,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
@ -1619,6 +1621,9 @@ class ObjectSetViewModel(
}
fun onHomeButtonClicked() {
viewModelScope.launch {
navPanelState.firstOrNull()?.leftButtonClickAnalytics(analytics)
}
viewModelScope.launch {
dispatch(AppNavigation.Command.ExitToSpaceHome)
}
@ -1626,11 +1631,10 @@ class ObjectSetViewModel(
fun onShareButtonClicked() {
viewModelScope.launch {
dispatch(
AppNavigation.Command.OpenShareScreen(
vmParams.space
)
)
navPanelState.firstOrNull()?.leftButtonClickAnalytics(analytics)
}
viewModelScope.launch {
dispatch(AppNavigation.Command.OpenShareScreen(vmParams.space))
}
}

View file

@ -13,7 +13,9 @@ import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Filepath
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.PRIVATE_SPACE_TYPE
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.SHARED_SPACE_TYPE
import com.anytypeio.anytype.core_models.SpaceType
import com.anytypeio.anytype.core_models.UNKNOWN_SPACE_TYPE
import com.anytypeio.anytype.core_models.asSpaceType
@ -289,6 +291,38 @@ class SpaceSettingsViewModel(
}
fun onSharePrivateSpaceClicked() {
viewModelScope.launch {
val data = spaceViewState.value
when(data) {
is ViewState.Success -> {
when(data.data.spaceType) {
PRIVATE_SPACE_TYPE -> {
analytics.sendEvent(
eventName = EventsDictionary.screenSettingsSpaceShare,
props = Props(
mapOf(
EventsPropertiesKey.route to EventsDictionary.Routes.settings
)
)
)
}
SHARED_SPACE_TYPE -> {
analytics.sendEvent(
eventName = EventsDictionary.screenSettingsSpaceMembers,
props = Props(
mapOf(
EventsPropertiesKey.route to EventsDictionary.Routes.settings
)
)
)
}
}
}
else -> {
// Do nothing.
}
}
}
viewModelScope.launch {
val data = spaceViewState.value
if (data is ViewState.Success) {

View file

@ -50,6 +50,7 @@ import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
import com.anytypeio.anytype.presentation.home.navigation
import com.anytypeio.anytype.presentation.navigation.DefaultObjectView
import com.anytypeio.anytype.presentation.navigation.NavPanelState
import com.anytypeio.anytype.presentation.navigation.leftButtonClickAnalytics
import com.anytypeio.anytype.presentation.objects.ObjectAction
import com.anytypeio.anytype.presentation.objects.getCreateObjectParams
import com.anytypeio.anytype.presentation.objects.mapFileObjectToView
@ -74,6 +75,7 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
@ -874,13 +876,12 @@ class CollectionViewModel(
}
fun onShareButtonClicked() {
viewModelScope.launch {
navPanelState.value.leftButtonClickAnalytics(analytics)
}
launch { commands.emit(OpenShareScreen(vmParams.spaceId)) }
}
fun onBackLongClicked() {
launch { commands.emit(ExitToSpaceWidgets) }
}
fun onSearchClicked(space: Id) {
viewModelScope.sendEvent(
analytics = analytics,