From 7437b71b2431f4c5142a1f6f5d1cd9f4e81f48ef Mon Sep 17 00:00:00 2001 From: NIkita Fedrunov Date: Mon, 23 May 2022 15:15:32 +0200 Subject: [PATCH] analytics --- .../experiment/ExperimentInteraction.kt | 44 +++++++++++++++++++ .../app/features/home/HomeDetailFragment.kt | 7 +++ .../app/features/home/HomeDetailViewModel.kt | 9 +++- .../features/home/SpaceListModalFragment.kt | 4 ++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 vector/src/main/java/im/vector/app/features/analytics/experiment/ExperimentInteraction.kt diff --git a/vector/src/main/java/im/vector/app/features/analytics/experiment/ExperimentInteraction.kt b/vector/src/main/java/im/vector/app/features/analytics/experiment/ExperimentInteraction.kt new file mode 100644 index 0000000000..a6ef02b30b --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/analytics/experiment/ExperimentInteraction.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.analytics.experiment + +import im.vector.app.features.analytics.itf.VectorAnalyticsEvent + +data class ExperimentInteraction( + /** + * The unique name of this element. + */ + val name: Name, + + val extra: Map = emptyMap() +) : VectorAnalyticsEvent { + + enum class Name { + SpaceSwitchHeader, + SpaceSwitchHeaderAdd, + SpaceSwitchHeaderCreate, + } + + override fun getName() = "Interaction" + + override fun getProperties(): Map? { + return mutableMapOf().apply { + put("name", name.name) + putAll(extra) + }.takeIf { it.isNotEmpty() } + } +} diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index 33d1b963ae..1e5c1a5750 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -45,6 +45,7 @@ import im.vector.app.core.ui.views.CurrentCallsView import im.vector.app.core.ui.views.CurrentCallsViewPresenter import im.vector.app.core.ui.views.KeysBackupBanner import im.vector.app.databinding.FragmentHomeDetailBinding +import im.vector.app.features.analytics.experiment.ExperimentInteraction import im.vector.app.features.call.SharedKnownCallsViewModel import im.vector.app.features.call.VectorCallActivity import im.vector.app.features.call.dialpad.DialPadFragment @@ -279,6 +280,12 @@ class HomeDetailFragment @Inject constructor( .setInterpolator(DecelerateInterpolator()) .start() } else { + val extraProperties = if (getCurrentSpace() != null) { + mapOf("isSubspace" to true) + } else { + mapOf("isSubspace" to false) + } + analyticsTracker.capture(ExperimentInteraction(ExperimentInteraction.Name.SpaceSwitchHeader, extraProperties)) showModal() } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index f08353d950..0db12adc9f 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -29,7 +29,10 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.extensions.singletonEntryPoint import im.vector.app.core.platform.VectorViewModel import im.vector.app.features.VectorOverrides +import im.vector.app.features.analytics.AnalyticsTracker +import im.vector.app.features.analytics.extensions.toAnalyticsViewRoom import im.vector.app.features.analytics.plan.Interaction +import im.vector.app.features.analytics.plan.ViewRoom import im.vector.app.features.call.dialpad.DialPadLookup import im.vector.app.features.call.lookup.CallProtocolsChecker import im.vector.app.features.call.webrtc.WebRtcCallManager @@ -75,7 +78,8 @@ class HomeDetailViewModel @AssistedInject constructor( private val directRoomHelper: DirectRoomHelper, private val appStateHandler: AppStateHandler, private val autoAcceptInvites: AutoAcceptInvites, - private val vectorOverrides: VectorOverrides + private val vectorOverrides: VectorOverrides, + private val analyticsTracker: AnalyticsTracker ) : VectorViewModel(initialState), CallProtocolsChecker.Listener { @@ -290,6 +294,9 @@ class HomeDetailViewModel @AssistedInject constructor( hasUnreadMessages = dmRooms.totalCount + otherRooms.totalCount > 0 ) } + groupingMethod.spaceSummary?.toAnalyticsViewRoom(null, groupingMethod)?.let { + analyticsTracker.capture(it) + } } null -> Unit } diff --git a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt index b7e560eca8..828955026d 100644 --- a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt @@ -29,6 +29,8 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentSpaceListModalBinding +import im.vector.app.features.analytics.experiment.ExperimentInteraction +import im.vector.app.features.analytics.plan.Interaction import im.vector.app.features.home.room.list.UnreadCounterBadgeView import im.vector.app.features.spaces.SpaceListAction import im.vector.app.features.spaces.SpaceListViewModel @@ -90,8 +92,10 @@ class SpaceListModalFragment : VectorBaseFragment binding.addSpaceLayout.setOnClickListener { val currentSpace = sharedActionViewModel.space.value if (currentSpace != null) { + analyticsTracker.capture(ExperimentInteraction(ExperimentInteraction.Name.SpaceSwitchHeaderAdd)) startActivity(SpaceManageActivity.newIntent(requireActivity(), currentSpace.roomId, ManageType.AddRoomsOnlySpaces)) } else { + analyticsTracker.capture(ExperimentInteraction(ExperimentInteraction.Name.SpaceSwitchHeaderCreate)) sharedActionViewModel.post(HomeActivitySharedAction.AddSpace) } }