Skip to content

Commit

Permalink
email pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Feb 27, 2025
1 parent c979b68 commit 29ecd3a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_APPEARANCE_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_APPTP_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_COOKIE_POPUP_PROTECTION_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_DEFAULT_BROWSER_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_EMAIL_PROTECTION_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_FIRE_BUTTON_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_GENERAL_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_NEXT_STEPS_ADDRESS_BAR
Expand Down Expand Up @@ -281,7 +280,7 @@ class NewSettingsViewModel @Inject constructor(
}
this@NewSettingsViewModel.command.send(command)
}
pixel.fire(SETTINGS_EMAIL_PROTECTION_PRESSED)
settingsPixelDispatcher.fireEmailPressed()
}

fun onAppTPSettingClicked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.duckduckgo.app.settings

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_EMAIL_PROTECTION_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_SYNC_PRESSED
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.common.utils.extensions.toBinaryString
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.duckchat.api.DuckChat
Expand All @@ -38,6 +40,7 @@ import kotlinx.coroutines.launch
interface SettingsPixelDispatcher {
fun fireSyncPressed()
fun fireDuckChatPressed()
fun fireEmailPressed()
}

@ContributesBinding(scope = AppScope::class)
Expand All @@ -47,6 +50,7 @@ class SettingsPixelDispatcherImpl @Inject constructor(
private val pixel: Pixel,
private val syncStateMonitor: SyncStateMonitor,
private val duckChat: DuckChat,
private val emailManager: EmailManager,
) : SettingsPixelDispatcher {

override fun fireSyncPressed() {
Expand Down Expand Up @@ -74,8 +78,21 @@ class SettingsPixelDispatcherImpl @Inject constructor(
}
}

override fun fireEmailPressed() {
appCoroutineScope.launch {
val isSignedIn = emailManager.isSignedIn()
pixel.fire(
pixel = SETTINGS_EMAIL_PROTECTION_PRESSED,
parameters = mapOf(
PARAM_EMAIL_IS_SIGNED_IN to isSignedIn.toBinaryString(),
),
)
}
}

private companion object {
const val PARAM_SYNC_IS_ENABLED = "is_enabled"
const val PARAM_DUCK_CHAT_USED_BEFORE = "was_used_before"
const val PARAM_EMAIL_IS_SIGNED_IN = "is_signed_in"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@ class NewSettingsViewModelTest {

verify(settingsPixelDispatcherMock).fireDuckChatPressed()
}

@Test
fun `when Email pressed then pixel is fired`() {
testee.onEmailProtectionSettingClicked()

verify(settingsPixelDispatcherMock).fireEmailPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.duckduckgo.app.settings

import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_EMAIL_PROTECTION_PRESSED
import com.duckduckgo.app.pixels.AppPixelName.SETTINGS_SYNC_PRESSED
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.duckchat.api.DuckChat
import com.duckduckgo.duckchat.impl.DuckChatPixelName
Expand Down Expand Up @@ -45,6 +47,8 @@ class SettingsPixelDispatcherTest {

@Mock private lateinit var duckChatMock: DuckChat

@Mock private lateinit var emailManagerMock: EmailManager

lateinit var testee: SettingsPixelDispatcherImpl

@Before
Expand Down Expand Up @@ -143,10 +147,37 @@ class SettingsPixelDispatcherTest {
)
}

@Test
fun `when fireEmailPressed and is not signed in, then send a pixel with not actively used information`() = runTest {
whenever(emailManagerMock.isSignedIn()).thenReturn(false)

val testee = createTestee()
testee.fireEmailPressed()

verify(pixelMock).fire(
pixel = SETTINGS_EMAIL_PROTECTION_PRESSED,
parameters = mapOf("is_signed_in" to "0"),
)
}

@Test
fun `when fireEmailPressed and is signed in, then send a pixel with actively used information`() = runTest {
whenever(emailManagerMock.isSignedIn()).thenReturn(true)

val testee = createTestee()
testee.fireEmailPressed()

verify(pixelMock).fire(
pixel = SETTINGS_EMAIL_PROTECTION_PRESSED,
parameters = mapOf("is_signed_in" to "1"),
)
}

private fun createTestee() = SettingsPixelDispatcherImpl(
appCoroutineScope = coroutinesTestRule.testScope,
pixel = pixelMock,
syncStateMonitor = syncStateMonitorMock,
duckChat = duckChatMock,
emailManager = emailManagerMock,
)
}

0 comments on commit 29ecd3a

Please sign in to comment.