Skip to content

Commit

Permalink
netp pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Feb 28, 2025
1 parent 55278d4 commit 88dd14a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.networkprotection.impl.cohort
import androidx.annotation.VisibleForTesting
import com.duckduckgo.common.utils.plugins.pixel.PixelInterceptorPlugin
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.networkprotection.impl.pixels.NetworkProtectionPixelNames.NETP_SETTINGS_PRESSED
import com.squareup.anvil.annotations.ContributesMultibinding
import javax.inject.Inject
import logcat.logcat
Expand Down Expand Up @@ -84,6 +85,7 @@ class NetpCohortPixelInterceptor @Inject constructor(
"m_netp_ev_terms_accepted",
"m_netp_imp_geoswitching",
"m_netp_ev_geoswitching",
NETP_SETTINGS_PRESSED.pixelName,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.toBinaryString
import com.duckduckgo.mobile.android.R as CommonR
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams
import com.duckduckgo.networkprotection.api.NetworkProtectionAccessState
Expand Down Expand Up @@ -101,7 +102,8 @@ class LegacyProSettingNetPViewModel(
val screen = networkProtectionAccessState.getScreenForCurrentState()
screen?.let {
command.send(OpenNetPScreen(screen))
pixel.fire(NETP_SETTINGS_PRESSED)
val wasUsedBefore = networkProtectionState.isOnboarded()
pixel.fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to wasUsedBefore.toBinaryString()))
} ?: logcat { "Get screen for current NetP state is null" }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.toBinaryString
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams
import com.duckduckgo.networkprotection.api.NetworkProtectionAccessState
import com.duckduckgo.networkprotection.api.NetworkProtectionState
Expand Down Expand Up @@ -136,7 +137,8 @@ class ProSettingNetPViewModel(
val screen = networkProtectionAccessState.getScreenForCurrentState()
screen?.let {
command.send(OpenNetPScreen(screen))
pixel.fire(NETP_SETTINGS_PRESSED)
val wasUsedBefore = networkProtectionState.isOnboarded()
pixel.fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to wasUsedBefore.toBinaryString()))
} ?: logcat { "Get screen for current NetP state is null" }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ class NetpCohortPixelInterceptorTest {
assertEquals(null, result.body)
}

@Test
fun `when cohort local date is not set then send exempted main VPN settings pressed pixel`() {
whenever(netpCohortStore.cohortLocalDate).thenReturn(null)
val pixelUrl = String.format(PIXEL_TEMPLATE, "m_netp_ev_setting_pressed_c")

val result = testee.intercept(FakeChain(pixelUrl))

assertEquals(pixelUrl, result.request.url.toString())
assertEquals("", result.message)
assertEquals(null, result.body)
}

companion object {
private const val PIXEL_TEMPLATE = "https://improving.duckduckgo.com/t/%s_android_phone?appVersion=5.135.0&test=1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,32 @@ class LegacyProSettingNetPViewModelTest {
}

@Test
fun whenNetPSettingClickedThenReturnScreenForCurrentState() = runTest {
fun `when NetP setting clicked and not onboarded then return screen for current state and send pixel`() = runTest {
val testScreen = object : ActivityParams {}
whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen)
whenever(networkProtectionState.isOnboarded()).thenReturn(false)

proSettingNetPViewModel.commands().test {
proSettingNetPViewModel.onNetPSettingClicked()

assertEquals(Command.OpenNetPScreen(testScreen), awaitItem())
verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "0"))

cancelAndConsumeRemainingEvents()
}
}

@Test
fun `when NetP setting clicked and onboarded then return screen for current state and send pixel`() = runTest {
val testScreen = object : ActivityParams {}
whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen)
whenever(networkProtectionState.isOnboarded()).thenReturn(true)

proSettingNetPViewModel.commands().test {
proSettingNetPViewModel.onNetPSettingClicked()

assertEquals(Command.OpenNetPScreen(testScreen), awaitItem())
verify(pixel).fire(NETP_SETTINGS_PRESSED)
verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "1"))

cancelAndConsumeRemainingEvents()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,32 @@ class ProSettingNetPViewModelTest {
}

@Test
fun `when netp Setting clicked then netp screen is opened`() = runTest {
fun `when NetP setting clicked and not onboarded then return screen for current state and send pixel`() = runTest {
val testScreen = object : ActivityParams {}
whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen)
whenever(networkProtectionState.isOnboarded()).thenReturn(false)

proSettingNetPViewModel.commands().test {
proSettingNetPViewModel.onNetPSettingClicked()

assertEquals(Command.OpenNetPScreen(testScreen), awaitItem())
verify(pixel).fire(NETP_SETTINGS_PRESSED)
verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "0"))

cancelAndConsumeRemainingEvents()
}
}

@Test
fun `when NetP setting clicked and onboarded then return screen for current state and send pixel`() = runTest {
val testScreen = object : ActivityParams {}
whenever(networkProtectionAccessState.getScreenForCurrentState()).thenReturn(testScreen)
whenever(networkProtectionState.isOnboarded()).thenReturn(true)

proSettingNetPViewModel.commands().test {
proSettingNetPViewModel.onNetPSettingClicked()

assertEquals(Command.OpenNetPScreen(testScreen), awaitItem())
verify(pixel).fire(NETP_SETTINGS_PRESSED, parameters = mapOf("was_used_before" to "1"))

cancelAndConsumeRemainingEvents()
}
Expand Down

0 comments on commit 88dd14a

Please sign in to comment.