Skip to content

Commit

Permalink
Edit temporary pixel for not showing trackers network dialog (#5244)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1208660560293084/f

### Description
Fire skip network pixel only if onboarding is still active

### Steps to test this PR
_Send pixel_
- [x] Fresh install
- [x] Go to any youtube URL
- [x] Check pixel `m_onboarding_skip_major_network_unique` is **sent**

_Ignore pixel_
- [x] Refresh youtube site or go to a different youtube URL
- [x] Check pixel `m_onboarding_skip_major_network_unique` is
**ignored**

_Pixel **not** fired_
- [x] Go to any website with trackers (_e.g. bbc.co.uk_)
- [x] Tap 'Got it!' button
- [x] Go to any youtube URL
- [x] Check pixel `m_onboarding_skip_major_network_unique` is ** not
sent or ignored**

### No UI changes
  • Loading branch information
nalcalag authored Nov 14, 2024
1 parent 3a877a3 commit ca8bf2e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,39 @@ class CtaViewModelTest {
whenever(mockDuckPlayer.isSimulatedYoutubeNoCookie(any())).thenReturn(false)

val value = testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = true, site = site)
verify(mockPixel).fire(eq(ONBOARDING_SKIP_MAJOR_NETWORK_UNIQUE), any(), any(), eq(Unique()))
assertNull(value)
}

@Test
fun givenDuckPlayerSiteWhenRefreshCtaWhileBrowsingThenFireSkipMajorNetworkPixel() = runTest {
givenDaxOnboardingActive()
val site = site(url = "duck://player/12345", entity = TestEntity("Google", "Google", 9.0))

whenever(mockDuckPlayer.isDuckPlayerUri(any())).thenReturn(true)
whenever(mockDuckPlayer.getDuckPlayerState()).thenReturn(ENABLED)
whenever(mockDuckPlayer.getUserPreferences()).thenReturn(UserPreferences(false, AlwaysAsk))
whenever(mockDuckPlayer.isYouTubeUrl(any())).thenReturn(false)
whenever(mockDuckPlayer.isSimulatedYoutubeNoCookie(any())).thenReturn(false)

testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = true, site = site)
verify(mockPixel).fire(eq(ONBOARDING_SKIP_MAJOR_NETWORK_UNIQUE), any(), any(), eq(Unique()))
}

@Test
fun givenDuckPlayerSiteWhenRefreshCtaWhileBrowsingAndTrackersDialogAlreadyShownThenDontSentSkipMajorNetworkPixel() = runTest {
givenDaxOnboardingActive()
val site = site(url = "duck://player/12345", entity = TestEntity("Google", "Google", 9.0))

whenever(mockDuckPlayer.isDuckPlayerUri(any())).thenReturn(true)
whenever(mockDuckPlayer.getDuckPlayerState()).thenReturn(ENABLED)
whenever(mockDuckPlayer.getUserPreferences()).thenReturn(UserPreferences(false, AlwaysAsk))
whenever(mockDuckPlayer.isYouTubeUrl(any())).thenReturn(false)
whenever(mockDuckPlayer.isSimulatedYoutubeNoCookie(any())).thenReturn(false)

testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = true, site = site)
verify(mockPixel).fire(eq(ONBOARDING_SKIP_MAJOR_NETWORK_UNIQUE), any(), any(), eq(Unique()))
}

@Test
fun givenHighlightsExperimentWhenRefreshCtaOnHomeTabAndIntroCtaWasNotPreviouslyShownThenExperimentIntroCtaShown() = runTest {
givenDaxOnboardingActive()
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class CtaViewModel @Inject constructor(
val nonNullSite = site ?: return null

val host = nonNullSite.domain
if (host == null || userAllowListRepository.isDomainInUserAllowList(host) || isSiteNotAllowedForOnboarding(nonNullSite.url)) {
if (host == null || userAllowListRepository.isDomainInUserAllowList(host) || isSiteNotAllowedForOnboarding(nonNullSite)) {
return null
}

Expand Down Expand Up @@ -368,20 +368,25 @@ class CtaViewModel @Inject constructor(
}
}

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

if (subscriptions.isPrivacyProUrl(uri)) return true

val isDuckPlayerUrl =
duckPlayer.getDuckPlayerState() == DuckPlayerState.ENABLED &&
(
(duckPlayer.getUserPreferences().privatePlayerMode == AlwaysAsk && duckPlayer.isYouTubeUrl(uri)) ||
duckPlayer.isDuckPlayerUri(url) || duckPlayer.isSimulatedYoutubeNoCookie(uri)
duckPlayer.isDuckPlayerUri(site.url) || duckPlayer.isSimulatedYoutubeNoCookie(uri)
)

if (isDuckPlayerUrl) {
pixel.fire(pixel = ONBOARDING_SKIP_MAJOR_NETWORK_UNIQUE, type = Unique())
if (isDuckPlayerUrl) { // temporary pixel
val isMayorNetwork = !daxDialogNetworkShown() && !daxDialogTrackersFoundShown() && OnboardingDaxDialogCta.mainTrackerNetworks.any {
site.entity?.displayName?.contains(it) ?: false
}
if (isMayorNetwork) {
pixel.fire(pixel = ONBOARDING_SKIP_MAJOR_NETWORK_UNIQUE, type = Unique())
}
}

return isDuckPlayerUrl
Expand Down

0 comments on commit ca8bf2e

Please sign in to comment.