Skip to content

Commit 5dca388

Browse files
linabutlermergify[bot]
authored andcommitted
Bug 1871156 - Report impressions and clicks for Firefox Suggestions in the events ping.
Fenix currently reports AMP and Wikipedia impressions and clicks in the `fx-suggest` ping, which intentionally omits the `client_id`. This complicates experiment analysis, because our tooling relies on the `client_id`. This commit adds separate events for impressions and clicks on sponsored and non-sponsored suggestions to the `events` ping. * The new `awesomebar.{non_}sponsored_suggestion_clicked` events are collected the same way as the existing `fx-suggest` ping, and in line with the other `awesomebar.*_suggestion_clicked` events. * The new `awesomebar.{non_}sponsored_suggestion_impressed` events are collected for engaged and abandoned search sessions. In constrast, the `fx-suggest` ping is only sent for engaged search sessions.
1 parent 2f6f862 commit 5dca388

7 files changed

Lines changed: 376 additions & 51 deletions

File tree

android-components/components/feature/fxsuggest/README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ implementation "org.mozilla.components:feature-fxsuggest:{latest-version}"
1818

1919
This component emits the following [Facts](../../support/base/README.md#Facts):
2020

21-
| Action | Item | Extras | Description |
22-
|---------------|----------------------------------|-------------------------------|-----------------------------------------------------------------------------------------------------|
23-
| `INTERACTION` | `amp_suggestion_clicked` | `suggestion_clicked_extras` | The user clicked on a Firefox Suggestion from adMarketplace. |
24-
| `DISPLAY` | `amp_suggestion_impressed` | `suggestion_impressed_extras` | The user saw a Firefox Suggestion from adMarketplace just before they navigated to a destination. |
25-
| `INTERACTION` | `wikipedia_suggestion_clicked` | `suggestion_clicked_extras` | The user clicked on a Firefox Suggestion for a Wikipedia page. |
26-
| `DISPLAY` | `wikipedia_suggestion_impressed` | `suggestion_impressed_extras` | The user saw a Firefox Suggestion for a Wikipedia page just before they navigated to a destination. |
21+
| Action | Item | Extras | Description |
22+
|---------------|----------------------------------|-------------------------------|---------------------------------------------------------------------------------------------------------------|
23+
| `INTERACTION` | `amp_suggestion_clicked` | `suggestion_clicked_extras` | The user clicked on a Firefox Suggestion from adMarketplace. |
24+
| `DISPLAY` | `amp_suggestion_impressed` | `suggestion_impressed_extras` | A Firefox Suggestion from adMarketplace was visible when the user finished interacting with the awesomebar. |
25+
| `INTERACTION` | `wikipedia_suggestion_clicked` | `suggestion_clicked_extras` | The user clicked on a Firefox Suggestion for a Wikipedia page. |
26+
| `DISPLAY` | `wikipedia_suggestion_impressed` | `suggestion_impressed_extras` | A Firefox Suggestion for a Wikipedia page was visible when the user finished interacting with the awesomebar. |
2727

2828
#### `suggestion_clicked_extras`
2929

@@ -35,11 +35,12 @@ This component emits the following [Facts](../../support/base/README.md#Facts):
3535

3636
#### `suggestion_impressed_extras`
3737

38-
| Key | Type | Value |
39-
|--------------------|----------------------------|------------------------------------------------------------|
40-
| `interaction_info` | `FxSuggestInteractionInfo` | Type-specific information to record for this suggestion. |
41-
| `position` | `Long` | The 1-based position of this suggestion in the awesomebar. |
42-
| `is_clicked` | `Boolean` | Whether the user clicked on this suggestion. |
38+
| Key | Type | Value |
39+
|------------------------|----------------------------|----------------------------------------------------------------------------------------------------------------|
40+
| `interaction_info` | `FxSuggestInteractionInfo` | Type-specific information to record for this suggestion. |
41+
| `position` | `Long` | The 1-based position of this suggestion in the awesomebar. |
42+
| `is_clicked` | `Boolean` | Whether the user clicked on this suggestion after it was shown. |
43+
| `engagement_abandoned` | `Boolean` | Whether the user dismissed the awesomebar without navigating to a destination after this suggestion was shown. |
4344

4445
## License
4546

android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/facts/FxSuggestFacts.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class FxSuggestFacts {
3131
const val INTERACTION_INFO = "interaction_info"
3232
const val POSITION = "position"
3333
const val IS_CLICKED = "is_clicked"
34+
const val ENGAGEMENT_ABANDONED = "engagement_abandoned"
3435
}
3536
}
3637

@@ -70,6 +71,7 @@ internal fun emitSuggestionImpressedFact(
7071
interactionInfo: FxSuggestInteractionInfo,
7172
positionInAwesomeBar: Long,
7273
isClicked: Boolean,
74+
engagementAbandoned: Boolean,
7375
) {
7476
emitFxSuggestFact(
7577
Action.DISPLAY,
@@ -81,6 +83,7 @@ internal fun emitSuggestionImpressedFact(
8183
FxSuggestFacts.MetadataKeys.INTERACTION_INFO to interactionInfo,
8284
FxSuggestFacts.MetadataKeys.POSITION to positionInAwesomeBar,
8385
FxSuggestFacts.MetadataKeys.IS_CLICKED to isClicked,
86+
FxSuggestFacts.MetadataKeys.ENGAGEMENT_ABANDONED to engagementAbandoned,
8487
),
8588
)
8689
}

android-components/components/feature/fxsuggest/src/main/java/mozilla/components/feature/fxsuggest/facts/FxSuggestFactsMiddleware.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import mozilla.components.support.base.facts.Fact
1919
* Reports [Fact]s for interactions with Firefox Suggest [AwesomeBar.Suggestion]s.
2020
*
2121
* We report two kinds of interactions: impressions and clicks. We report impressions for any Firefox Suggest
22-
* search suggestions that are still visible just before the user navigates to a destination: either a URL, a
23-
* search results page, or a suggestion. If the user navigates to one of those Firefox Suggest suggestions,
24-
* we also report a click.
22+
* search suggestions that are visible when the user finishes interacting with the [AwesomeBar].
23+
* If the user taps on one of those visible Firefox Suggest suggestions, we'll also report a click for that suggestion.
2524
*
26-
* We _don't_ report impressions for any suggestions that the user sees as they're still typing, or
27-
* if they dismiss the [AwesomeBar] without navigating to a destination.
25+
* Each impression's [Fact.metadata] contains a [FxSuggestFacts.MetadataKeys.ENGAGEMENT_ABANDONED] key, whose value is
26+
* `false` if the user navigated to a destination (like a URL, a search results page, or a suggestion), or
27+
* `true` if the user dismissed the [AwesomeBar] without navigating to a destination.
28+
*
29+
* We _don't_ report impressions for any suggestions that the user sees as they're still typing.
2830
*/
2931
class FxSuggestFactsMiddleware : Middleware<BrowserState, BrowserAction> {
3032
override fun invoke(
@@ -40,12 +42,14 @@ class FxSuggestFactsMiddleware : Middleware<BrowserState, BrowserAction> {
4042
context: MiddlewareContext<BrowserState, BrowserAction>,
4143
action: BrowserAction,
4244
) = when (action) {
43-
is AwesomeBarAction.EngagementFinished ->
44-
if (action.abandoned) Unit else emitSuggestionFacts(context.state.awesomeBarState)
45+
is AwesomeBarAction.EngagementFinished -> emitSuggestionFacts(
46+
awesomeBarState = context.state.awesomeBarState,
47+
engagementAbandoned = action.abandoned,
48+
)
4549
else -> Unit
4650
}
4751

48-
private fun emitSuggestionFacts(awesomeBarState: AwesomeBarState) {
52+
private fun emitSuggestionFacts(awesomeBarState: AwesomeBarState, engagementAbandoned: Boolean) {
4953
val visibilityState = awesomeBarState.visibilityState
5054
val clickedSuggestion = awesomeBarState.clickedSuggestion
5155
visibilityState.visibleProviderGroups.entries.forEachIndexed { groupIndex, (_, suggestions) ->
@@ -58,7 +62,12 @@ class FxSuggestFactsMiddleware : Middleware<BrowserState, BrowserAction> {
5862
FxSuggestSuggestionProvider.MetadataKeys.IMPRESSION_INFO,
5963
) as? FxSuggestInteractionInfo
6064
impressionInfo?.let {
61-
emitSuggestionImpressedFact(it, positionInGroup, isClicked = isClicked)
65+
emitSuggestionImpressedFact(
66+
interactionInfo = it,
67+
positionInAwesomeBar = positionInAwesomeBar,
68+
isClicked = isClicked,
69+
engagementAbandoned = engagementAbandoned,
70+
)
6271
}
6372

6473
if (isClicked) {

0 commit comments

Comments
 (0)