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

DROID-2322 Gallery experience | Analytics (#1076)

This commit is contained in:
Konstantin Ivanov 2024-04-08 11:28:50 +02:00 committed by GitHub
parent d96359f93c
commit 406e838dff
Signed by: github
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 4 deletions

View file

@ -192,6 +192,14 @@ object EventsDictionary {
const val selectNetwork = "SelectNetwork"
const val uploadNetworkConfiguration = "UploadNetworkConfiguration"
//Gallery experience
const val screenGalleryInstall = "ScreenGalleryInstall"
const val clickGalleryInstall = "ClickGalleryInstall"
const val clickGalleryInstallSpace = "ClickGalleryInstallSpace"
const val galleryInstallSuccess = "GalleryInstall"
const val galleryParamNew = "New"
const val galleryParamExisting = "Existing"
enum class ScreenOnboardingStep(val value: String) {
VOID("Void"),
PHRASE("Phrase")
@ -226,6 +234,7 @@ object EventsDictionary {
const val navigation = "Navigation"
const val longTap = "LongTap"
const val sharingExtension = "SharingExtension"
const val gallery = "Gallery"
}
object Type {
@ -283,4 +292,5 @@ object EventsPropertiesKey {
const val align = "align"
const val view = "view"
const val step = "step"
const val name = "name"
}

View file

@ -3,6 +3,14 @@ package com.anytypeio.anytype.gallery_experience.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.analytics.base.EventsDictionary
import com.anytypeio.anytype.analytics.base.EventsDictionary.galleryInstallSuccess
import com.anytypeio.anytype.analytics.base.EventsDictionary.galleryParamExisting
import com.anytypeio.anytype.analytics.base.EventsDictionary.galleryParamNew
import com.anytypeio.anytype.analytics.base.EventsDictionary.screenGalleryInstall
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.ManifestInfo
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Process
@ -20,6 +28,8 @@ import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationNaviga
import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationSpacesState
import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationState
import com.anytypeio.anytype.gallery_experience.models.GallerySpaceView
import com.anytypeio.anytype.presentation.extension.getTypePropName
import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel.Companion.MAX_SPACE_COUNT
import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider
import com.anytypeio.anytype.presentation.spaces.spaceIcon
import kotlinx.coroutines.flow.MutableSharedFlow
@ -46,8 +56,6 @@ class GalleryInstallationViewModel(
val command = MutableSharedFlow<GalleryInstallationNavigation>(replay = 0)
val errorState = MutableSharedFlow<String?>(replay = 0)
private val MAX_SPACES = 10
init {
Timber.d("GalleryInstallationViewModel init, viewModelParams: $viewModelParams")
downloadGalleryManifest()
@ -61,6 +69,7 @@ class GalleryInstallationViewModel(
if (manifestInfo != null) {
Timber.d("DownloadGalleryManifest success, manifestInfo: $manifestInfo")
mainState.value = GalleryInstallationState.Success(manifestInfo)
sendScreenEvent(name = manifestInfo.title)
} else {
Timber.e("DownloadGalleryManifest failed, manifestInfo is null")
errorState.emit("Download manifest error: manifestInfo is null")
@ -84,7 +93,7 @@ class GalleryInstallationViewModel(
spaces = filteredSpaces.map {
it.toView(urlBuilder, spaceGradientProvider)
},
isNewButtonVisible = filteredSpaces.size < MAX_SPACES
isNewButtonVisible = filteredSpaces.size < MAX_SPACE_COUNT
)
command.emit(GalleryInstallationNavigation.Spaces)
},
@ -93,6 +102,9 @@ class GalleryInstallationViewModel(
errorState.emit("Get Spaces error: ${error.message}")
}
)
analytics.sendEvent(
eventName = EventsDictionary.clickGalleryInstall
)
}
}
@ -112,6 +124,18 @@ class GalleryInstallationViewModel(
createSpace.async(params).fold(
onSuccess = { space ->
Timber.d("CreateSpace success, space: $space")
analytics.sendEvent(
eventName = EventsDictionary.clickGalleryInstallSpace,
props = Props(
mapOf(EventsPropertiesKey.type to galleryParamNew)
)
)
analytics.sendEvent(
eventName = EventsDictionary.createSpace,
props = Props(
mapOf(EventsPropertiesKey.route to EventsDictionary.Routes.gallery)
)
)
proceedWithInstallation(
spaceId = SpaceId(space),
isNewSpace = true,
@ -138,6 +162,12 @@ class GalleryInstallationViewModel(
Timber.e("onSpaceClick, spaceId is null")
return@launch
}
analytics.sendEvent(
eventName = EventsDictionary.clickGalleryInstallSpace,
props = Props(
mapOf(EventsPropertiesKey.type to galleryParamExisting)
)
)
proceedWithInstallation(
spaceId = SpaceId(spaceId),
isNewSpace = false,
@ -165,6 +195,12 @@ class GalleryInstallationViewModel(
isNewSpace: Boolean,
manifestInfo: ManifestInfo
) {
analytics.sendEvent(
eventName = galleryInstallSuccess,
props = Props(
mapOf(EventsPropertiesKey.name to manifestInfo.title)
),
)
val params = ImportExperience.Params(
spaceId = spaceId,
url = manifestInfo.downloadLink,
@ -208,6 +244,15 @@ class GalleryInstallationViewModel(
val deepLinkType: String,
val deepLinkSource: String
)
private suspend fun sendScreenEvent(name: String) {
analytics.sendEvent(
eventName = screenGalleryInstall,
props = Props(
mapOf(EventsPropertiesKey.name to name)
),
)
}
}
private fun ObjectWrapper.SpaceView.toView(

View file

@ -5,7 +5,9 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
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.Id
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.domain.base.fold
@ -66,7 +68,12 @@ class CreateSpaceViewModel(
result.fold(
onLoading = { isInProgress.value = true },
onSuccess = { space: Id ->
analytics.sendEvent(eventName = EventsDictionary.createSpace)
analytics.sendEvent(
eventName = EventsDictionary.createSpace,
props = Props(
mapOf(EventsPropertiesKey.route to EventsDictionary.Routes.navigation)
)
)
setNewSpaceAsCurrentSpace(space)
Timber.d("Successfully created space: $space").also {
isSucceeded.value = true