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

move out of main cta viewmodel checks #5414

Merged
merged 2 commits into from
Dec 20, 2024
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
69 changes: 36 additions & 33 deletions app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,41 @@ class CtaViewModel @Inject constructor(
}

suspend fun onCtaShown(cta: Cta) {
cta.shownPixel?.let {
val canSendPixel = when (cta) {
is DaxCta -> cta.canSendShownPixel()
else -> true
withContext(dispatchers.io()) {
cta.shownPixel?.let {
val canSendPixel = when (cta) {
is DaxCta -> cta.canSendShownPixel()
else -> true
}
if (canSendPixel) {
pixel.fire(it, cta.pixelShownParameters())
}
}
if (canSendPixel) {
pixel.fire(it, cta.pixelShownParameters())
if (cta is OnboardingDaxDialogCta && cta.markAsReadOnShow) {
dismissedCtaDao.insert(DismissedCta(cta.ctaId))
}
}
if (cta is OnboardingDaxDialogCta && cta.markAsReadOnShow) {
dismissedCtaDao.insert(DismissedCta(cta.ctaId))
}
if (cta is BrokenSitePromptDialogCta) {
brokenSitePrompt.ctaShown()
}
withContext(dispatchers.io()) {
if (cta is BrokenSitePromptDialogCta) {
brokenSitePrompt.ctaShown()
}

if (cta is DaxBubbleCta.DaxPrivacyProCta || cta is DaxBubbleCta.DaxExperimentPrivacyProCta) {
extendedOnboardingPixelsPlugin.testPrivacyProOnboardingShownMetricPixel()?.getPixelDefinitions()?.forEach {
pixel.fire(it.pixelName, it.params)
}
}
}

// Temporary pixel
val isVisitSiteSuggestionsCta =
cta is DaxBubbleCta.DaxIntroVisitSiteOptionsCta || cta is DaxBubbleCta.DaxExperimentIntroVisitSiteOptionsCta ||
cta is OnboardingDaxDialogCta.DaxSiteSuggestionsCta || cta is OnboardingDaxDialogCta.DaxExperimentSiteSuggestionsCta
if (isVisitSiteSuggestionsCta) {
if (userBrowserProperties.daysSinceInstalled() <= MIN_DAYS_TO_COUNT_ONBOARDING_CTA_SHOWN) {
val count = onboardingStore.visitSiteCtaDisplayCount ?: 0
pixel.fire(AppPixelName.ONBOARDING_VISIT_SITE_CTA_SHOWN, mapOf("count" to count.toString()))
onboardingStore.visitSiteCtaDisplayCount = count + 1
} else {
onboardingStore.clearVisitSiteCtaDisplayCount()
// Temporary pixel
val isVisitSiteSuggestionsCta =
cta is DaxBubbleCta.DaxIntroVisitSiteOptionsCta || cta is DaxBubbleCta.DaxExperimentIntroVisitSiteOptionsCta ||
cta is OnboardingDaxDialogCta.DaxSiteSuggestionsCta || cta is OnboardingDaxDialogCta.DaxExperimentSiteSuggestionsCta
if (isVisitSiteSuggestionsCta) {
if (userBrowserProperties.daysSinceInstalled() <= MIN_DAYS_TO_COUNT_ONBOARDING_CTA_SHOWN) {
val count = onboardingStore.visitSiteCtaDisplayCount ?: 0
pixel.fire(AppPixelName.ONBOARDING_VISIT_SITE_CTA_SHOWN, mapOf("count" to count.toString()))
onboardingStore.visitSiteCtaDisplayCount = count + 1
} else {
onboardingStore.clearVisitSiteCtaDisplayCount()
}
}
}
}
Expand Down Expand Up @@ -250,8 +251,8 @@ class CtaViewModel @Inject constructor(
}

suspend fun getFireDialogCta(): OnboardingDaxDialogCta? {
if (!daxOnboardingActive() || daxDialogFireEducationShown()) return null
return withContext(dispatchers.io()) {
if (!daxOnboardingActive() || daxDialogFireEducationShown()) return@withContext null
if (highlightsOnboardingExperimentManager.isHighlightsEnabled()) {
return@withContext OnboardingDaxDialogCta.DaxExperimentFireButtonCta(onboardingStore, appInstallStore)
} else {
Expand All @@ -261,8 +262,8 @@ class CtaViewModel @Inject constructor(
}

suspend fun getSiteSuggestionsDialogCta(): OnboardingDaxDialogCta? {
if (!daxOnboardingActive() || !canShowDaxIntroVisitSiteCta()) return null
return withContext(dispatchers.io()) {
if (!daxOnboardingActive() || !canShowDaxIntroVisitSiteCta()) return@withContext null
if (highlightsOnboardingExperimentManager.isHighlightsEnabled()) {
return@withContext OnboardingDaxDialogCta.DaxExperimentSiteSuggestionsCta(onboardingStore, appInstallStore)
} else {
Expand All @@ -272,8 +273,8 @@ class CtaViewModel @Inject constructor(
}

suspend fun getEndStaticDialogCta(): OnboardingDaxDialogCta.DaxExperimentEndStaticCta? {
if (!daxOnboardingActive() && daxDialogEndShown()) return null
return withContext(dispatchers.io()) {
if (!daxOnboardingActive() && daxDialogEndShown()) return@withContext null
return@withContext OnboardingDaxDialogCta.DaxExperimentEndStaticCta(onboardingStore, appInstallStore)
}
}
Expand Down Expand Up @@ -473,7 +474,7 @@ class CtaViewModel @Inject constructor(
}
}

private suspend fun isSiteNotAllowedForOnboarding(site: Site): Boolean {
private fun isSiteNotAllowedForOnboarding(site: Site): Boolean {
val uri = site.url.toUri()

if (subscriptions.isPrivacyProUrl(uri)) return true
Expand Down Expand Up @@ -502,9 +503,11 @@ class CtaViewModel @Inject constructor(
// We only want to show New Tab when the Home CTAs from Onboarding has finished
// https://app.asana.com/0/1157893581871903/1207769731595075/f
suspend fun areBubbleDaxDialogsCompleted(): Boolean {
val noBrowserCtaExperiment = extendedOnboardingFeatureToggles.noBrowserCtas().isEnabled()
val bubbleCtasShown = daxDialogEndShown() && (daxDialogNetworkShown() || daxDialogOtherShown() || daxDialogTrackersFoundShown())
return noBrowserCtaExperiment || bubbleCtasShown || hideTips() || !userStageStore.daxOnboardingActive()
return withContext(dispatchers.io()) {
val noBrowserCtaExperiment = extendedOnboardingFeatureToggles.noBrowserCtas().isEnabled()
val bubbleCtasShown = daxDialogEndShown() && (daxDialogNetworkShown() || daxDialogOtherShown() || daxDialogTrackersFoundShown())
noBrowserCtaExperiment || bubbleCtasShown || hideTips() || !userStageStore.daxOnboardingActive()
}
}

private fun daxDialogSerpShown(): Boolean = dismissedCtaDao.exists(CtaId.DAX_DIALOG_SERP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.duckduckgo.app.widget.ui.WidgetCapabilities
import com.duckduckgo.brokensite.api.BrokenSitePrompt
import com.duckduckgo.browser.api.UserBrowserProperties
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.duckplayer.api.DuckPlayer
import com.duckduckgo.feature.toggles.api.Toggle
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -72,7 +71,6 @@ class OnboardingDaxDialogTests {
private val onboardingStore: OnboardingStore = mock()
private val userStageStore: UserStageStore = mock()
private val tabRepository: TabRepository = mock()
private val dispatchers: DispatcherProvider = mock()
private val duckDuckGoUrlDetector: DuckDuckGoUrlDetector = mock()
private val extendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles = mock()
private val mockDuckPlayer: DuckPlayer = mock()
Expand All @@ -95,7 +93,13 @@ class OnboardingDaxDialogTests {
widgetCapabilities,
dismissedCtaDao,
userAllowListRepository,
settingsDataStore, onboardingStore, userStageStore, tabRepository, dispatchers, duckDuckGoUrlDetector, extendedOnboardingFeatureToggles,
settingsDataStore,
onboardingStore,
userStageStore,
tabRepository,
coroutineRule.testDispatcherProvider,
duckDuckGoUrlDetector,
extendedOnboardingFeatureToggles,
subscriptions = mock(),
mockDuckPlayer,
mockHighlightsOnboardingExperimentManager,
Expand Down
Loading