This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 711
For #4967 - Record search / ads providers appearing in search results #4968
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,52 @@ legacy_ids: | |
notification_emails: | ||
- [email protected] | ||
expires: never | ||
|
||
browser.search: | ||
with_ads: | ||
type: labeled_counter | ||
description: | | ||
Records counts of SERP pages with adverts displayed. | ||
The key format is `<provider-name>`. | ||
send_in_pings: | ||
- metrics | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/4967 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443 | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: "2022-07-01" | ||
ad_clicks: | ||
type: labeled_counter | ||
description: | | ||
Records clicks of adverts on SERP pages. | ||
The key format is `<provider-name>`. | ||
send_in_pings: | ||
- metrics | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/4967 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443 | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: "2022-07-01" | ||
in_content: | ||
type: labeled_counter | ||
description: | | ||
Records the type of interaction a user has on SERP pages. | ||
send_in_pings: | ||
- metrics | ||
bugs: | ||
- https://github.com/mozilla-mobile/fenix/issues/4967 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/focus-android/pull/4968#issuecomment-879256443 | ||
data_sensitivity: | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
expires: "2022-07-01" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/org/mozilla/focus/telemetry/FactsProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.telemetry | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import mozilla.components.feature.search.telemetry.ads.AdsTelemetry | ||
import mozilla.components.feature.search.telemetry.incontent.InContentTelemetry | ||
import mozilla.components.support.base.Component | ||
import mozilla.components.support.base.facts.Fact | ||
import mozilla.components.support.base.facts.FactProcessor | ||
import mozilla.components.support.base.facts.Facts | ||
|
||
/** | ||
* Processes all [Fact]s emitted from Android Components based on which the appropriate telemetry | ||
* will be collected. | ||
*/ | ||
object FactsProcessor { | ||
fun initialize() { | ||
Facts.registerProcessor(object : FactProcessor { | ||
override fun process(fact: Fact) { | ||
fact.process() | ||
} | ||
}) | ||
} | ||
|
||
@VisibleForTesting | ||
internal fun Fact.process() = when (Pair(component, item)) { | ||
Component.FEATURE_SEARCH to AdsTelemetry.SERP_ADD_CLICKED -> { | ||
TelemetryWrapper.clickAddInSearchEvent(value!!) | ||
} | ||
Component.FEATURE_SEARCH to AdsTelemetry.SERP_SHOWN_WITH_ADDS -> { | ||
TelemetryWrapper.searchWithAdsShownEvent(value!!) | ||
} | ||
Component.FEATURE_SEARCH to InContentTelemetry.IN_CONTENT_SEARCH -> { | ||
TelemetryWrapper.inContentSearchEvent(value!!) | ||
} | ||
else -> Unit | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/test/java/org/mozilla/focus/telemetry/GleanMetricsServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.telemetry | ||
|
||
import android.content.Context | ||
import mozilla.components.browser.state.store.BrowserStore | ||
import mozilla.components.concept.engine.Engine | ||
import mozilla.components.feature.search.telemetry.ads.AdsTelemetry | ||
import mozilla.components.feature.search.telemetry.incontent.InContentTelemetry | ||
import org.junit.Test | ||
import org.mockito.Mockito.doReturn | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.mozilla.focus.Components | ||
|
||
class GleanMetricsServiceTest { | ||
@Test | ||
fun `WHEN installSearchTelemetryExtensions is called THEN install the ads and search telemetry extensions`() { | ||
val components = mock(Components::class.java) | ||
val store = mock(BrowserStore::class.java) | ||
val engine = mock(Engine::class.java) | ||
val adsExtension = mock(AdsTelemetry::class.java) | ||
val searchExtension = mock(InContentTelemetry::class.java) | ||
doReturn(engine).`when`(components).engine | ||
doReturn(store).`when`(components).store | ||
doReturn(adsExtension).`when`(components).adsTelemetry | ||
doReturn(searchExtension).`when`(components).searchTelemetry | ||
val glean = GleanMetricsService(mock(Context::class.java)) | ||
|
||
glean.installSearchTelemetryExtensions(components) | ||
|
||
verify(adsExtension).install(engine, store) | ||
verify(searchExtension).install(engine, store) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be nice to only initialize all these only if
isTelemetryEnabled()
and then observe changes and if the users enable telemetry do the initialization or immediately stop the functionality?Currently the first two will do their own
isTelemetryEnabled()
check and abort the initialization but theFactsProcessor
won't.