Skip to content

Commit

Permalink
Add autocomplete deletion daily pixel (#5078)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1208403817322208/f

### Description
- Adds an `AUTOCOMPLETE_RESULT_DELETED_DAILY` pixel that's fired once
per day when an autocomplete result is deleted.
- This is fired from both the browser tab and system search.

### Steps to test this PR

_Browser tab_
- [ ] Fresh install
- [ ] Search for something
- [ ] Long press and delete the search suggestion
- [ ] Verify that the `m_autocomplete_result_deleted_daily` pixel is
fired
- [ ] Search for something
- [ ] Long press and delete the search suggestion
- [ ] Verify that the `m_autocomplete_result_deleted_daily` pixel is not
fired

_System search_
- [ ] Fresh install
- [ ] Add the search widget
- [ ] Search for something
- [ ] Long press and delete the search suggestion after tapping the
widget
- [ ] Verify that the `m_autocomplete_result_deleted_daily` pixel is
fired
- [ ] Search for something
- [ ] Long press and delete the search suggestion after tapping the
widget
- [ ] Verify that the `m_autocomplete_result_deleted_daily` pixel is not
fired
  • Loading branch information
joshliebe authored Sep 27, 2024
1 parent 165b202 commit 93fe833
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5783,7 +5783,7 @@ class BrowserTabViewModelTest {
}

@Test
fun whenOnRemoveSearchSuggestionConfirmedForHistorySuggestionThenPixelFiredAndHistoryEntryRemoved() = runBlocking {
fun whenOnRemoveSearchSuggestionConfirmedForHistorySuggestionThenPixelsFiredAndHistoryEntryRemoved() = runBlocking {
val suggestion = AutoCompleteHistorySuggestion(phrase = "phrase", title = "title", url = "url", isAllowedInTopHits = false)
val omnibarText = "foo"

Expand All @@ -5793,13 +5793,14 @@ class BrowserTabViewModelTest {
testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED)
verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())
verify(mockNavigationHistory).removeHistoryEntryByUrl(suggestion.url)
testObserver.assertValue(omnibarText)
assertCommandIssued<Command.AutocompleteItemRemoved>()
}

@Test
fun whenOnRemoveSearchSuggestionConfirmedForHistorySearchSuggestionThenPixelFiredAndHistoryEntryRemoved() = runBlocking {
fun whenOnRemoveSearchSuggestionConfirmedForHistorySearchSuggestionThenPixelsFiredAndHistoryEntryRemoved() = runBlocking {
val suggestion = AutoCompleteHistorySearchSuggestion(phrase = "phrase", isAllowedInTopHits = false)
val omnibarText = "foo"

Expand All @@ -5809,6 +5810,7 @@ class BrowserTabViewModelTest {
testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED)
verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())
verify(mockNavigationHistory).removeHistoryEntryByQuery(suggestion.phrase)
testObserver.assertValue(omnibarText)
assertCommandIssued<Command.AutocompleteItemRemoved>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_BANNER_SHOWN
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_HISTORY_SEARCH_SELECTION
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_HISTORY_SITE_SELECTION
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_RESULT_DELETED
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_RESULT_DELETED_DAILY
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_SEARCH_PHRASE_SELECTION
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION
import com.duckduckgo.app.pixels.AppPixelName.ONBOARDING_SEARCH_CUSTOM
Expand Down Expand Up @@ -899,6 +900,8 @@ class BrowserTabViewModel @Inject constructor(
fun onRemoveSearchSuggestionConfirmed(suggestion: AutoCompleteSuggestion, omnibarText: String) {
appCoroutineScope.launch(dispatchers.io()) {
pixel.fire(AUTOCOMPLETE_RESULT_DELETED)
pixel.fire(AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())

when (suggestion) {
is AutoCompleteHistorySuggestion -> {
history.removeHistoryEntryByUrl(suggestion.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
AUTOCOMPLETE_DISPLAYED_LOCAL_HISTORY_SEARCH("m_autocomplete_displayed_history_search"),

AUTOCOMPLETE_RESULT_DELETED("m_autocomplete_result_deleted"),
AUTOCOMPLETE_RESULT_DELETED_DAILY("m_autocomplete_result_deleted_daily"),

SERP_REQUERY("rq_%s"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class SystemSearchViewModel @Inject constructor(
fun onRemoveSearchSuggestionConfirmed(suggestion: AutoCompleteSuggestion, omnibarText: String) {
appCoroutineScope.launch(dispatchers.io()) {
pixel.fire(AUTOCOMPLETE_RESULT_DELETED)
pixel.fire(AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())

when (suggestion) {
is AutoCompleteHistorySuggestion -> {
history.removeHistoryEntryByUrl(suggestion.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.duckduckgo.app.onboarding.store.*
import com.duckduckgo.app.pixels.AppPixelName.*
import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Daily
import com.duckduckgo.app.systemsearch.SystemSearchViewModel.Command
import com.duckduckgo.app.systemsearch.SystemSearchViewModel.Command.AutocompleteItemRemoved
import com.duckduckgo.app.systemsearch.SystemSearchViewModel.Command.LaunchDuckDuckGo
Expand Down Expand Up @@ -510,7 +511,7 @@ class SystemSearchViewModelTest {
}

@Test
fun whenOnRemoveSearchSuggestionConfirmedForHistorySuggestionThenPixelFiredAndHistoryEntryRemoved() = runBlocking {
fun whenOnRemoveSearchSuggestionConfirmedForHistorySuggestionThenPixelsFiredAndHistoryEntryRemoved() = runBlocking {
val suggestion = AutoCompleteHistorySuggestion(phrase = "phrase", title = "title", url = "url", isAllowedInTopHits = false)
val omnibarText = "foo"

Expand All @@ -520,13 +521,14 @@ class SystemSearchViewModelTest {
testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AUTOCOMPLETE_RESULT_DELETED)
verify(mockPixel).fire(AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())
verify(mockHistory).removeHistoryEntryByUrl(suggestion.url)
testObserver.assertValue(omnibarText)
assertCommandIssued<AutocompleteItemRemoved>()
}

@Test
fun whenOnRemoveSearchSuggestionConfirmedForHistorySearchSuggestionThenPixelFiredAndHistoryEntryRemoved() = runBlocking {
fun whenOnRemoveSearchSuggestionConfirmedForHistorySearchSuggestionThenPixelsFiredAndHistoryEntryRemoved() = runBlocking {
val suggestion = AutoCompleteHistorySearchSuggestion(phrase = "phrase", isAllowedInTopHits = false)
val omnibarText = "foo"

Expand All @@ -536,6 +538,7 @@ class SystemSearchViewModelTest {
testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AUTOCOMPLETE_RESULT_DELETED)
verify(mockPixel).fire(AUTOCOMPLETE_RESULT_DELETED_DAILY, type = Daily())
verify(mockHistory).removeHistoryEntryByQuery(suggestion.phrase)
testObserver.assertValue(omnibarText)
assertCommandIssued<AutocompleteItemRemoved>()
Expand Down

0 comments on commit 93fe833

Please sign in to comment.