Skip to content

Commit 536d709

Browse files
authored
add missing discovery param to autofill_settings_opened pixel (#6267)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1202552961248957/task/1210398081973867?focus=true ### Description Adds missing pixel parameter. ### Steps to test this PR - [ ] Launch a clean app. - [ ] Open "Passwords & Autofill" from settings. - [ ] Verify that `autofill_settings_opened` pixel is sent with `source=settings` and `has_credentials_saved=0` parameters.
1 parent df099cc commit 536d709

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/ui/settings/AutofillSettingsViewModel.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ import com.duckduckgo.autofill.impl.ui.settings.AutofillSettingsViewModel.Comman
4343
import com.duckduckgo.autofill.impl.ui.settings.AutofillSettingsViewModel.Command.NavigatePasswordList
4444
import com.duckduckgo.autofill.impl.ui.settings.AutofillSettingsViewModel.Command.NavigateToHowToSyncWithDesktop
4545
import com.duckduckgo.common.utils.DispatcherProvider
46+
import com.duckduckgo.common.utils.extensions.toBinaryString
4647
import com.duckduckgo.di.scopes.ActivityScope
4748
import javax.inject.Inject
4849
import kotlinx.coroutines.channels.Channel
4950
import kotlinx.coroutines.flow.Flow
5051
import kotlinx.coroutines.flow.MutableStateFlow
5152
import kotlinx.coroutines.flow.distinctUntilChanged
53+
import kotlinx.coroutines.flow.firstOrNull
5254
import kotlinx.coroutines.flow.map
5355
import kotlinx.coroutines.flow.onStart
5456
import kotlinx.coroutines.flow.receiveAsFlow
@@ -106,10 +108,16 @@ class AutofillSettingsViewModel @Inject constructor(
106108
}
107109

108110
fun sendLaunchPixel(autofillScreenLaunchSource: AutofillScreenLaunchSource) {
109-
pixel.fire(
110-
AUTOFILL_SETTINGS_OPENED,
111-
parameters = mapOf("source" to autofillScreenLaunchSource.asString()),
112-
)
111+
viewModelScope.launch {
112+
val hasCredentialsSaved = (autofillStore.getCredentialCount().firstOrNull() ?: 0) > 0
113+
pixel.fire(
114+
AUTOFILL_SETTINGS_OPENED,
115+
parameters = mapOf(
116+
"source" to autofillScreenLaunchSource.asString(),
117+
"has_credentials_saved" to hasCredentialsSaved.toBinaryString(),
118+
),
119+
)
120+
}
113121
}
114122

115123
private fun onViewStateFlowStart() {

autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/ui/settings/AutofillSettingsViewModelTest.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,18 @@ class AutofillSettingsViewModelTest {
122122
}
123123

124124
@Test
125-
fun whenSendLaunchPixelThenPixelIsSent() = runTest {
125+
fun `when send launch pixel and no credentials saved then pixel is sent`() = runTest {
126+
whenever(mockStore.getCredentialCount()).thenReturn(flowOf(0))
126127
testee.sendLaunchPixel(AutofillScreenLaunchSource.SettingsActivity)
127-
val expectedParams = mapOf("source" to "settings")
128+
val expectedParams = mapOf("source" to "settings", "has_credentials_saved" to "0")
129+
verify(pixel).fire(pixel = eq(AUTOFILL_SETTINGS_OPENED), parameters = eq(expectedParams), any(), any())
130+
}
131+
132+
@Test
133+
fun `when send launch pixel and has credentials saved then pixel is sent`() = runTest {
134+
whenever(mockStore.getCredentialCount()).thenReturn(flowOf(5))
135+
testee.sendLaunchPixel(AutofillScreenLaunchSource.BrowserOverflow)
136+
val expectedParams = mapOf("source" to "overflow_menu", "has_credentials_saved" to "1")
128137
verify(pixel).fire(pixel = eq(AUTOFILL_SETTINGS_OPENED), parameters = eq(expectedParams), any(), any())
129138
}
130139

0 commit comments

Comments
 (0)