Skip to content

Commit

Permalink
Adding DuckPlayer Telemetry events (#5201)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208637207606569/f

### Description

The DuckPlayer frontend will send an event when the landscape view is
shown, this PR adds a pixel for it.

- Fire `duckplayer_landscape_layout_impressions` when the FE sends a
telemetry event
(https://app.asana.com/0/69071770703008/1208686513106880/f)
- iOS PR: duckduckgo/iOS#3493

### Steps to test this PR

- ~install CSS at branch pr-releases/pr-1164~
- load DuckPlayer in landscape (or rotate)
- you should receive 1 event per page-load, and the pixel should fire.

### UI changes
| Before  | After |
| ------ | ----- |
!(Upload before screenshot)|(Upload after screenshot)|

---------

Co-authored-by: Shane Osbourne <sosbourne@duckduckgo.com>
Co-authored-by: Cris Barreiro <cbarreiro@duckduckgo.com>
  • Loading branch information
3 people authored and aitorvs committed Nov 6, 2024
1 parent 2a5dddd commit ccf6605
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 @@ -152,6 +152,7 @@ import com.duckduckgo.app.onboarding.ui.page.extendedonboarding.ExtendedOnboardi
import com.duckduckgo.app.onboarding.ui.page.extendedonboarding.HighlightsOnboardingExperimentManager
import com.duckduckgo.app.pixels.AppPixelName
import com.duckduckgo.app.pixels.AppPixelName.AUTOCOMPLETE_BANNER_SHOWN
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_LANDSCAPE_LAYOUT_IMPRESSIONS
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_DUCK_PLAYER
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_OVERLAY_YOUTUBE
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_NEVER_OVERLAY_YOUTUBE
Expand Down Expand Up @@ -5196,6 +5197,21 @@ class BrowserTabViewModelTest {
assertCommandNotIssued<Navigate>()
}

@Test
fun whenProcessJsCallbackMessageTelemetryEventThenFirePixel() = runTest {
whenever(mockEnabledToggle.isEnabled()).thenReturn(true)
whenever(mockDuckPlayer.getUserPreferences()).thenReturn(UserPreferences(overlayInteracted = true, privatePlayerMode = AlwaysAsk))
testee.processJsCallbackMessage(
DUCK_PLAYER_PAGE_FEATURE_NAME,
"telemetryEvent",
"id",
JSONObject("""{"attributes": {"name": "impression", "value": "landscape-layout"}}"""),
false,
{ "someUrl" },
)
verify(mockPixel).fire(DUCK_PLAYER_LANDSCAPE_LAYOUT_IMPRESSIONS)
}

@Test
fun whenJsCallbackMessageInitialSetupFromOverlayThenSendResponseToJs() = runTest {
whenever(mockEnabledToggle.isEnabled()).thenReturn(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.duckduckgo.app.browser.commands.Command.SendResponseToDuckPlayer
import com.duckduckgo.app.browser.commands.Command.SendResponseToJs
import com.duckduckgo.app.browser.commands.Command.SendSubscriptions
import com.duckduckgo.app.browser.commands.NavigationCommand.Navigate
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_LANDSCAPE_LAYOUT_IMPRESSIONS
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_DUCK_PLAYER
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_OVERLAY_YOUTUBE
import com.duckduckgo.app.pixels.AppPixelName.DUCK_PLAYER_SETTING_ALWAYS_SERP
Expand Down Expand Up @@ -239,6 +240,33 @@ class DuckPlayerJSHelper @Inject constructor(
"reportPageException", "reportInitException" -> {
Timber.tag(method).d(data.toString())
}
"telemetryEvent" -> {
val attributes = data?.getJSONObject("attributes")

if (attributes?.getString("name") == "impression" && attributes.getString("value") == "landscape-layout") {
pixel.fire(DUCK_PLAYER_LANDSCAPE_LAYOUT_IMPRESSIONS)
}

// TODO (cbarreiro) Abstract this to provide better support for telemetry events
/**
* incoming data looks like this, where `name` is used to discriminate,
* and 'value' is linked to it (but is optional)
*
* {
* "attributes": {
* "name": "impression",
* "value": "landscape-layout"
* }
* }
*
* Another event might look like this in the future: (note: no 'value' field)
* {
* "attributes": {
* "name": "page-view"
* }
* }
*/
}
"openSettings" -> {
return OpenDuckPlayerSettings
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
DUCK_PLAYER_SETTING_NEVER_SERP("duckplayer_setting_never_overlay_serp"),
DUCK_PLAYER_SETTING_NEVER_OVERLAY_YOUTUBE("duckplayer_setting_never_overlay_youtube"),
DUCK_PLAYER_SETTING_ALWAYS_DUCK_PLAYER("duckplayer_setting_always_duck-player"),
DUCK_PLAYER_LANDSCAPE_LAYOUT_IMPRESSIONS("duckplayer_landscape_layout_impressions"),

ADD_BOOKMARK_CONFIRM_EDITED("m_add_bookmark_confirm_edit"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class DuckPlayerScriptsJsMessaging @Inject constructor(
"setUserValues",
"reportPageException",
"reportInitException",
"telemetryEvent",
)
}
}

0 comments on commit ccf6605

Please sign in to comment.