Skip to content

Commit

Permalink
Implement Reader dropdown menu opened analytics event
Browse files Browse the repository at this point in the history
  • Loading branch information
RenanLukas committed Jan 10, 2024
1 parent 9b7a5de commit dd30f9c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fun JetpackDropdownMenu(
onSingleItemClick: (MenuElementData.Item.Single) -> Unit,
menuButtonHeight: Dp = 36.dp,
contentSizeAnimation: FiniteAnimationSpec<IntSize> = spring(),
onDropdownMenuClick: () -> Unit,
) {
Column {
var isMenuVisible by remember { mutableStateOf(false) }
Expand All @@ -63,6 +64,7 @@ fun JetpackDropdownMenu(
contentSizeAnimation = contentSizeAnimation,
selectedItem = selectedItem,
onClick = {
onDropdownMenuClick()
isMenuVisible = !isMenuVisible
}
)
Expand Down Expand Up @@ -269,7 +271,8 @@ fun JetpackDropdownMenuPreview() {
JetpackDropdownMenu(
selectedItem = selectedItem,
menuItems = menuItems,
onSingleItemClick = { selectedItem = it }
onSingleItemClick = { selectedItem = it },
onDropdownMenuClick = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ class ReaderTracker @Inject constructor(
analyticsUtilsWrapper.trackRailcarRender(railcarJson)
}

fun trackDropdownMenuOpened() {
analyticsTrackerWrapper.track(AnalyticsTracker.Stat.READER_DROPDOWN_MENU_OPENED)
}

/* HELPER */

@JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -515,6 +520,7 @@ class ReaderViewModel @Inject constructor(
val menuItems: List<MenuElementData>,
val selectedItem: MenuElementData.Item.Single,
val filterUiState: FilterUiState? = null,
val onDropdownMenuClick: () -> Unit,
) {
data class FilterUiState(
val blogsFilterCount: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fun ReaderTopAppBar(
onSingleItemClick = onMenuItemClick,
menuButtonHeight = chipHeight,
contentSizeAnimation = tween(ANIM_DURATION),
onDropdownMenuClick = topBarUiState.onDropdownMenuClick,
)

AnimatedVisibility(
Expand Down Expand Up @@ -206,6 +207,7 @@ fun ReaderTopAppBarPreview() {
ReaderViewModel.TopBarUiState(
menuItems = menuItems,
selectedItem = menuItems.first() as MenuElementData.Item.Single,
onDropdownMenuClick = {},
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dd30f9c

Please sign in to comment.