Skip to content

Commit

Permalink
Replace helper with tracker for MainCreateSheet analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Horta committed Jun 3, 2024
1 parent 4183f35 commit 096ad6e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 316 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package org.wordpress.android.ui.main.utils

import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper
import org.wordpress.android.ui.main.MainActionListItem
import org.wordpress.android.ui.main.WPMainNavigationView.PageType
import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution
import org.wordpress.android.ui.voicetocontent.VoiceToContentFeatureUtils
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.SiteUtilsWrapper
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.util.config.ReaderFloatingButtonFeatureConfig
import java.util.Locale
import javax.inject.Inject

class MainCreateSheetHelper @Inject constructor(
Expand All @@ -20,7 +15,6 @@ class MainCreateSheetHelper @Inject constructor(
private val bloggingPromptsSettingsHelper: BloggingPromptsSettingsHelper,
private val buildConfig: BuildConfigWrapper,
private val siteUtils: SiteUtilsWrapper,
private val analyticsTracker: AnalyticsTrackerWrapper,
) {
fun shouldShowFabForPage(page: PageType?): Boolean {
val enabledForPage = page == PageType.MY_SITE ||
Expand All @@ -40,53 +34,4 @@ class MainCreateSheetHelper @Inject constructor(
}

suspend fun canCreatePromptAnswer(): Boolean = bloggingPromptsSettingsHelper.shouldShowPromptsFeature()

// region Analytics
fun trackActionTapped(page: PageType, actionType: MainActionListItem.ActionType) {
val stat = when (page) {
PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_ACTION_TAPPED
PageType.READER -> 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: PageType, attribution: BloggingPromptAttribution) {
val properties = mapOf("attribution" to attribution.value).filterValues { it.isNotBlank() }
val stat = when (page) {
PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_ANSWER_PROMPT_TAPPED
PageType.READER -> Stat.READER_CREATE_SHEET_ANSWER_PROMPT_TAPPED
else -> return
}
analyticsTracker.track(stat, properties)
}

fun trackHelpPromptActionTapped(page: PageType) {
val stat = when (page) {
PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_PROMPT_HELP_TAPPED
PageType.READER -> Stat.READER_CREATE_SHEET_PROMPT_HELP_TAPPED
else -> return
}
analyticsTracker.track(stat)
}

fun trackSheetShown(page: PageType) {
val stat = when (page) {
PageType.MY_SITE -> Stat.MY_SITE_CREATE_SHEET_SHOWN
PageType.READER -> Stat.READER_CREATE_SHEET_SHOWN
else -> return
}
analyticsTracker.track(stat)
}

fun trackFabShown(page: PageType) {
val stat = when (page) {
PageType.MY_SITE -> Stat.MY_SITE_CREATE_FAB_SHOWN
PageType.READER -> Stat.READER_CREATE_FAB_SHOWN
else -> return
}
analyticsTracker.track(stat)
}
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.wordpress.android.ui.main.MainActionListItem.AnswerBloggingPromptActi
import org.wordpress.android.ui.main.MainActionListItem.CreateAction
import org.wordpress.android.ui.main.MainFabUiState
import org.wordpress.android.ui.main.WPMainNavigationView.PageType
import org.wordpress.android.ui.main.analytics.MainCreateSheetTracker
import org.wordpress.android.ui.main.utils.MainCreateSheetHelper
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.ui.mysite.cards.dashboard.bloggingprompts.BloggingPromptAttribution
Expand Down Expand Up @@ -65,9 +66,10 @@ class WPMainActivityViewModel @Inject constructor(
private val accountStore: AccountStore,
private val siteStore: SiteStore,
private val bloggingPromptsStore: BloggingPromptsStore,
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
private val shouldAskPrivacyConsent: ShouldAskPrivacyConsent,
private val mainCreateSheetHelper: MainCreateSheetHelper,
private val mainCreateSheetTracker: MainCreateSheetTracker,
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
) : ScopedViewModel(mainDispatcher) {
private var isStarted = false

Expand Down Expand Up @@ -236,11 +238,11 @@ class WPMainActivityViewModel @Inject constructor(
}

_mainActions.postValue(actionsList)
if (onFabClicked) trackCreateActionsSheetCard(actionsList)
if (onFabClicked) mainCreateSheetTracker.trackCreateActionsSheetCard(actionsList)
}

private fun onCreateActionClicked(actionType: ActionType, page: PageType) {
mainCreateSheetHelper.trackActionTapped(page, actionType)
mainCreateSheetTracker.trackActionTapped(page, actionType)
_isBottomSheetShowing.postValue(Event(false))
_createAction.postValue(actionType)

Expand All @@ -253,22 +255,16 @@ class WPMainActivityViewModel @Inject constructor(
}

private fun onAnswerPromptActionClicked(promptId: Int, attribution: BloggingPromptAttribution, page: PageType) {
mainCreateSheetHelper.trackAnswerPromptActionTapped(page, attribution)
mainCreateSheetTracker.trackAnswerPromptActionTapped(page, attribution)
_isBottomSheetShowing.postValue(Event(false))
_createPostWithBloggingPrompt.postValue(promptId)
}

private fun onHelpPromptActionClicked(page: PageType) {
mainCreateSheetHelper.trackHelpPromptActionTapped(page)
mainCreateSheetTracker.trackHelpPromptActionTapped(page)
_openBloggingPromptsOnboarding.call()
}

private fun trackCreateActionsSheetCard(actions: List<MainActionListItem>) {
if (actions.any { it is AnswerBloggingPromptAction }) {
analyticsTracker.track(Stat.BLOGGING_PROMPTS_CREATE_SHEET_CARD_VIEWED)
}
}

fun onFabClicked(site: SiteModel?, page: PageType) {
appPrefsWrapper.setMainFabTooltipDisabled(true)

Expand All @@ -284,7 +280,7 @@ class WPMainActivityViewModel @Inject constructor(
// latest info.
loadMainActions(site, page, onFabClicked = true)

mainCreateSheetHelper.trackSheetShown(page)
mainCreateSheetTracker.trackSheetShown(page)
_isBottomSheetShowing.postValue(Event(true))
}
} else {
Expand Down Expand Up @@ -332,7 +328,7 @@ class WPMainActivityViewModel @Inject constructor(
}

private fun setMainFabUiState(isFabVisible: Boolean, site: SiteModel?, page: PageType?) {
if (isFabVisible && page != null) mainCreateSheetHelper.trackFabShown(page)
if (isFabVisible && page != null) mainCreateSheetTracker.trackFabShown(page)

val newState = MainFabUiState(
isFabVisible = isFabVisible,
Expand Down
Loading

0 comments on commit 096ad6e

Please sign in to comment.