Skip to content

Commit

Permalink
Merge pull request #16634 from wordpress-mobile/issue/16521-blogging-…
Browse files Browse the repository at this point in the history
…prompts-prompt-reminder-modal-analytics-events

[Blogging prompts v1] Implement prompt reminder modal analytics events
  • Loading branch information
RenanLukas authored Jun 2, 2022
2 parents 28bc84e + 4708597 commit 6b2e279
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,5 @@ class BloggingReminderBottomSheetFragment : BottomSheetDialogFragment() {

companion object {
const val TAG = "BLOGGING_REMINDER_BOTTOM_SHEET_FRAGMENT"

@JvmStatic
fun newInstance() = BloggingReminderBottomSheetFragment()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class BloggingRemindersAnalyticsTracker @Inject constructor(
BLOGGING_REMINDERS_NOTIFICATION_RECEIVED, mapOf(PROMPT_INCLUDED to "$promptIncluded")
)

fun trackRemindersIncludePromptPressed(promptEnabled: Boolean) =
track(Stat.BLOGGING_REMINDERS_INCLUDE_PROMPT_TAPPED, mapOf(PROMPT_ENABLED_KEY to "$promptEnabled"))

fun trackRemindersIncludePromptHelpPressed() = track(Stat.BLOGGING_REMINDERS_INCLUDE_PROMPT_HELP_TAPPED)

private fun track(stat: Stat, properties: Map<String, Any?> = emptyMap()) = analyticsTracker.track(
stat,
properties + (BLOG_TYPE_KEY to siteType?.trackingName)
Expand Down Expand Up @@ -93,6 +98,7 @@ class BloggingRemindersAnalyticsTracker @Inject constructor(
private const val SCREEN_KEY = "screen"
private const val BUTTON_KEY = "button"
private const val SOURCE_KEY = "source"
private const val PROMPT_ENABLED_KEY = "enabled"
private const val DAYS_OF_WEEK_COUNT_KEY = "days_of_week_count"
private const val SELECTED_TIME_KEY = "selected_time"
private const val PROMPT_INCLUDED = "prompt_included"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ class BloggingRemindersViewModel @Inject constructor(

private fun togglePromptSwitch() {
_bloggingRemindersModel.value?.let { currentState ->
_bloggingRemindersModel.value = currentState.copy(isPromptIncluded = !currentState.isPromptIncluded)
val newState = !currentState.isPromptIncluded
analyticsTracker.trackRemindersIncludePromptPressed(newState)
_bloggingRemindersModel.value = currentState.copy(isPromptIncluded = newState)
}
}

private fun showBloggingPromptDialog() {
analyticsTracker.trackRemindersIncludePromptHelpPressed()
_showBloggingPromptHelpDialogVisible.value = Event(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_FLOW_COMPLETED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_FLOW_DISMISSED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_FLOW_START
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_INCLUDE_PROMPT_HELP_TAPPED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_INCLUDE_PROMPT_TAPPED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_NOTIFICATION_RECEIVED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_SCHEDULED
import org.wordpress.android.analytics.AnalyticsTracker.Stat.BLOGGING_REMINDERS_SCREEN_SHOWN
Expand Down Expand Up @@ -161,6 +163,23 @@ class BloggingRemindersAnalyticsTrackerTest {
})
}

@Test
fun `trackRemindersIncludePromptPressed tracks correct event and properties`() {
bloggingRemindersAnalyticsTracker.trackRemindersIncludePromptPressed(true)
verify(analyticsTracker).track(
BLOGGING_REMINDERS_INCLUDE_PROMPT_TAPPED,
mapOf("enabled" to "true", "blog_type" to null)
)
}

@Test
fun `trackRemindersIncludePromptHelpPressed tracks correct event`() {
bloggingRemindersAnalyticsTracker.trackRemindersIncludePromptHelpPressed()
verify(analyticsTracker).track(eq(BLOGGING_REMINDERS_INCLUDE_PROMPT_HELP_TAPPED), checkMap {
assertThat(it).containsKey("blog_type")
})
}

private fun mapCaptor() = argumentCaptor<Map<String, Any?>>()

private fun checkMap(predicate: (Map<String, Any?>) -> Unit) = check(predicate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ public enum Stat {
BLOGGING_REMINDERS_SCHEDULED,
BLOGGING_REMINDERS_CANCELLED,
BLOGGING_REMINDERS_NOTIFICATION_RECEIVED,
BLOGGING_REMINDERS_INCLUDE_PROMPT_TAPPED,
BLOGGING_REMINDERS_INCLUDE_PROMPT_HELP_TAPPED,
LOGIN_EPILOGUE_CHOOSE_SITE_TAPPED,
LOGIN_EPILOGUE_CREATE_NEW_SITE_TAPPED,
CREATE_SITE_NOTIFICATION_SCHEDULED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) {
return "blogging_reminders_cancelled";
case BLOGGING_REMINDERS_NOTIFICATION_RECEIVED:
return "blogging_reminders_notification_received";
case BLOGGING_REMINDERS_INCLUDE_PROMPT_TAPPED:
return "blogging_reminders_include_prompt_tapped";
case BLOGGING_REMINDERS_INCLUDE_PROMPT_HELP_TAPPED:
return "blogging_reminders_include_prompt_help_tapped";
case LOGIN_EPILOGUE_CHOOSE_SITE_TAPPED:
return "login_epilogue_choose_site_tapped";
case LOGIN_EPILOGUE_CREATE_NEW_SITE_TAPPED:
Expand Down

0 comments on commit 6b2e279

Please sign in to comment.