Skip to content

Commit

Permalink
added analytics for app layout (#7242)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedrunov authored Oct 3, 2022
1 parent 8fd0107 commit 9f8c768
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.d/6508.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[AppLayout]: added tracking of new analytics events
8 changes: 8 additions & 0 deletions vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.BehaviorDataSource
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.plan.UserProperties
import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.ui.UiStateRepository
Expand Down Expand Up @@ -82,6 +83,13 @@ class SpaceStateHandlerImpl @Inject constructor(
return
}

analyticsTracker.capture(
ViewRoom(
isDM = false,
isSpace = true,
)
)

if (isForwardNavigation) {
addToBackstack(spaceToLeave, spaceToSet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package im.vector.app.features.analytics.extensions

import im.vector.app.features.analytics.plan.UserProperties
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
import im.vector.app.features.onboarding.FtueUseCase

fun FtueUseCase.toTrackingValue(): UserProperties.FtueUseCaseSelection {
Expand All @@ -27,3 +28,12 @@ fun FtueUseCase.toTrackingValue(): UserProperties.FtueUseCaseSelection {
FtueUseCase.SKIP -> UserProperties.FtueUseCaseSelection.Skip
}
}

fun HomeRoomFilter.toTrackingValue(): UserProperties.AllChatsActiveFilter {
return when (this) {
HomeRoomFilter.ALL -> UserProperties.AllChatsActiveFilter.All
HomeRoomFilter.UNREADS -> UserProperties.AllChatsActiveFilter.Unreads
HomeRoomFilter.FAVOURITES -> UserProperties.AllChatsActiveFilter.Favourites
HomeRoomFilter.PEOPlE -> UserProperties.AllChatsActiveFilter.People
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import im.vector.app.core.platform.StateView
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toTrackingValue
import im.vector.app.features.analytics.plan.UserProperties
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.room.list.home.header.HomeRoomFilter
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -74,6 +77,7 @@ class HomeRoomListViewModel @AssistedInject constructor(
private val preferencesStore: HomeLayoutPreferencesStore,
private val stringProvider: StringProvider,
private val drawableProvider: DrawableProvider,
private val analyticsTracker: AnalyticsTracker,
) : VectorViewModel<HomeRoomListViewState, HomeRoomListAction, HomeRoomListViewEvents>(initialState) {

@AssistedFactory
Expand Down Expand Up @@ -358,6 +362,7 @@ class HomeRoomListViewModel @AssistedInject constructor(
}
setState { copy(headersData = headersData.copy(currentFilter = newFilter)) }
updateEmptyState()
analyticsTracker.updateUserProperties(UserProperties(allChatsActiveFilter = newFilter.toTrackingValue()))
filteredPagedRoomSummariesLive?.let { liveResults ->
liveResults.queryParams = getFilteredQueryParams(newFilter, liveResults.queryParams)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.google.android.material.color.MaterialColors
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.FirstItemUpdatedObserver
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.list.RoomListListener
import org.matrix.android.sdk.api.session.room.model.RoomSummary
Expand All @@ -38,6 +39,7 @@ class HomeRoomsHeadersController @Inject constructor(
val stringProvider: StringProvider,
private val avatarRenderer: AvatarRenderer,
resources: Resources,
private val analyticsTracker: AnalyticsTracker,
) : EpoxyController() {

private var data: RoomsHeadersData = RoomsHeadersData()
Expand Down Expand Up @@ -73,7 +75,11 @@ class HomeRoomsHeadersController @Inject constructor(
}

host.data.filtersList?.let {
addRoomFilterHeaderItem(host.onFilterChangedListener, it, host.data.currentFilter)
addRoomFilterHeaderItem(
filterChangedListener = host.onFilterChangedListener,
filtersList = it,
currentFilter = host.data.currentFilter,
analyticsTracker = analyticsTracker)
}
}

Expand Down Expand Up @@ -158,12 +164,14 @@ class HomeRoomsHeadersController @Inject constructor(
filterChangedListener: ((HomeRoomFilter) -> Unit)?,
filtersList: List<HomeRoomFilter>,
currentFilter: HomeRoomFilter?,
analyticsTracker: AnalyticsTracker,
) {
roomFilterHeaderItem {
id("filter_header")
filtersData(filtersList)
selectedFilter(currentFilter)
onFilterChangedListener(filterChangedListener)
analyticsTracker(analyticsTracker)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.google.android.material.tabs.TabLayout
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.plan.Interaction

@EpoxyModelClass
abstract class RoomFilterHeaderItem : VectorEpoxyModel<RoomFilterHeaderItem.Holder>(R.layout.item_home_filter_tabs) {
Expand All @@ -35,6 +37,9 @@ abstract class RoomFilterHeaderItem : VectorEpoxyModel<RoomFilterHeaderItem.Hold
@EpoxyAttribute
var selectedFilter: HomeRoomFilter? = null

@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var analyticsTracker: AnalyticsTracker? = null

override fun bind(holder: Holder) {
super.bind(holder)
with(holder.tabLayout) {
Expand All @@ -51,6 +56,7 @@ abstract class RoomFilterHeaderItem : VectorEpoxyModel<RoomFilterHeaderItem.Hold
addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
(tab?.tag as? HomeRoomFilter)?.let { filter ->
trackFilterChangeEvent(filter)
onFilterChangedListener?.invoke(filter)
}
}
Expand All @@ -61,6 +67,23 @@ abstract class RoomFilterHeaderItem : VectorEpoxyModel<RoomFilterHeaderItem.Hold
}
}

private fun trackFilterChangeEvent(filter: HomeRoomFilter) {
val interactionName = when (filter) {
HomeRoomFilter.ALL -> Interaction.Name.MobileAllChatsFilterAll
HomeRoomFilter.UNREADS -> Interaction.Name.MobileAllChatsFilterUnreads
HomeRoomFilter.FAVOURITES -> Interaction.Name.MobileAllChatsFilterFavourites
HomeRoomFilter.PEOPlE -> Interaction.Name.MobileAllChatsFilterPeople
}

analyticsTracker?.capture(
Interaction(
index = null,
interactionType = null,
name = interactionName
)
)
}

override fun unbind(holder: Holder) {
holder.tabLayout.clearOnTabSelectedListeners()
super.unbind(holder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.StateView
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentInvitesBinding
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.analytics.plan.ViewRoom
import im.vector.app.features.home.room.list.RoomListListener
import im.vector.app.features.notifications.NotificationDrawerManager
Expand All @@ -48,6 +49,11 @@ class InvitesFragment : VectorBaseFragment<FragmentInvitesBinding>(), RoomListLi
return FragmentInvitesBinding.inflate(inflater, container, false)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.Invites
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetHomeLayoutSettingsBinding
import im.vector.app.features.analytics.plan.Interaction
import im.vector.app.features.home.room.list.home.HomeLayoutPreferencesStore
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -54,20 +55,52 @@ class HomeLayoutSettingBottomDialogFragment : VectorBaseBottomSheetDialogFragmen
}

views.homeLayoutSettingsRecents.setOnCheckedChangeListener { _, isChecked ->
trackRecentsStateEvent(isChecked)
setRecentsEnabled(isChecked)
}
views.homeLayoutSettingsFilters.setOnCheckedChangeListener { _, isChecked ->
trackFiltersStateEvent(isChecked)
setFiltersEnabled(isChecked)
}
views.homeLayoutSettingsSortGroup.setOnCheckedChangeListener { _, checkedId ->
setAzOrderingEnabled(checkedId == R.id.home_layout_settings_sort_name)
}
}

private fun trackRecentsStateEvent(areEnabled: Boolean) {
val interactionName = if (areEnabled) {
Interaction.Name.MobileAllChatsRecentsEnabled
} else {
Interaction.Name.MobileAllChatsRecentsDisabled
}
analyticsTracker.capture(
Interaction(
index = null,
interactionType = null,
name = interactionName
)
)
}

private fun setRecentsEnabled(isEnabled: Boolean) = lifecycleScope.launch {
preferencesStore.setRecentsEnabled(isEnabled)
}

private fun trackFiltersStateEvent(areEnabled: Boolean) {
val interactionName = if (areEnabled) {
Interaction.Name.MobileAllChatsFiltersEnabled
} else {
Interaction.Name.MobileAllChatsFiltersDisabled
}
analyticsTracker.capture(
Interaction(
index = null,
interactionType = null,
name = interactionName
)
)
}

private fun setFiltersEnabled(isEnabled: Boolean) = lifecycleScope.launch {
preferencesStore.setFiltersEnabled(isEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class NewSpaceSummaryController @Inject constructor(
text(host.stringProvider.getString(R.string.all_chats))
selected(selected)
countState(UnreadCounterBadgeView.State.Count(homeCount.totalCount, homeCount.isHighlight))
listener { host.callback?.onSpaceSelected(null) }
listener { host.callback?.onSpaceSelected(null, isSubSpace = false) }
}
}

Expand All @@ -99,7 +99,7 @@ class NewSpaceSummaryController @Inject constructor(
hasChildren(hasChildren)
matrixItem(spaceSummary.toMatrixItem())
onLongClickListener { host.callback?.onSpaceSettings(spaceSummary) }
onSpaceSelectedListener { host.callback?.onSpaceSelected(spaceSummary) }
onSpaceSelectedListener { host.callback?.onSpaceSelected(spaceSummary, isSubSpace = false) }
onToggleExpandListener { host.callback?.onToggleExpand(spaceSummary) }
selected(isSelected)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ class NewSpaceSummaryController @Inject constructor(
indent(depth)
matrixItem(childSummary.toMatrixItem())
onLongClickListener { host.callback?.onSpaceSettings(childSummary) }
onSubSpaceSelectedListener { host.callback?.onSpaceSelected(childSummary) }
onSubSpaceSelectedListener { host.callback?.onSpaceSelected(childSummary, isSubSpace = true) }
onToggleExpandListener { host.callback?.onToggleExpand(childSummary) }
selected(isSelected)
}
Expand Down Expand Up @@ -184,8 +184,10 @@ class NewSpaceSummaryController @Inject constructor(
}
}

/**
* This is a full duplicate of [SpaceSummaryController.Callback]. We need to merge them ASAP*/
interface Callback {
fun onSpaceSelected(spaceSummary: RoomSummary?)
fun onSpaceSelected(spaceSummary: RoomSummary?, isSubSpace: Boolean)
fun onSpaceInviteSelected(spaceSummary: RoomSummary)
fun onSpaceSettings(spaceSummary: RoomSummary)
fun onToggleExpand(spaceSummary: RoomSummary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import im.vector.app.core.platform.VectorViewModelAction
import org.matrix.android.sdk.api.session.room.model.RoomSummary

sealed class SpaceListAction : VectorViewModelAction {
data class SelectSpace(val spaceSummary: RoomSummary?) : SpaceListAction()
data class SelectSpace(val spaceSummary: RoomSummary?, val isSubSpace: Boolean) : SpaceListAction()
data class OpenSpaceInvite(val spaceSummary: RoomSummary) : SpaceListAction()
data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction()
data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ import im.vector.app.R
import im.vector.app.core.extensions.replaceChildFragment
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.FragmentSpacesBottomSheetBinding
import im.vector.app.features.analytics.plan.MobileScreen

class SpaceListBottomSheet : VectorBaseBottomSheetDialogFragment<FragmentSpacesBottomSheetBinding>() {

override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSpacesBottomSheetBinding {
return FragmentSpacesBottomSheetBinding.inflate(inflater, container, false)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
analyticsScreenName = MobileScreen.ScreenName.SpaceBottomSheet
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
replaceChildFragment(R.id.space_list, SpaceListFragment::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class SpaceListFragment :
}
}

override fun onSpaceSelected(spaceSummary: RoomSummary?) {
viewModel.handle(SpaceListAction.SelectSpace(spaceSummary))
override fun onSpaceSelected(spaceSummary: RoomSummary?, isSubSpace: Boolean) {
viewModel.handle(SpaceListAction.SelectSpace(spaceSummary, isSubSpace = isSubSpace))
roomListSharedActionViewModel.post(RoomListSharedAction.CloseBottomSheet)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,18 @@ class SpaceListViewModel @AssistedInject constructor(

private fun handleSelectSpace(action: SpaceListAction.SelectSpace) = withState { state ->
if (state.selectedSpace?.roomId != action.spaceSummary?.roomId) {
analyticsTracker.capture(Interaction(null, null, Interaction.Name.SpacePanelSwitchSpace))
val interactionName = if (action.isSubSpace) {
Interaction.Name.SpacePanelSwitchSubSpace
} else {
Interaction.Name.SpacePanelSwitchSpace
}
analyticsTracker.capture(
Interaction(
index = null,
interactionType = null,
name = interactionName
)
)
setState { copy(selectedSpace = action.spaceSummary) }
spaceStateHandler.setCurrentSpace(action.spaceSummary?.roomId)
_viewEvents.post(SpaceListViewEvents.CloseDrawer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SpaceSummaryController @Inject constructor(
id("space_home")
selected(selectedSpace == null)
countState(UnreadCounterBadgeView.State.Count(homeCount.totalCount, homeCount.isHighlight))
listener { host.callback?.onSpaceSelected(null) }
listener { host.callback?.onSpaceSelected(null, isSubSpace = false) }
}

rootSpaces
Expand All @@ -114,7 +114,7 @@ class SpaceSummaryController @Inject constructor(
selected(isSelected)
canDrag(true)
onMore { host.callback?.onSpaceSettings(roomSummary) }
listener { host.callback?.onSpaceSelected(roomSummary) }
listener { host.callback?.onSpaceSelected(roomSummary, isSubSpace = false) }
toggleExpand { host.callback?.onToggleExpand(roomSummary) }
countState(
UnreadCounterBadgeView.State.Count(
Expand Down Expand Up @@ -165,7 +165,7 @@ class SpaceSummaryController @Inject constructor(
expanded(expanded)
onMore { host.callback?.onSpaceSettings(childSummary) }
matrixItem(childSummary.toMatrixItem())
listener { host.callback?.onSpaceSelected(childSummary) }
listener { host.callback?.onSpaceSelected(childSummary, isSubSpace = true) }
toggleExpand { host.callback?.onToggleExpand(childSummary) }
indent(currentDepth)
countState(
Expand All @@ -184,7 +184,7 @@ class SpaceSummaryController @Inject constructor(
}

interface Callback {
fun onSpaceSelected(spaceSummary: RoomSummary?)
fun onSpaceSelected(spaceSummary: RoomSummary?, isSubSpace: Boolean)
fun onSpaceInviteSelected(spaceSummary: RoomSummary)
fun onSpaceSettings(spaceSummary: RoomSummary)
fun onToggleExpand(spaceSummary: RoomSummary)
Expand Down
Loading

0 comments on commit 9f8c768

Please sign in to comment.