Skip to content

Commit

Permalink
Added pixels.
Browse files Browse the repository at this point in the history
  • Loading branch information
anikiki committed Sep 26, 2024
1 parent 2ee8aac commit 2491fda
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,37 @@ class BrowserTabViewModelTest {
assertEquals("false", argumentCaptor.firstValue[PixelParameter.BOOKMARK_CAPABLE])
}

@Test
fun whenSearchSuggestionSubmittedWithTabsThenAutoCompleteSearchSelectionPixelSent() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0), TabEntity("2", "https://example.com", position = 1))
val suggestions = listOf(AutoCompleteSwitchToTabSuggestion("example", "", "", ""))
testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", suggestions))
testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion("example", "", "", ""))

val argumentCaptor = argumentCaptor<Map<String, String>>()
verify(mockPixel).fire(eq(AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("true", argumentCaptor.firstValue[PixelParameter.SHOWED_SWITCH_TO_TAB])
assertEquals("true", argumentCaptor.firstValue[PixelParameter.SWITCH_TO_TAB_CAPABLE])
}

@Test
fun whenSearchSuggestionSubmittedWithoutTabsThenAutoCompleteSearchSelectionPixelSent() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))
testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", emptyList()))
testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion("example", "", "", ""))

val argumentCaptor = argumentCaptor<Map<String, String>>()
verify(mockPixel).fire(eq(AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("false", argumentCaptor.firstValue[PixelParameter.SHOWED_SWITCH_TO_TAB])
assertEquals("false", argumentCaptor.firstValue[PixelParameter.SWITCH_TO_TAB_CAPABLE])
}

@Test
fun whenUserSelectToEditQueryThenMoveCaretToTheEnd() = runTest {
testee.onUserSelectedToEditQuery("foo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,17 +838,23 @@ class BrowserTabViewModel @Inject constructor(
val hasHistory = withContext(dispatchers.io()) {
history.hasHistory()
}
val hasTabs = withContext(dispatchers.io()) {
(tabRepository.liveTabs.value?.size ?: 0) > 1
}
val hasBookmarkResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteBookmarkSuggestion && !it.isFavorite }
val hasFavoriteResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteBookmarkSuggestion && it.isFavorite }
val hasHistoryResults =
currentViewState.searchResults.suggestions.any { it is AutoCompleteHistorySuggestion || it is AutoCompleteHistorySearchSuggestion }
val hasSwitchToTabResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteSwitchToTabSuggestion }
val params = mapOf(
PixelParameter.SHOWED_BOOKMARKS to hasBookmarkResults.toString(),
PixelParameter.SHOWED_FAVORITES to hasFavoriteResults.toString(),
PixelParameter.BOOKMARK_CAPABLE to hasBookmarks.toString(),
PixelParameter.FAVORITE_CAPABLE to hasFavorites.toString(),
PixelParameter.HISTORY_CAPABLE to hasHistory.toString(),
PixelParameter.SHOWED_HISTORY to hasHistoryResults.toString(),
PixelParameter.SWITCH_TO_TAB_CAPABLE to hasTabs.toString(),
PixelParameter.SHOWED_SWITCH_TO_TAB to hasSwitchToTabResults.toString(),
)
val pixelName = when (suggestion) {
is AutoCompleteBookmarkSuggestion -> {
Expand All @@ -861,6 +867,7 @@ class BrowserTabViewModel @Inject constructor(
is AutoCompleteSearchSuggestion -> if (suggestion.isUrl) AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION else AUTOCOMPLETE_SEARCH_PHRASE_SELECTION
is AutoCompleteHistorySuggestion -> AUTOCOMPLETE_HISTORY_SITE_SELECTION
is AutoCompleteHistorySearchSuggestion -> AUTOCOMPLETE_HISTORY_SEARCH_SELECTION
is AutoCompleteSwitchToTabSuggestion -> AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION
else -> return
}

Expand Down Expand Up @@ -3653,6 +3660,9 @@ class BrowserTabViewModel @Inject constructor(
if (suggestions.any { it is AutoCompleteSearchSuggestion && it.isUrl }) {
pixel.fire(AppPixelName.AUTOCOMPLETE_DISPLAYED_LOCAL_WEBSITE)
}
if (suggestions.any { it is AutoCompleteSwitchToTabSuggestion }) {
pixel.fire(AppPixelName.AUTOCOMPLETE_DISPLAYED_LOCAL_SWITCH_TO_TAB)
}
}
lastAutoCompleteState = null
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
AUTOCOMPLETE_HISTORY_SEARCH_SELECTION("m_autocomplete_click_history_search"),
AUTOCOMPLETE_HISTORY_SITE_SELECTION("m_autocomplete_click_history_site"),

AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION("m_autocomplete_click_switch_to_tab"),

AUTOCOMPLETE_TOGGLED_OFF("m_autocomplete_recent_sites_toggled_off"),
AUTOCOMPLETE_TOGGLED_ON("m_autocomplete_recent_sites_toggled_on"),

Expand All @@ -216,6 +218,7 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
AUTOCOMPLETE_DISPLAYED_LOCAL_WEBSITE("m_autocomplete_displayed_website"),
AUTOCOMPLETE_DISPLAYED_LOCAL_HISTORY("m_autocomplete_displayed_history_site"),
AUTOCOMPLETE_DISPLAYED_LOCAL_HISTORY_SEARCH("m_autocomplete_displayed_history_search"),
AUTOCOMPLETE_DISPLAYED_LOCAL_SWITCH_TO_TAB("m_autocomplete_displayed_switch_to_tab"),

AUTOCOMPLETE_RESULT_DELETED("m_autocomplete_result_deleted"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ interface Pixel {
const val BOOKMARK_CAPABLE = "bc"
const val FAVORITE_CAPABLE = "fc"
const val HISTORY_CAPABLE = "hc"
const val SWITCH_TO_TAB_CAPABLE = "switch_to_tab_capable"
const val SHOWED_BOOKMARKS = "sb"
const val SHOWED_FAVORITES = "sf"
const val SHOWED_HISTORY = "sh"
const val SHOWED_SWITCH_TO_TAB = "showed_switch_to_tab"
const val DEFAULT_BROWSER_BEHAVIOUR_TRIGGERED = "bt"
const val DEFAULT_BROWSER_SET_FROM_ONBOARDING = "fo"
const val DEFAULT_BROWSER_SET_ORIGIN = "dbo"
Expand Down

0 comments on commit 2491fda

Please sign in to comment.