Skip to content

Add new thumnbail pixels and unique variant for Duck Player pixels #5803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import com.duckduckgo.app.statistics.pixels.Pixel

enum class DuckPlayerPixelName(override val pixelName: String) : Pixel.PixelName {
DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS("duckplayer_overlay_youtube_impressions"),
DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE("duckplayer_overlay_youtube_impressions_unique"),
DUCK_PLAYER_VIEW_FROM_YOUTUBE_MAIN_OVERLAY("duckplayer_view-from_youtube_main-overlay"),
DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE("duckplayer_overlay_youtube_watch_here"),
DUCK_PLAYER_OVERLAY_YOUTUBE_DISMISS("duckplayer_overlay_youtube_dismiss-play"),
DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE("duckplayer_overlay_youtube_choice_unique"),
DUCK_PLAYER_WATCH_ON_YOUTUBE("duckplayer_watch_on_youtube"),
DUCK_PLAYER_DAILY_UNIQUE_VIEW("duckplayer_daily-unique-view"),
DUCK_PLAYER_VIEW_FROM_YOUTUBE_AUTOMATIC("duckplayer_view-from_youtube_automatic"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import androidx.fragment.app.FragmentManager
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.di.IsMainProcess
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Count
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Daily
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Unique
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.UrlScheme.Companion.duck
import com.duckduckgo.common.utils.UrlScheme.Companion.https
Expand All @@ -53,7 +56,10 @@ 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_CHOICE_UNIQUE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_DISMISS
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_VIEW_FROM_OTHER
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_VIEW_FROM_SERP
Expand All @@ -73,6 +79,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

private const val DUCK_PLAYER_VIDEO_ID_QUERY_PARAM = "videoID"
const val DUCK_PLAYER_OPEN_IN_YOUTUBE_PATH = "openInYoutube"
Expand Down Expand Up @@ -184,15 +191,46 @@ class RealDuckPlayer @Inject constructor(
pixelData: Map<String, String>,
) {
if (!isFeatureEnabled) return
val duckPlayerPixelName = when (pixelName) {
"overlay" -> DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS
"play.use" -> DUCK_PLAYER_VIEW_FROM_YOUTUBE_MAIN_OVERLAY
"play.do_not_use" -> DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE
else -> { null }
val duckPlayerPixelNames: List<Pair<DuckPlayerPixelName, PixelType>>? = when (pixelName) {
"overlay" -> {
listOf(
DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS to Count,
DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE to Unique(),
)
}
"play.use" -> {
listOf(
DUCK_PLAYER_VIEW_FROM_YOUTUBE_MAIN_OVERLAY to Count,
DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE to Unique(),
)
}
"play.do_not_use" -> {
listOf(
DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE to Count,
DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE to Unique(),
)
}
"play.do_not_use.dismiss" -> {
listOf(
DUCK_PLAYER_OVERLAY_YOUTUBE_DISMISS to Count,
DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE to Unique(),
)
}
else -> {
Timber.d("Unknown duck player pixel: $pixelName, data: $pixelData")
null
}
}

duckPlayerPixelName?.let {
pixel.fire(duckPlayerPixelName, parameters = pixelData)
duckPlayerPixelNames?.forEach { (duckPlayerPixelName, type) ->
val dataToSend = when {
duckPlayerPixelName == DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE -> mapOf("choice" to pixelName.split(".").last())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do this, at this point, I'd rather either create a wrapper class with PixelName, Type, and params, or just fire the necessary pixels from each when branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this is a little confusing. Encapsulating each in their own class seems like a better approach.

type is Unique -> emptyMap()
else -> pixelData
}

pixel.fire(duckPlayerPixelName, dataToSend, type = type)

if (duckPlayerPixelName == DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS) {
duckPlayerFeatureRepository.setUserOnboarded()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Count
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Daily
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Unique
import com.duckduckgo.common.utils.UrlScheme.Companion.duck
import com.duckduckgo.common.utils.UrlScheme.Companion.https
import com.duckduckgo.duckplayer.api.DuckPlayer.DuckPlayerOrigin.AUTO
Expand All @@ -40,7 +41,10 @@ import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Enabled
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_CHOICE_UNIQUE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_DISMISS
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_VIEW_FROM_OTHER
import com.duckduckgo.duckplayer.impl.DuckPlayerPixelName.DUCK_PLAYER_VIEW_FROM_YOUTUBE_AUTOMATIC
Expand Down Expand Up @@ -244,6 +248,7 @@ class RealDuckPlayerTest {
testee.sendDuckPlayerPixel(pixelName, pixelData)

verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS, pixelData, emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE, emptyMap(), emptyMap(), Unique())
}

@Test
Expand All @@ -253,44 +258,64 @@ class RealDuckPlayerTest {
testee.sendDuckPlayerPixel(pixelName, emptyMap())

verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS, emptyMap(), emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_IMPRESSIONS_UNIQUE, emptyMap(), emptyMap(), Unique())
}

@Test
fun sendDuckPlayerPixelWithPlayUse_firesPixelWithCorrectNameAndData() = runTest {
val pixelName = "play.use"
val pixelData = mapOf("key" to "value")
val uniquePixelData = mapOf("choice" to "use")

testee.sendDuckPlayerPixel(pixelName, pixelData)

verify(mockPixel).fire(DUCK_PLAYER_VIEW_FROM_YOUTUBE_MAIN_OVERLAY, pixelData, emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE, uniquePixelData, emptyMap(), Unique())
}

@Test
fun sendDuckPlayerPixelWithPlayUse_firesPixelWithEmptyDataWhenNoDataProvided() = runTest {
val pixelName = "play.use"
val uniquePixelData = mapOf("choice" to "use")

testee.sendDuckPlayerPixel(pixelName, emptyMap())

verify(mockPixel).fire(DUCK_PLAYER_VIEW_FROM_YOUTUBE_MAIN_OVERLAY, emptyMap(), emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE, uniquePixelData, emptyMap(), Unique())
}

@Test
fun sendDuckPlayerPixelWithPlayDoNotUse_firesPixelWithCorrectNameAndData() = runTest {
val pixelName = "play.do_not_use"
val pixelData = mapOf("key" to "value")
val uniquePixelData = mapOf("choice" to "do_not_use")

testee.sendDuckPlayerPixel(pixelName, pixelData)

verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE, pixelData, emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE, uniquePixelData, emptyMap(), Unique())
}

@Test
fun sendDuckPlayerPixelWithPlayDoNotUse_firesPixelWithEmptyDataWhenNoDataProvided() = runTest {
val pixelName = "play.do_not_use"
val uniquePixelData = mapOf("choice" to "do_not_use")

testee.sendDuckPlayerPixel(pixelName, emptyMap())

verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_WATCH_HERE, emptyMap(), emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE, uniquePixelData, emptyMap(), Unique())
}

@Test
fun sendDuckPlayerPixelWithPlayDoNotUseDismiss_firesPixelWithEmptyDataWhenNoDataProvided() = runTest {
val pixelName = "play.do_not_use.dismiss"
val uniquePixelData = mapOf("choice" to "dismiss")

testee.sendDuckPlayerPixel(pixelName, emptyMap())

verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_DISMISS, emptyMap(), emptyMap(), Count)
verify(mockPixel).fire(DUCK_PLAYER_OVERLAY_YOUTUBE_CHOICE_UNIQUE, uniquePixelData, emptyMap(), Unique())
}

// endregion
Expand Down
Loading