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] Implement analytics events considering new filter UI #19929

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading