Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader IA] Add dropdown menu analytics events #19911

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

AnimatedVisibility(
Expand Down Expand Up @@ -209,6 +210,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,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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tracker> TRACKERS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading