Skip to content

Commit

Permalink
Omnibar position: Pixels (#4974)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1207418217763355/1208145303592222/f

### Description

This PR implements a new plugin that allows the
`m_browser_feature_daily_active_user_d` pixel to collect additional
parameters from different parts of the app. This is used to report the
omnibar position.

### Steps to test this PR

_Omnibar position selection_
- [x] Go to Settings -> Appearance
- [x] Tap on the Address bar option
- [x] Verify that `ms_address_bar_position_setting_pressed` pixel is
fired
- [x] Select the Top option
- [x] Verify that `ms_address_bar_position_setting_selected_top` pixel
is fired
- [x] Tap on the address bar again
- [x] Select the Bottom option
- [x] Verify that `ms_address_bar_position_setting_selected_bottom`
pixel is fired

_Omnibar position detection_
- [x] Uninstall the app, if already installed
- [x] Run the app
- [x] Verify that`m_browser_feature_daily_active_user_d` pixel is fired
with params: `{default_browser=0, email=0, voice_search=0,
address_bar=[[CURRENT OMNIBAR POSITION]], locale=en-US}` with the
correct position
  • Loading branch information
0nko committed Sep 23, 2024
1 parent ccfd313 commit 9e63edb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class AppearanceViewModel @Inject constructor(
viewModelScope.launch(dispatcherProvider.io()) {
settingsDataStore.omnibarPosition = position
viewState.update { currentViewState().copy(omnibarPosition = position) }

when (position) {
OmnibarPosition.TOP -> pixel.fire(AppPixelName.SETTINGS_ADDRESS_BAR_POSITION_SELECTED_TOP)
OmnibarPosition.BOTTOM -> pixel.fire(AppPixelName.SETTINGS_ADDRESS_BAR_POSITION_SELECTED_BOTTOM)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.browser.omnibar

import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.app.statistics.api.BrowserFeatureStateReporterPlugin
import com.duckduckgo.app.statistics.pixels.Pixel.PixelParameter
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.SingleInstanceIn
import javax.inject.Inject

interface OmnibarPositionReporterPlugin

@ContributesMultibinding(scope = AppScope::class, boundType = BrowserFeatureStateReporterPlugin::class)
@ContributesBinding(scope = AppScope::class, boundType = OmnibarPositionReporterPlugin::class)
@SingleInstanceIn(AppScope::class)
class OmnibarPositionDetector @Inject constructor(
private val settingsDataStore: SettingsDataStore,
) : OmnibarPositionReporterPlugin, BrowserFeatureStateReporterPlugin {
override fun featureStateParams(): Map<String, String> {
return mapOf(PixelParameter.ADDRESS_BAR to settingsDataStore.omnibarPosition.name)
}
}
2 changes: 2 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 @@ -124,6 +124,8 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
SETTINGS_APPEARANCE_PRESSED("ms_appearance_setting_pressed"),
SETTINGS_APP_ICON_PRESSED("ms_app_icon_setting_pressed"),
SETTINGS_ADDRESS_BAR_POSITION_PRESSED("ms_address_bar_position_setting_pressed"),
SETTINGS_ADDRESS_BAR_POSITION_SELECTED_TOP("ms_address_bar_position_setting_selected_top"),
SETTINGS_ADDRESS_BAR_POSITION_SELECTED_BOTTOM("ms_address_bar_position_setting_selected_bottom"),
SETTINGS_MAC_APP_PRESSED("ms_mac_app_setting_pressed"),
SETTINGS_WINDOWS_APP_PRESSED("ms_windows_app_setting_pressed"),
SETTINGS_EMAIL_PROTECTION_PRESSED("ms_email_protection_setting_pressed"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,27 @@ internal class AppearanceViewModelTest {
verify(mockPixel).fire(AppPixelName.FORCE_DARK_MODE_DISABLED)
}

@Test
fun whenOmnibarPositionSettingPressed() = runTest {
testee.commands().test {
testee.userRequestedToChangeAddressBarPosition()
assertEquals(Command.LaunchOmnibarPositionSettings(TOP), awaitItem())
verify(mockPixel).fire(AppPixelName.SETTINGS_ADDRESS_BAR_POSITION_PRESSED)
}
}

@Test
fun whenOmnibarPositionUpdatedToBottom() = runTest {
testee.onOmnibarPositionUpdated(BOTTOM)
verify(mockAppSettingsDataStore).omnibarPosition = BOTTOM
verify(mockPixel).fire(AppPixelName.SETTINGS_ADDRESS_BAR_POSITION_SELECTED_BOTTOM)
}

@Test
fun whenOmnibarPositionUpdatedToTop() = runTest {
testee.onOmnibarPositionUpdated(TOP)
verify(mockAppSettingsDataStore).omnibarPosition = TOP
verify(mockPixel).fire(AppPixelName.SETTINGS_ADDRESS_BAR_POSITION_SELECTED_TOP)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface Pixel {
const val VOICE_SEARCH = "voice_search"
const val LOCALE = "locale"
const val FROM_ONBOARDING = "from_onboarding"
const val ADDRESS_BAR = "address_bar"

// Loading Bar Experiment
const val LOADING_BAR_EXPERIMENT = "loading_bar_exp"
Expand Down

0 comments on commit 9e63edb

Please sign in to comment.