From d472f3e8d0c554711eec2c2dc19e6ccdb6739b2c Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:42:34 +0100 Subject: [PATCH] DROID-1706 Analytics | SelectObjectType event (#515) --- .../analytics/base/EventsDictionary.kt | 1 + .../presentation/editor/EditorViewModel.kt | 24 +++++++++++++-- .../presentation/extension/AnalyticsExt.kt | 30 +++++++++++++++++-- .../presentation/mapper/MapperExtension.kt | 3 +- .../presentation/objects/ObjectTypeView.kt | 3 +- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/analytics/src/main/java/com/anytypeio/anytype/analytics/base/EventsDictionary.kt b/analytics/src/main/java/com/anytypeio/anytype/analytics/base/EventsDictionary.kt index ba5f1740c2..358373732e 100644 --- a/analytics/src/main/java/com/anytypeio/anytype/analytics/base/EventsDictionary.kt +++ b/analytics/src/main/java/com/anytypeio/anytype/analytics/base/EventsDictionary.kt @@ -57,6 +57,7 @@ object EventsDictionary { const val searchResult = "SearchResult" const val searchWords = "SearchWords" const val objectTypeChanged = "ChangeObjectType" + const val selectObjectType = "SelectObjectType" const val objectLayoutChange = "ChangeLayout" const val objectSetIcon = "SetIcon" const val objectRemoveIcon = "RemoveIcon" diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt index 43c75a262a..a24c201687 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt @@ -201,6 +201,7 @@ import com.anytypeio.anytype.presentation.extension.sendAnalyticsMentionMenuEven import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectCreateEvent import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectShowEvent import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectTypeChangeEvent +import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectTypeSelectOrChangeEvent import com.anytypeio.anytype.presentation.extension.sendAnalyticsOpenAsObject import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationValueEvent import com.anytypeio.anytype.presentation.extension.sendAnalyticsSearchResultEvent @@ -4322,6 +4323,7 @@ class EditorViewModel( } private suspend fun proceedWithConvertingToSet() { + val startTime = System.currentTimeMillis() val params = ConvertObjectToSet.Params( ctx = context, sources = emptyList() @@ -4330,16 +4332,29 @@ class EditorViewModel( onFailure = { error -> Timber.e(error, "Error convert object to set") }, onSuccess = { proceedWithOpeningDataViewObject(target = context, isPopUpToDashboard = true) + viewModelScope.sendAnalyticsObjectTypeSelectOrChangeEvent( + analytics = analytics, + startTime = startTime, + sourceObject = ObjectTypeIds.SET, + containsFlagType = true + ) } ) } private suspend fun proceedWithConvertingToCollection() { + val startTime = System.currentTimeMillis() val params = ConvertObjectToCollection.Params(ctx = context) objectToCollection.async(params).fold( onFailure = { error -> Timber.e(error, "Error convert object to collection") }, onSuccess = { proceedWithOpeningDataViewObject(target = context, isPopUpToDashboard = true) + viewModelScope.sendAnalyticsObjectTypeSelectOrChangeEvent( + analytics = analytics, + startTime = startTime, + sourceObject = ObjectTypeIds.COLLECTION, + containsFlagType = true + ) } ) } @@ -5950,6 +5965,8 @@ class EditorViewModel( private fun proceedWithObjectTypeChange(item: ObjectTypeView, onSuccess: (() -> Unit)? = null) { val startTime = System.currentTimeMillis() + val internalFlags = getInternalFlagsFromDetails() + val containsTypeFlag = internalFlags.contains(InternalFlags.ShouldSelectType) viewModelScope.launch { val params = SetObjectType.Params( context = context, @@ -5960,10 +5977,11 @@ class EditorViewModel( onSuccess = { response -> Timber.d("proceedWithObjectTypeChange success, key:[${item.key}]") dispatcher.send(response) - sendAnalyticsObjectTypeChangeEvent( + sendAnalyticsObjectTypeSelectOrChangeEvent( analytics = analytics, - objType = storeOfObjectTypes.getByKey(item.key), - startTime = startTime + startTime = startTime, + sourceObject = item.sourceObject, + containsFlagType = containsTypeFlag ) onSuccess?.invoke() } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt index 260546f59c..7ba1e486f3 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt @@ -41,6 +41,7 @@ import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.DVFilterCondition import com.anytypeio.anytype.core_models.DVViewerType import com.anytypeio.anytype.core_models.Id +import com.anytypeio.anytype.core_models.InternalFlags import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relation @@ -632,6 +633,31 @@ fun CoroutineScope.sendAnalyticsObjectTypeChangeEvent( ) } +fun CoroutineScope.sendAnalyticsObjectTypeSelectOrChangeEvent( + analytics: Analytics, + startTime: Long, + sourceObject: Id? = null, + containsFlagType: Boolean +) { + val objType = sourceObject ?: OBJ_TYPE_CUSTOM + val props = Props( + mapOf( + EventsPropertiesKey.objectType to objType + ) + ) + val event = if (containsFlagType) { + EventsDictionary.selectObjectType + } else { + EventsDictionary.objectTypeChanged + } + sendEvent( + analytics = analytics, + eventName = event, + props = props, + startTime = startTime + ) +} + suspend fun Analytics.sendAnalyticsObjectLayoutChangeEvent(name: String) { val event = EventAnalytics.Anytype( name = EventsDictionary.objectLayoutChange, @@ -1918,9 +1944,9 @@ private fun getAnalyticsObjectType( details: Map, ctx: Id ): String { - val objTypeId = details.getValue(ctx).type.firstOrNull() + val objTypeId = details[ctx]?.type?.firstOrNull() val sourceObject = if (objTypeId != null) { - ObjectWrapper.Type(details.getValue(objTypeId).map).sourceObject + ObjectWrapper.Type(details[objTypeId]?.map ?: emptyMap()).sourceObject } else null return sourceObject ?: OBJ_TYPE_CUSTOM } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt index 488564e871..5c2491b810 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt @@ -606,7 +606,8 @@ fun ObjectWrapper.Type.toObjectTypeView(selectedSources: List = emptyList()) emoji = iconEmoji, description = description, isSelected = selectedSources.contains(id), - defaultTemplate = defaultTemplateId + defaultTemplate = defaultTemplateId, + sourceObject = sourceObject ) fun List.toView(): List = mapNotNull { layout -> diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectTypeView.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectTypeView.kt index dd67598284..acdf638579 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectTypeView.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/ObjectTypeView.kt @@ -23,7 +23,8 @@ data class ObjectTypeView( val description: String?, val emoji: String?, val isSelected: Boolean = false, - val defaultTemplate: Id? = null + val defaultTemplate: Id? = null, + val sourceObject: Id? = null ) class ObjectTypeViewComparator : Comparator {