Skip to content

Commit

Permalink
Add pixels for open in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Oct 14, 2024
1 parent 8ca66e6 commit c0c88b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ enum class DuckPlayerPixelName(override val pixelName: String) : Pixel.PixelName
DUCK_PLAYER_SETTINGS_BACK_TO_DEFAULT("duckplayer_setting_back-to-default"),
DUCK_PLAYER_SETTINGS_NEVER_SETTINGS("duckplayer_setting_never_settings"),
DUCK_PLAYER_SETTINGS_PRESSED("duckplayer_setting_pressed"),
DUCK_PLAYER_NEWTAB_SETTING_ON("duckplayer_newtab_setting-on"),
DUCK_PLAYER_NEWTAB_SETTING_OFF("duckplayer_newtab_setting-off"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled
import com.duckduckgo.duckplayer.api.YOUTUBE_HOST
import com.duckduckgo.duckplayer.api.YOUTUBE_MOBILE_HOST
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_DAILY_UNIQUE_VIEW
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_NEWTAB_SETTING_OFF
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_NEWTAB_SETTING_ON
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_VIEW_FROM_OTHER
Expand Down Expand Up @@ -188,6 +190,11 @@ class RealDuckPlayer @Inject constructor(

override fun setOpenInNewTab(enabled: Boolean) {
duckPlayerFeatureRepository.setOpenInNewTab(enabled)
if (enabled) {
pixel.fire(DUCK_PLAYER_NEWTAB_SETTING_ON)
} else {
pixel.fire(DUCK_PLAYER_NEWTAB_SETTING_OFF)
}
}

private suspend fun createYoutubeNoCookieFromDuckPlayer(uri: Uri): String? {
Expand Down Expand Up @@ -312,13 +319,18 @@ class RealDuckPlayer @Inject constructor(
}
} else {
val inputStream: InputStream = webView.context.assets.open(DUCK_PLAYER_ASSETS_INDEX_PATH)
val openInNewTab = shouldOpenDuckPlayerInNewTab() is On
return WebResourceResponse("text/html", "UTF-8", inputStream).also {
when (getUserPreferences().privatePlayerMode) {
Enabled -> "always"
AlwaysAsk -> "default"
else -> null
}?.let { setting ->
pixel.fire(DUCK_PLAYER_DAILY_UNIQUE_VIEW, type = Daily(), parameters = mapOf("setting" to setting))
pixel.fire(
DUCK_PLAYER_DAILY_UNIQUE_VIEW,
type = Daily(),
parameters = mapOf("setting" to setting, "newtab" to openInNewTab.toString()),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,11 @@ class RealDuckPlayerTest {
val result = testee.intercept(request, url, webView)

verify(mockAssets).open("duckplayer/index.html")
verify(mockPixel).fire(DUCK_PLAYER_DAILY_UNIQUE_VIEW, type = Daily(), parameters = mapOf("setting" to "always"))
verify(mockPixel).fire(
DUCK_PLAYER_DAILY_UNIQUE_VIEW,
type = Daily(),
parameters = mapOf("setting" to "always", "newtab" to "false"),
)
assertEquals("text/html", result?.mimeType)
}

Expand Down

0 comments on commit c0c88b1

Please sign in to comment.