Skip to content

Commit 293a5c8

Browse files
authored
add "was_used_before" pixel param for Duck.ai launches originating on the Input Screen (#6739)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671518894266/task/1211247695189653?focus=true ### Description Adds "was_used_before" pixel param for Duck.ai launches originating on the Input Screen. ### Steps to test this PR - [x] Clean install the app. - [x] Go to Settings -> AI Features. - [x] Enable the experimental address bar. - [x] Go to browser and click on the omnibar. - [x] Switch to Duck.ai and submit a prompt. - [x] Verify that `m_aichat_experimental_omnibar_prompt_submitted_count` is sent with `was_used_before=0` param. - [x] Go to browser again and click on the omnibar. - [x] Switch to Duck.ai and submit a prompt. - [x] Verify that `m_aichat_experimental_omnibar_prompt_submitted_count` is sent with `was_used_before=1` param.
1 parent 372dbac commit 293a5c8

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/inputscreen/ui/viewmodel/InputScreenViewModel.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,22 @@ class InputScreenViewModel @AssistedInject constructor(
375375
}
376376

377377
fun onChatSubmitted(query: String) {
378-
if (isWebUrl(query)) {
379-
command.value = Command.SubmitSearch(query)
380-
} else {
381-
command.value = Command.SubmitChat(query)
382-
duckChat.openDuckChatWithAutoPrompt(query)
383-
}
384-
pixel.fire(DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED)
385-
pixel.fire(DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED_DAILY, type = Daily())
386-
inputScreenDiscoveryFunnel.onPromptSubmitted()
387-
inputScreenSessionUsageMetric.onPromptSubmitted()
388-
389378
viewModelScope.launch {
379+
val wasDuckAiOpenedBefore = duckChat.wasOpenedBefore()
380+
if (isWebUrl(query)) {
381+
command.value = Command.SubmitSearch(query)
382+
} else {
383+
command.value = Command.SubmitChat(query)
384+
duckChat.openDuckChatWithAutoPrompt(query)
385+
}
386+
387+
val params = mapOf(DuckChatPixelParameters.WAS_USED_BEFORE to wasDuckAiOpenedBefore.toBinaryString())
388+
pixel.fire(pixel = DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED, parameters = params)
389+
pixel.fire(DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED_DAILY, type = Daily())
390+
391+
inputScreenDiscoveryFunnel.onPromptSubmitted()
392+
inputScreenSessionUsageMetric.onPromptSubmitted()
393+
390394
sessionStore.setHasUsedChatMode(true)
391395
checkAndFireBothModesPixel()
392396
}

duckchat/duckchat-impl/src/test/kotlin/com/duckduckgo/duckchat/impl/ui/inputscreen/InputScreenViewModelTest.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ class InputScreenViewModelTest {
6868
private val inputScreenSessionUsageMetric: InputScreenSessionUsageMetric = mock()
6969

7070
@Before
71-
fun setup() {
71+
fun setup() = runTest {
7272
whenever(autoCompleteSettings.autoCompleteSuggestionsEnabled).thenReturn(true)
7373
whenever(autoComplete.autoComplete(any())).thenReturn(
7474
flowOf(AutoCompleteResult("", listOf(AutoCompleteDefaultSuggestion("suggestion")))),
7575
)
76+
whenever(duckChat.wasOpenedBefore()).thenReturn(false)
7677
}
7778

7879
private fun createViewModel(currentOmnibarText: String = ""): InputScreenViewModel {
@@ -852,14 +853,35 @@ class InputScreenViewModelTest {
852853

853854
@Test
854855
fun `when onChatSubmitted then prompt submitted pixels are fired`() = runTest {
856+
whenever(duckChat.wasOpenedBefore()).thenReturn(false)
855857
val viewModel = createViewModel()
856858

857859
whenever(inputScreenSessionStore.hasUsedSearchMode()).thenReturn(false)
858860
whenever(inputScreenSessionStore.hasUsedChatMode()).thenReturn(false)
859861

860862
viewModel.onChatSubmitted("prompt")
861863

862-
verify(pixel).fire(DuckChatPixelName.DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED)
864+
verify(pixel).fire(
865+
pixel = DuckChatPixelName.DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED,
866+
parameters = mapOf(DuckChatPixelParameters.WAS_USED_BEFORE to "0"),
867+
)
868+
verify(pixel).fire(DuckChatPixelName.DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED_DAILY, type = Daily())
869+
}
870+
871+
@Test
872+
fun `when onChatSubmitted and DuckChat was used before then prompt submitted pixel includes was_used_before parameter as 1`() = runTest {
873+
whenever(duckChat.wasOpenedBefore()).thenReturn(true)
874+
val viewModel = createViewModel()
875+
876+
whenever(inputScreenSessionStore.hasUsedSearchMode()).thenReturn(false)
877+
whenever(inputScreenSessionStore.hasUsedChatMode()).thenReturn(false)
878+
879+
viewModel.onChatSubmitted("prompt")
880+
881+
verify(pixel).fire(
882+
pixel = DuckChatPixelName.DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED,
883+
parameters = mapOf(DuckChatPixelParameters.WAS_USED_BEFORE to "1"),
884+
)
863885
verify(pixel).fire(DuckChatPixelName.DUCK_CHAT_EXPERIMENTAL_OMNIBAR_PROMPT_SUBMITTED_DAILY, type = Daily())
864886
}
865887

0 commit comments

Comments
 (0)