Skip to content

Commit

Permalink
Merge pull request #18310 from wordpress-mobile/issue/18219-activity-…
Browse files Browse the repository at this point in the history
…card-track-events

Dashboard Cards: Activity Card implement tracking
  • Loading branch information
AjeshRPai authored Apr 24, 2023
2 parents 40b881a + 3bb31a6 commit d0c1cd4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ class MySiteViewModel @Inject constructor(
}

private fun onActivityCardItemClick(activityCardItemClickParams: ActivityCardItemClickParams) {
// implement track event for activity item click
cardsTracker.trackActivityCardItemClicked()
_onNavigation.value =
Event(
SiteNavigationAction.OpenActivityLogDetail(
Expand All @@ -730,7 +730,7 @@ class MySiteViewModel @Inject constructor(
}

private fun onActivityCardFooterLinkClick() {
// implement track event for activity card footer link
cardsTracker.trackActivityCardFooterClicked()
_onNavigation.value =
Event(SiteNavigationAction.OpenActivityLog(requireNotNull(selectedSiteRepository.getSelectedSite())))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CardsShownTracker @Inject constructor(
Type.PAGES.label
)
)
is DashboardCard.ActivityCard -> trackCardShown(
is DashboardCard.ActivityCard.ActivityCardWithItems -> trackCardShown(
Pair(
card.dashboardCardType.toTypeValue().label,
Type.ACTIVITY.label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CardsTracker @Inject constructor(
BLOGGING_PROMPT("blogging_prompt"),
PROMOTE_WITH_BLAZE("promote_with_blaze"),
PAGES("pages"),
ACTIVITY("activity"),
ACTIVITY("activity_log"),
DASHBOARD_CARD_DOMAIN("dashboard_card_domain"),
}

Expand All @@ -49,6 +49,10 @@ class CardsTracker @Inject constructor(
SCHEDULED("scheduled")
}

enum class ActivityLogSubtype(val label: String) {
ACTIVITY_LOG("activity_log"),
}

fun trackQuickStartCardItemClicked(quickStartTaskType: QuickStartTaskType) {
trackCardItemClicked(Type.QUICK_START.label, quickStartTaskType.toSubtypeValue().label)
}
Expand All @@ -73,6 +77,14 @@ class CardsTracker @Inject constructor(
trackCardItemClicked(Type.POST.label, postCardType.toSubtypeValue().label)
}

fun trackActivityCardItemClicked() {
trackCardItemClicked(Type.ACTIVITY.label, ActivityLogSubtype.ACTIVITY_LOG.label)
}

fun trackActivityCardFooterClicked() {
trackCardFooterLinkClicked(Type.ACTIVITY.label, ActivityLogSubtype.ACTIVITY_LOG.label)
}

private fun trackCardFooterLinkClicked(type: String, subtype: String) {
analyticsTrackerWrapper.track(
Stat.MY_SITE_DASHBOARD_CARD_FOOTER_ACTION_TAPPED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ActivityCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ActivityCard.ActivityCardWithItems
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.ErrorCard
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.FooterLink
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.PostCardWithPostItems
import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard.PostCard.PostCardWithoutPostItems
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.ActivityLogSubtype
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.PostSubtype
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.Type
import org.wordpress.android.ui.mysite.cards.dashboard.posts.PostCardType
Expand Down Expand Up @@ -77,6 +80,13 @@ class CardsShownTrackerTest {
)
}

@Test
fun `when activity card is shown, then activity log shown event is tracked`() {
cardsShownTracker.track(buildActivityDashboardCards())

verifyCardShownTracked(Type.ACTIVITY.label, ActivityLogSubtype.ACTIVITY_LOG.label)
}

private fun verifyCardShownTracked(type: String, subtype: String) {
verify(analyticsTracker).track(
Stat.MY_SITE_DASHBOARD_CARD_SHOWN,
Expand Down Expand Up @@ -125,6 +135,21 @@ class CardsShownTrackerTest {
)
)

private fun buildActivityDashboardCards() = DashboardCards(
cards = mutableListOf<DashboardCard>().apply {
addAll(buildActivityCard())
}
)

private fun buildActivityCard() =
listOf(
ActivityCardWithItems(
title = UiStringText("title"),
footerLink = ActivityCard.FooterLink(UiStringText("footer"), onClick = mock()),
activityItems = emptyList()
)
)

private fun buildErrorCard(): DashboardCards {
val cards = listOf(ErrorCard(onRetryClick = mock()))
val dashboardCard = mutableListOf<DashboardCard>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.verify
import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.ActivityLogSubtype
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.PostSubtype
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.QuickStartSubtype
import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker.StatsSubtype
Expand Down Expand Up @@ -119,6 +120,20 @@ class CardsTrackerTest {
verifyCardItemClickedTracked(Type.POST, PostSubtype.SCHEDULED.label)
}

@Test
fun `when activity log item is clicked, then activity card item event is tracked`() {
cardsTracker.trackActivityCardItemClicked()

verifyCardItemClickedTracked(Type.ACTIVITY, ActivityLogSubtype.ACTIVITY_LOG.label)
}

@Test
fun `when activity card footer link is clicked, then footer link clicked is tracked`() {
cardsTracker.trackActivityCardFooterClicked()

verifyFooterLinkClickedTracked(Type.ACTIVITY, ActivityLogSubtype.ACTIVITY_LOG.label)
}

private fun verifyFooterLinkClickedTracked(
typeValue: Type,
subtypeValue: String
Expand Down

0 comments on commit d0c1cd4

Please sign in to comment.