diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptor.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptor.kt index f2bd2def964c..e21e02a4d430 100644 --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptor.kt +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptor.kt @@ -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 @@ -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, ) } } diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt index 686f54ddc531..16cd17e9f139 100644 --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModel.kt @@ -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 @@ -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" } } } diff --git a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt index a5881ddeb1de..ca62b5abe29c 100644 --- a/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt +++ b/network-protection/network-protection-impl/src/main/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModel.kt @@ -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 @@ -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" } } } diff --git a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptorTest.kt b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptorTest.kt index f07c563126bd..bb716fc97ebc 100644 --- a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptorTest.kt +++ b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/cohort/NetpCohortPixelInterceptorTest.kt @@ -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" } diff --git a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt index 25866ec4dd9a..398b9541b120 100644 --- a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt +++ b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/LegacyProSettingNetPViewModelTest.kt @@ -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() } diff --git a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt index 92e8b91c50bb..858ce6fcab79 100644 --- a/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt +++ b/network-protection/network-protection-impl/src/test/java/com/duckduckgo/networkprotection/impl/subscription/settings/ProSettingNetPViewModelTest.kt @@ -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() }