diff --git a/WordPress/src/main/java/org/wordpress/android/ui/compose/components/menu/dropdown/JetpackDropdownMenu.kt b/WordPress/src/main/java/org/wordpress/android/ui/compose/components/menu/dropdown/JetpackDropdownMenu.kt index 0e47fa436414..ab48ff30a30b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/compose/components/menu/dropdown/JetpackDropdownMenu.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/compose/components/menu/dropdown/JetpackDropdownMenu.kt @@ -55,6 +55,7 @@ fun JetpackDropdownMenu( onSingleItemClick: (MenuElementData.Item.Single) -> Unit, menuButtonHeight: Dp = 36.dp, contentSizeAnimation: FiniteAnimationSpec = spring(), + onDropdownMenuClick: () -> Unit, ) { Column { var isMenuVisible by remember { mutableStateOf(false) } @@ -63,6 +64,7 @@ fun JetpackDropdownMenu( contentSizeAnimation = contentSizeAnimation, selectedItem = selectedItem, onClick = { + onDropdownMenuClick() isMenuVisible = !isMenuVisible } ) @@ -269,7 +271,8 @@ fun JetpackDropdownMenuPreview() { JetpackDropdownMenu( selectedItem = selectedItem, menuItems = menuItems, - onSingleItemClick = { selectedItem = it } + onSingleItemClick = { selectedItem = it }, + onDropdownMenuClick = {}, ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt index 4a528e534147..15822295422c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/tracker/ReaderTracker.kt @@ -376,6 +376,27 @@ class ReaderTracker @Inject constructor( analyticsUtilsWrapper.trackRailcarRender(railcarJson) } + fun trackDropdownMenuOpened() { + analyticsTrackerWrapper.track(AnalyticsTracker.Stat.READER_DROPDOWN_MENU_OPENED) + } + + fun trackDropdownMenuItemTapped(readerTag: ReaderTag) { + when { + readerTag.isDiscover -> "discover" + readerTag.isFollowedSites -> "following" + readerTag.isBookmarked -> "saved" + readerTag.isPostsILike -> "liked" + readerTag.isA8C -> "a8c" + readerTag.isListTopic -> "list" + else -> null + }?.let { trackingId -> + analyticsTrackerWrapper.track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to trackingId) + ) + } + } + /* HELPER */ @JvmOverloads diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt index bcbdd5ceb700..4b6d3b5ce45f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt @@ -149,23 +149,6 @@ class ReaderViewModel @Inject constructor( } } -// TODO verify side effects of removing this logic -// private suspend fun initializeTabSelection(tagList: ReaderTagList) { -// withContext(bgDispatcher) { -// val selectTab = { readerTag: ReaderTag -> -// val index = tagList.indexOf(readerTag) -// if (index != -1) { -// updateSelectedContent(readerTag) -// } -// } -// appPrefsWrapper.getReaderTag()?.let { -// selectTab.invoke(it) -// } ?: tagList.find { it.isDiscover }?.let { -// selectTab.invoke(it) -// } -// } -// } - fun onTagChanged(selectedTag: ReaderTag?) { selectedTag?.let { trackReaderTabShownIfNecessary(it) @@ -389,12 +372,17 @@ class ReaderViewModel @Inject constructor( menuItems = menuItems, selectedItem = selectedItem, filterUiState = filterUiState, + onDropdownMenuClick = ::onDropdownMenuClick, isSearchActionVisible = isSearchSupported(), ) ) } } + private fun onDropdownMenuClick() { + readerTracker.trackDropdownMenuOpened() + } + private fun getMenuItemFromReaderTag(readerTag: ReaderTag): MenuElementData.Item.Single? = _topBarUiState.value?.menuItems // Selected menu item must be an Item.Single @@ -426,6 +414,9 @@ class ReaderViewModel @Inject constructor( if (item.id != _topBarUiState.value?.selectedItem?.id) { selectedReaderTag?.let { updateSelectedContent(it) } } + if (selectedReaderTag != null) { + readerTracker.trackDropdownMenuItemTapped(selectedReaderTag) + } } fun onSubFilterItemSelected(item: SubfilterListItem) { @@ -516,6 +507,7 @@ class ReaderViewModel @Inject constructor( val menuItems: List, val selectedItem: MenuElementData.Item.Single, val filterUiState: FilterUiState? = null, + val onDropdownMenuClick: () -> Unit, val isSearchActionVisible: Boolean = false, ) { data class FilterUiState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt index c1228c929565..6578d1ba6b5d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt @@ -102,6 +102,7 @@ fun ReaderTopAppBar( onSingleItemClick = onMenuItemClick, menuButtonHeight = chipHeight, contentSizeAnimation = tween(ANIM_DURATION), + onDropdownMenuClick = topBarUiState.onDropdownMenuClick, ) AnimatedVisibility( @@ -209,6 +210,7 @@ fun ReaderTopAppBarPreview() { ReaderViewModel.TopBarUiState( menuItems = menuItems, selectedItem = menuItems.first() as MenuElementData.Item.Single, + onDropdownMenuClick = {}, ) ) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/ReaderTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/ReaderTrackerTest.kt index 04f68d2a7c88..e6eddc8466df 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/reader/ReaderTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/ReaderTrackerTest.kt @@ -6,7 +6,11 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.models.ReaderTag +import org.wordpress.android.models.ReaderTagType import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.reader.tracker.ReaderTracker import org.wordpress.android.ui.reader.tracker.ReaderTrackerType @@ -204,6 +208,114 @@ class ReaderTrackerTest { assertThat(tracker.isRunning(ReaderTrackerType.MAIN_READER)).isEqualTo(false) } + @Test + fun `Should track dropdown menu opened correctly`() { + tracker.trackDropdownMenuOpened() + verify(analyticsTrackerWrapper).track(AnalyticsTracker.Stat.READER_DROPDOWN_MENU_OPENED) + } + + @Test + fun `Should track dropdown menu item Discover tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + ReaderTag.DISCOVER_PATH, + ReaderTagType.DEFAULT, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "discover"), + ) + } + + @Test + fun `Should track dropdown menu item Subscriptions tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + ReaderTag.FOLLOWING_PATH, + ReaderTagType.DEFAULT, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "following"), + ) + } + + @Test + fun `Should track dropdown menu item Saved tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + null, + ReaderTagType.BOOKMARKED, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "saved"), + ) + } + + @Test + fun `Should track dropdown menu item Liked tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + ReaderTag.LIKED_PATH, + ReaderTagType.DEFAULT, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "liked"), + ) + } + + @Test + fun `Should track dropdown menu item Automattic tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + "/read/a8c", + ReaderTagType.DEFAULT, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "a8c"), + ) + } + + @Test + fun `Should track dropdown menu custom list item tapped`() { + tracker.trackDropdownMenuItemTapped( + ReaderTag( + "slug", + "displayName", + "title", + "/read/list/", + ReaderTagType.DEFAULT, + ) + ) + verify(analyticsTrackerWrapper).track( + stat = AnalyticsTracker.Stat.READER_DROPDOWN_MENU_ITEM_TAPPED, + properties = mapOf("id" to "list"), + ) + } + private fun addToDate(date: Date, seconds: Int): Date { val calendar = Calendar.getInstance() calendar.time = date diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 28c466bd1e75..ac29ce4057f6 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -1099,7 +1099,9 @@ public enum Stat { DYNAMIC_DASHBOARD_CARD_TAPPED, DYNAMIC_DASHBOARD_CARD_CTA_TAPPED, DYNAMIC_DASHBOARD_CARD_HIDE_TAPPED, - DEEP_LINK_FAILED + DEEP_LINK_FAILED, + READER_DROPDOWN_MENU_OPENED, + READER_DROPDOWN_MENU_ITEM_TAPPED } private static final List TRACKERS = new ArrayList<>(); diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 8d863c39dfd6..c505dfaaf2e9 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -2693,6 +2693,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "dynamic_dashboard_card_hide_tapped"; case DEEP_LINK_FAILED: return "deep_link_failed"; + case READER_DROPDOWN_MENU_OPENED: + return "reader_dropdown_menu_opened"; + case READER_DROPDOWN_MENU_ITEM_TAPPED: + return "reader_dropdown_menu_item_tapped"; } return null; }