For #25401 - Record Pocket sponsored stories telemetry

pull/543/head
Mugurell 2 years ago committed by mergify[bot]
parent feae3344de
commit d4dd62341a

@ -1623,6 +1623,25 @@ customize_home:
notification_emails:
- android-probes@mozilla.com
expires: 105
sponsored_pocket:
type: boolean
description: |
An indication of whether Pocket sponsored stories are enabled
to be displayed
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/25401
data_reviews:
- ???
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: 105
metadata:
tags:
- PocketIntegration
contile:
type: boolean
description: |
@ -5394,6 +5413,59 @@ pocket:
notification_emails:
- android-probes@mozilla.com
expires: 106
home_recs_spoc_clicked:
type: event
description: |
User tapped a Pocket sponsored story to be opened.
extra_keys:
times_shown:
type: string
description: |
How many times was this story shown, including current.
position:
type: string
description: |
Position of the clicked story in the list shown.
Uses the [row x column] matrix notation.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/25401
data_reviews:
- ?????
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: 106
metadata:
tags:
- PocketIntegration
home_recs_spoc_shown:
type: event
description: |
A particular Pocket sponsored story was visible more than 50%
on the homescreen.
extra_keys:
times_shown:
type: string
description: |
How many times was this story shown, including current.
position:
type: string
description: |
Position of the story in the list shown.
Uses the [row x column] matrix notation.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/25401
data_reviews:
- ???
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: 106
metadata:
tags:
- PocketIntegration
home_recs_category_clicked:
type: event
description: |

@ -795,6 +795,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
CustomizeHome.mostVisitedSites.set(settings.showTopSitesFeature)
CustomizeHome.recentlyVisited.set(settings.historyMetadataUIFeature)
CustomizeHome.pocket.set(settings.showPocketRecommendationsFeature)
CustomizeHome.sponsoredPocket.set(settings.showPocketSponsoredStories)
CustomizeHome.contile.set(settings.showContileFeature)
}

@ -214,6 +214,7 @@ fun PocketSponsoredStory(
* @param stories The list of [PocketStory]ies to be displayed. Expect a list with 8 items.
* @param contentPadding Dimension for padding the content after it has been clipped.
* This space will be used for shadows and also content rendering when the list is scrolled.
* @param onStoryShown Callback for when a certain story is visible to the user.
* @param onStoryClicked Callback for when the user taps on a recommended story.
* @param onDiscoverMoreClicked Callback for when the user taps an element which contains an
*/
@ -221,7 +222,7 @@ fun PocketSponsoredStory(
fun PocketStories(
@PreviewParameter(PocketStoryProvider::class) stories: List<PocketStory>,
contentPadding: Dp,
onStoryShown: (PocketStory) -> Unit,
onStoryShown: (PocketStory, Pair<Int, Int>) -> Unit,
onStoryClicked: (PocketStory, Pair<Int, Int>) -> Unit,
onDiscoverMoreClicked: (String) -> Unit
) {
@ -256,7 +257,7 @@ fun PocketStories(
} else if (story is PocketSponsoredStory) {
Box(
modifier = Modifier.onShown(0.5f) {
onStoryShown(story)
onStoryShown(story, rowIndex to columnIndex)
}
) {
PocketSponsoredStory(story) {
@ -340,8 +341,7 @@ private fun LayoutCoordinates.isVisible(
/**
* Returns the ratio of how much this intersects with [other].
*
* @param realSize [IntSize] containing the height and with of the composable.
* (The Rect may have a smaller height / width accounting for just what is visible)
* @param realSize [IntSize] containing the true height and width of the composable.
* @param other Other [Rect] for whcih to check the intersection area.
*
* @return A `0..1` float range for how much this [Rect] intersects with other.
@ -452,7 +452,7 @@ private fun PocketStoriesComposablesPreview() {
PocketStories(
stories = getFakePocketStories(8),
contentPadding = 0.dp,
onStoryShown = {},
onStoryShown = { _, _ -> },
onStoryClicked = { _, _ -> },
onDiscoverMoreClicked = {}
)

@ -9,6 +9,8 @@ import androidx.navigation.NavController
import mozilla.components.service.glean.private.NoExtras
import mozilla.components.service.pocket.PocketStory
import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import mozilla.components.service.pocket.PocketStory.PocketSponsoredStory
import mozilla.components.service.pocket.ext.getCurrentFlightImpressions
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.GleanMetrics.Pocket
import org.mozilla.fenix.HomeActivity
@ -22,8 +24,11 @@ import org.mozilla.fenix.components.appstate.AppAction
interface PocketStoriesController {
/**
* Callback to decide what should happen as an effect of a specific story being shown.
*
* @param storyShown The just shown [PocketStory].
* @param storyPosition `row x column` matrix representing the grid position of the shown story.
*/
fun handleStoryShown(storyShown: PocketStory)
fun handleStoryShown(storyShown: PocketStory, storyPosition: Pair<Int, Int>)
/**
* Callback to decide what should happen as an effect of a new list of stories being shown.
@ -74,8 +79,26 @@ internal class DefaultPocketStoriesController(
private val appStore: AppStore,
private val navController: NavController,
) : PocketStoriesController {
override fun handleStoryShown(storyShown: PocketStory) {
override fun handleStoryShown(
storyShown: PocketStory,
storyPosition: Pair<Int, Int>
) {
appStore.dispatch(AppAction.PocketStoriesShown(listOf(storyShown)))
when (storyShown) {
is PocketSponsoredStory -> {
Pocket.homeRecsSpocShown.record(
Pocket.HomeRecsSpocShownExtra(
position = "${storyPosition.first}x${storyPosition.second}",
timesShown = storyShown.getCurrentFlightImpressions().size.inc().toString()
)
)
}
else -> {
// no-op
// The telemetry for PocketRecommendedStory is sent separately for bulk updates.
}
}
}
override fun handleStoriesShown(storiesShown: List<PocketStory>) {
@ -129,13 +152,24 @@ internal class DefaultPocketStoriesController(
) {
dismissSearchDialogIfDisplayed()
homeActivity.openToBrowserAndLoad(storyClicked.url, true, BrowserDirection.FromHome)
if (storyClicked is PocketRecommendedStory) {
Pocket.homeRecsStoryClicked.record(
Pocket.HomeRecsStoryClickedExtra(
position = "${storyPosition.first}x${storyPosition.second}",
timesShown = storyClicked.timesShown.inc().toString()
when (storyClicked) {
is PocketRecommendedStory -> {
Pocket.homeRecsStoryClicked.record(
Pocket.HomeRecsStoryClickedExtra(
position = "${storyPosition.first}x${storyPosition.second}",
timesShown = storyClicked.timesShown.inc().toString()
)
)
)
}
is PocketSponsoredStory -> {
Pocket.homeRecsSpocClicked.record(
Pocket.HomeRecsSpocClickedExtra(
position = "${storyPosition.first}x${storyPosition.second}",
timesShown = storyClicked.getCurrentFlightImpressions().size.inc().toString()
)
)
}
}
}

@ -15,8 +15,9 @@ interface PocketStoriesInteractor {
* Callback for when a certain story is shown to the user.
*
* @param storyShown The story shown to the user.
* @param storyPosition `row x column` matrix representing the grid position of the shown story.
*/
fun onStoryShown(storyShown: PocketStory)
fun onStoryShown(storyShown: PocketStory, storyPosition: Pair<Int, Int>)
/**
* Callback for then new stories are shown to the user.

@ -119,7 +119,7 @@ fun PocketStoriesViewHolderPreview() {
PocketStories(
stories = getFakePocketStories(8),
contentPadding = 0.dp,
onStoryShown = {},
onStoryShown = { _, _ -> },
onStoryClicked = { _, _ -> },
onDiscoverMoreClicked = {}
)

@ -430,8 +430,8 @@ class SessionControlInteractor(
controller.handleCustomizeHomeTapped()
}
override fun onStoryShown(storyShown: PocketStory) {
pocketStoriesController.handleStoryShown(storyShown)
override fun onStoryShown(storyShown: PocketStory, storyPosition: Pair<Int, Int>) {
pocketStoriesController.handleStoryShown(storyShown, storyPosition)
}
override fun onStoriesShown(storiesShown: List<PocketStory>) {

Loading…
Cancel
Save