From dd30f9cd81d9aa5086ac1c2da7f6f8883daaa345 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 9 Jan 2024 20:44:32 -0300 Subject: [PATCH] Implement Reader dropdown menu opened analytics event --- .../components/menu/dropdown/JetpackDropdownMenu.kt | 5 ++++- .../wordpress/android/ui/reader/tracker/ReaderTracker.kt | 4 ++++ .../android/ui/reader/viewmodels/ReaderViewModel.kt | 6 ++++++ .../android/ui/reader/views/compose/ReaderTopAppBar.kt | 2 ++ .../org/wordpress/android/ui/reader/ReaderTrackerTest.kt | 8 ++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) 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..d6f0e033acff 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,10 @@ class ReaderTracker @Inject constructor( analyticsUtilsWrapper.trackRailcarRender(railcarJson) } + fun trackDropdownMenuOpened() { + analyticsTrackerWrapper.track(AnalyticsTracker.Stat.READER_DROPDOWN_MENU_OPENED) + } + /* 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 145b4171aaaa..d26d7afc89fc 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 @@ -389,11 +389,16 @@ class ReaderViewModel @Inject constructor( menuItems = menuItems, selectedItem = selectedItem, filterUiState = filterUiState, + onDropdownMenuClick = ::onDropdownMenuClick, ) ) } } + private fun onDropdownMenuClick() { + readerTracker.trackDropdownMenuOpened() + } + private fun getMenuItemFromReaderTag(readerTag: ReaderTag): MenuElementData.Item.Single? = _topBarUiState.value?.menuItems // Selected menu item must be an Item.Single @@ -515,6 +520,7 @@ class ReaderViewModel @Inject constructor( val menuItems: List, val selectedItem: MenuElementData.Item.Single, val filterUiState: FilterUiState? = null, + val onDropdownMenuClick: () -> Unit, ) { data class FilterUiState( val blogsFilterCount: Int, 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 843fec5814c5..dfc4c5c60ce1 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 @@ -101,6 +101,7 @@ fun ReaderTopAppBar( onSingleItemClick = onMenuItemClick, menuButtonHeight = chipHeight, contentSizeAnimation = tween(ANIM_DURATION), + onDropdownMenuClick = topBarUiState.onDropdownMenuClick, ) AnimatedVisibility( @@ -206,6 +207,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..33aac06103fd 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,9 @@ 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.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.reader.tracker.ReaderTracker import org.wordpress.android.ui.reader.tracker.ReaderTrackerType @@ -204,6 +206,12 @@ 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) + } + private fun addToDate(date: Date, seconds: Int): Date { val calendar = Calendar.getInstance() calendar.time = date