Skip to content

Commit

Permalink
Merge pull request #19929 from wordpress-mobile/issue/19925-implement…
Browse files Browse the repository at this point in the history
…-analytics-events-new-filter-ui

[Reader] Implement analytics events considering new filter UI
  • Loading branch information
RenanLukas authored Jan 12, 2024
2 parents bb8988f + 45bd9fb commit 1217e44
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,6 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,

private fun clearFilter() {
val viewModel = getSubFilterViewModel() ?: return
viewModel.setDefaultSubfilter()
viewModel.setDefaultSubfilter(isClearingFilter = true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ private void initSubFilterViewModel(@Nullable Bundle savedInstanceState) {
visibleState.getCategories(),
mUiHelpers.getTextOfUiString(requireContext(), visibleState.getTitle())
);
mReaderTracker.track(Stat.READER_FILTER_SHEET_DISPLAYED);
bottomSheet.show(getChildFragmentManager(), SUBFILTER_BOTTOM_SHEET_TAG);
} else if (!uiState.isVisible() && bottomSheet != null) {
bottomSheet.dismiss();
Expand Down Expand Up @@ -792,7 +791,7 @@ private void resumeFollowedTag() {
mSubFilterViewModel.setSubfilterFromTag(newTag);
} else if (isFollowingScreen() && !ReaderTagTable.tagExists(getCurrentTag())) {
// user just removed a tag which was selected in the subfilter
mSubFilterViewModel.setDefaultSubfilter();
mSubFilterViewModel.setDefaultSubfilter(false);
} else {
// otherwise, refresh posts to make sure any changes are reflected and auto-update
// posts in the current tag if it's time
Expand Down Expand Up @@ -828,7 +827,7 @@ private void resumeFollowedSite(Site currentSite) {
refreshPosts();
} else {
if (mIsFilterableScreen) {
mSubFilterViewModel.setDefaultSubfilter();
mSubFilterViewModel.setDefaultSubfilter(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ class SubFilterViewModel @Inject constructor(
)
}

fun setDefaultSubfilter() {
fun setDefaultSubfilter(isClearingFilter: Boolean) {
readerTracker.track(Stat.READER_FILTER_SHEET_CLEARED)
updateSubfilter(
SiteAll(
filter = SiteAll(
onClickAction = ::onSubfilterClicked,
isSelected = true
)
isSelected = true,
isClearingFilter = isClearingFilter,
),
)
}

Expand All @@ -213,6 +214,11 @@ class SubFilterViewModel @Inject constructor(
listOf(category) // TODO thomashortadev this should accept only a single category
)
)
val source = when(category) {
SubfilterCategory.SITES -> "blogs"
SubfilterCategory.TAGS -> "tags"
}
readerTracker.track(Stat.READER_FILTER_SHEET_DISPLAYED, source)
}

fun updateTagsAndSites() {
Expand Down Expand Up @@ -286,7 +292,10 @@ class SubFilterViewModel @Inject constructor(
}

fun onSubfilterSelected(subfilterListItem: SubfilterListItem) {
readerTracker.track(Stat.READER_FILTER_SHEET_ITEM_SELECTED)
// We should not track subfilter selected if we're clearing a filter that is currently applied.
if (!subfilterListItem.isClearingFilter) {
readerTracker.track(Stat.READER_FILTER_SHEET_ITEM_SELECTED)
}
changeSubfilter(subfilterListItem, true, mTagFragmentStartedWith)
}

Expand Down Expand Up @@ -340,7 +349,7 @@ class SubFilterViewModel @Inject constructor(
)
)

setDefaultSubfilter()
setDefaultSubfilter(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringText

sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = false) {
open var isSelected: Boolean = false
open var isClearingFilter: Boolean = false
open val onClickAction: ((filter: SubfilterListItem) -> Unit)? = null
open val label: UiString? = null

Expand Down Expand Up @@ -52,6 +53,7 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean =
@Suppress("DataClassShouldBeImmutable")
data class SiteAll(
override var isSelected: Boolean = false,
override var isClearingFilter: Boolean = false,
override val onClickAction: (filter: SubfilterListItem) -> Unit
) : SubfilterListItem(SITE_ALL) {
override val label: UiString = UiStringRes(R.string.reader_filter_cta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.fluxc.model.AccountModel
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.models.ReaderTag
Expand Down Expand Up @@ -136,7 +137,7 @@ class SubFilterViewModelTest : BaseUnitTest() {

@Test
fun `view model doesn't start tracking subfiltered list if filter is a not tracked item`() {
viewModel.setDefaultSubfilter()
viewModel.setDefaultSubfilter(false)

// this is done to focus this unit test only on effects of initSubfiltersTracking
// usually it's not considered great to use this function but here it seemed
Expand Down Expand Up @@ -171,7 +172,7 @@ class SubFilterViewModelTest : BaseUnitTest() {
@Test
fun `view model is able to set default subfilter`() {
var item: SubfilterListItem? = null
viewModel.setDefaultSubfilter()
viewModel.setDefaultSubfilter(false)

viewModel.currentSubFilter.observeForever { item = it }

Expand Down Expand Up @@ -424,4 +425,24 @@ class SubFilterViewModelTest : BaseUnitTest() {
assertThat(it.isFiltered).isEqualTo(true)
}
}

@Test
fun `Should NOT track READER_FILTER_SHEET_ITEM_SELECTED if clearing filter when onSubfilterSelected is called`() {
val filter = SiteAll(
isClearingFilter = true,
onClickAction = {},
)
viewModel.onSubfilterSelected(filter)
verify(readerTracker, times(0)).track(AnalyticsTracker.Stat.READER_FILTER_SHEET_ITEM_SELECTED)
}

@Test
fun `Should track READER_FILTER_SHEET_ITEM_SELECTED if NOT clearing filter when onSubfilterSelected is called`() {
val filter = SiteAll(
isClearingFilter = false,
onClickAction = {},
)
viewModel.onSubfilterSelected(filter)
verify(readerTracker).track(AnalyticsTracker.Stat.READER_FILTER_SHEET_ITEM_SELECTED)
}
}

0 comments on commit 1217e44

Please sign in to comment.