-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Horta
committed
Jun 3, 2024
1 parent
7f5b700
commit 4183f35
Showing
2 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
WordPress/src/main/java/org/wordpress/android/ui/main/analytics/MainCreateSheetTracker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.wordpress.android.ui.main.analytics | ||
|
||
import org.wordpress.android.analytics.AnalyticsTracker | ||
import org.wordpress.android.ui.main.MainActionListItem | ||
import org.wordpress.android.ui.main.WPMainNavigationView | ||
import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution | ||
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper | ||
import java.util.Locale | ||
import javax.inject.Inject | ||
|
||
class MainCreateSheetTracker @Inject constructor( | ||
private val analyticsTracker: AnalyticsTrackerWrapper, | ||
) { | ||
fun trackActionTapped(page: WPMainNavigationView.PageType, actionType: MainActionListItem.ActionType) { | ||
val stat = when (page) { | ||
WPMainNavigationView.PageType.MY_SITE -> AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_ACTION_TAPPED | ||
WPMainNavigationView.PageType.READER -> AnalyticsTracker.Stat.READER_CREATE_SHEET_ACTION_TAPPED | ||
else -> return | ||
} | ||
val properties = mapOf("action" to actionType.name.lowercase(Locale.ROOT)) | ||
analyticsTracker.track(stat, properties) | ||
} | ||
|
||
fun trackAnswerPromptActionTapped(page: WPMainNavigationView.PageType, attribution: BloggingPromptAttribution) { | ||
val properties = mapOf("attribution" to attribution.value).filterValues { it.isNotBlank() } | ||
val stat = when (page) { | ||
WPMainNavigationView.PageType.MY_SITE -> AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_ANSWER_PROMPT_TAPPED | ||
WPMainNavigationView.PageType.READER -> AnalyticsTracker.Stat.READER_CREATE_SHEET_ANSWER_PROMPT_TAPPED | ||
else -> return | ||
} | ||
analyticsTracker.track(stat, properties) | ||
} | ||
|
||
fun trackHelpPromptActionTapped(page: WPMainNavigationView.PageType) { | ||
val stat = when (page) { | ||
WPMainNavigationView.PageType.MY_SITE -> AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_PROMPT_HELP_TAPPED | ||
WPMainNavigationView.PageType.READER -> AnalyticsTracker.Stat.READER_CREATE_SHEET_PROMPT_HELP_TAPPED | ||
else -> return | ||
} | ||
analyticsTracker.track(stat) | ||
} | ||
|
||
fun trackSheetShown(page: WPMainNavigationView.PageType) { | ||
val stat = when (page) { | ||
WPMainNavigationView.PageType.MY_SITE -> AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_SHOWN | ||
WPMainNavigationView.PageType.READER -> AnalyticsTracker.Stat.READER_CREATE_SHEET_SHOWN | ||
else -> return | ||
} | ||
analyticsTracker.track(stat) | ||
} | ||
|
||
fun trackFabShown(page: WPMainNavigationView.PageType) { | ||
val stat = when (page) { | ||
WPMainNavigationView.PageType.MY_SITE -> AnalyticsTracker.Stat.MY_SITE_CREATE_FAB_SHOWN | ||
WPMainNavigationView.PageType.READER -> AnalyticsTracker.Stat.READER_CREATE_FAB_SHOWN | ||
else -> return | ||
} | ||
analyticsTracker.track(stat) | ||
} | ||
|
||
fun trackCreateActionsSheetCard(actions: List<MainActionListItem>) { | ||
if (actions.any { it is MainActionListItem.AnswerBloggingPromptAction }) { | ||
analyticsTracker.track(AnalyticsTracker.Stat.BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED) | ||
} | ||
} | ||
} |
276 changes: 276 additions & 0 deletions
276
...Press/src/test/java/org/wordpress/android/ui/main/analytics/MainCreateSheetTrackerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
package org.wordpress.android.ui.main.analytics | ||
|
||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.argThat | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.verifyNoInteractions | ||
import org.wordpress.android.analytics.AnalyticsTracker | ||
import org.wordpress.android.ui.main.MainActionListItem | ||
import org.wordpress.android.ui.main.WPMainNavigationView | ||
import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution | ||
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class MainCreateSheetTrackerTest { | ||
@Mock | ||
private lateinit var analyticsTracker: AnalyticsTrackerWrapper | ||
|
||
private lateinit var tracker: MainCreateSheetTracker | ||
|
||
@Before | ||
fun setUp() { | ||
tracker = MainCreateSheetTracker(analyticsTracker) | ||
} | ||
|
||
// region trackActionTapped | ||
@Test | ||
fun `trackActionTapped tracks action tapped for my site page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.MY_SITE | ||
val actionType = MainActionListItem.ActionType.CREATE_NEW_POST | ||
val expectedStat = AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_ACTION_TAPPED | ||
|
||
// Act | ||
tracker.trackActionTapped(page, actionType) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(eq(expectedStat), argThat<Map<String, Any>> { | ||
this["action"] == "create_new_post" | ||
}) | ||
} | ||
|
||
@Test | ||
fun `trackActionTapped tracks action tapped for reader page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.READER | ||
val actionType = MainActionListItem.ActionType.CREATE_NEW_POST | ||
val expectedStat = AnalyticsTracker.Stat.READER_CREATE_SHEET_ACTION_TAPPED | ||
|
||
// Act | ||
tracker.trackActionTapped(page, actionType) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(eq(expectedStat), argThat<Map<String, Any>> { | ||
this["action"] == "create_new_post" | ||
}) | ||
} | ||
|
||
@Test | ||
fun `trackActionTapped does not track action tapped for other pages`() { | ||
WPMainNavigationView.PageType.entries | ||
.filterNot { it == WPMainNavigationView.PageType.MY_SITE || it == WPMainNavigationView.PageType.READER } | ||
.forEach { page -> | ||
// Arrange | ||
val actionType = MainActionListItem.ActionType.CREATE_NEW_POST | ||
|
||
// Act | ||
tracker.trackActionTapped(page, actionType) | ||
|
||
// Assert | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
} | ||
// endregion | ||
|
||
// region trackAnswerPromptActionTapped | ||
@Test | ||
fun `trackAnswerPromptActionTapped tracks answer prompt action tapped for my site page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.MY_SITE | ||
val attribution = BloggingPromptAttribution.DAY_ONE | ||
val expectedStat = AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_ANSWER_PROMPT_TAPPED | ||
|
||
// Act | ||
tracker.trackAnswerPromptActionTapped(page, attribution) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(eq(expectedStat), argThat<Map<String, Any>> { | ||
this["attribution"] == attribution.value | ||
}) | ||
} | ||
|
||
@Test | ||
fun `trackAnswerPromptActionTapped tracks answer prompt action tapped for reader page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.READER | ||
val attribution = BloggingPromptAttribution.DAY_ONE | ||
val expectedStat = AnalyticsTracker.Stat.READER_CREATE_SHEET_ANSWER_PROMPT_TAPPED | ||
|
||
// Act | ||
tracker.trackAnswerPromptActionTapped(page, attribution) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(eq(expectedStat), argThat<Map<String, Any>> { | ||
this["attribution"] == attribution.value | ||
}) | ||
} | ||
|
||
@Test | ||
fun `trackAnswerPromptActionTapped does not track answer prompt action tapped for other pages`() { | ||
WPMainNavigationView.PageType.entries | ||
.filterNot { it == WPMainNavigationView.PageType.MY_SITE || it == WPMainNavigationView.PageType.READER } | ||
.forEach { page -> | ||
// Arrange | ||
val attribution = BloggingPromptAttribution.DAY_ONE | ||
|
||
// Act | ||
tracker.trackAnswerPromptActionTapped(page, attribution) | ||
|
||
// Assert | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
} | ||
// endregion | ||
|
||
// region trackHelpPromptActionTapped | ||
@Test | ||
fun `trackHelpPromptActionTapped tracks help prompt action tapped for my site page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.MY_SITE | ||
val expectedStat = AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_PROMPT_HELP_TAPPED | ||
|
||
// Act | ||
tracker.trackHelpPromptActionTapped(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackHelpPromptActionTapped tracks help prompt action tapped for reader page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.READER | ||
val expectedStat = AnalyticsTracker.Stat.READER_CREATE_SHEET_PROMPT_HELP_TAPPED | ||
|
||
// Act | ||
tracker.trackHelpPromptActionTapped(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackHelpPromptActionTapped does not track help prompt action tapped for other pages`() { | ||
WPMainNavigationView.PageType.entries | ||
.filterNot { it == WPMainNavigationView.PageType.MY_SITE || it == WPMainNavigationView.PageType.READER } | ||
.forEach { page -> | ||
// Act | ||
tracker.trackHelpPromptActionTapped(page) | ||
|
||
// Assert | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
} | ||
// endregion | ||
|
||
// region trackSheetShown | ||
@Test | ||
fun `trackSheetShown tracks sheet shown for my site page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.MY_SITE | ||
val expectedStat = AnalyticsTracker.Stat.MY_SITE_CREATE_SHEET_SHOWN | ||
|
||
// Act | ||
tracker.trackSheetShown(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackSheetShown tracks sheet shown for reader page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.READER | ||
val expectedStat = AnalyticsTracker.Stat.READER_CREATE_SHEET_SHOWN | ||
|
||
// Act | ||
tracker.trackSheetShown(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackSheetShown does not track sheet shown for other pages`() { | ||
WPMainNavigationView.PageType.entries | ||
.filterNot { it == WPMainNavigationView.PageType.MY_SITE || it == WPMainNavigationView.PageType.READER } | ||
.forEach { page -> | ||
// Act | ||
tracker.trackSheetShown(page) | ||
|
||
// Assert | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
} | ||
// endregion | ||
|
||
// region trackFabShown | ||
@Test | ||
fun `trackFabShown tracks fab shown for my site page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.MY_SITE | ||
val expectedStat = AnalyticsTracker.Stat.MY_SITE_CREATE_FAB_SHOWN | ||
|
||
// Act | ||
tracker.trackFabShown(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackFabShown tracks fab shown for reader page`() { | ||
// Arrange | ||
val page = WPMainNavigationView.PageType.READER | ||
val expectedStat = AnalyticsTracker.Stat.READER_CREATE_FAB_SHOWN | ||
|
||
// Act | ||
tracker.trackFabShown(page) | ||
|
||
// Assert | ||
verify(analyticsTracker).track(expectedStat) | ||
} | ||
|
||
@Test | ||
fun `trackFabShown does not track fab shown for other pages`() { | ||
WPMainNavigationView.PageType.entries | ||
.filterNot { it == WPMainNavigationView.PageType.MY_SITE || it == WPMainNavigationView.PageType.READER } | ||
.forEach { page -> | ||
// Act | ||
tracker.trackFabShown(page) | ||
|
||
// Assert | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
} | ||
// endregion | ||
|
||
// region trackCreateActionsSheetCard | ||
@Test | ||
fun `trackCreateActionsSheetCard tracks bottom sheet when it is in the list`() { | ||
val actionList = listOf( | ||
mock<MainActionListItem.AnswerBloggingPromptAction>(), | ||
mock<MainActionListItem.CreateAction>(), | ||
mock<MainActionListItem.CreateAction>(), | ||
) | ||
tracker.trackCreateActionsSheetCard(actionList) | ||
verify(analyticsTracker).track(AnalyticsTracker.Stat.BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED) | ||
} | ||
|
||
@Test | ||
fun `trackCreateActionsSheetCard does not track bottom sheet when it is not in the list`() { | ||
val actionList = listOf( | ||
mock<MainActionListItem.CreateAction>(), | ||
mock<MainActionListItem.CreateAction>(), | ||
) | ||
tracker.trackCreateActionsSheetCard(actionList) | ||
verifyNoInteractions(analyticsTracker) | ||
} | ||
// endregion | ||
} |