Skip to content

Commit

Permalink
For mozilla-mobile#14565: Add telemetry for top sites
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Sep 17, 2020
1 parent f43476c commit 05f48de
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 13 deletions.
60 changes: 60 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3195,6 +3195,66 @@ top_sites:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-11-15"
open_frecency:
type: event
description: |
A user opened a frecency top site
bugs:
- https://github.com/mozilla-mobile/fenix/issues/14565
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/15136
data_sensitivity:
- interaction
notification_emails:
- fenix-core@mozilla.com
expires: "2021-03-15"
open_pinned:
type: event
description: |
A user opened a pinned top site
bugs:
- https://github.com/mozilla-mobile/fenix/issues/14565
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/15136
data_sensitivity:
- interaction
notification_emails:
- fenix-core@mozilla.com
expires: "2021-03-15"
swipe_carousel:
type: event
description: |
A user swiped to change the page of the top sites carousel
extra_keys:
page:
description: |
The page number the carousel is now on
bugs:
- https://github.com/mozilla-mobile/fenix/issues/14565
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/15136
data_sensitivity:
- interaction
notification_emails:
- fenix-core@mozilla.com
expires: "2021-03-15"
long_press:
type: event
description: |
A user long pressed on a top site
extra_keys:
type:
description: |
The type of top site. Options are: "FRECENCY," "DEFAULT," or "PINNED."
bugs:
- https://github.com/mozilla-mobile/fenix/issues/14565
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/15136
data_sensitivity:
- interaction
notification_emails:
- fenix-core@mozilla.com
expires: "2021-03-15"
open_in_new_tab:
type: event
description: |
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.mozilla.fenix.components.metrics
import android.content.Context
import mozilla.components.browser.errorpages.ErrorType
import mozilla.components.browser.search.SearchEngine
import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AppTheme
import org.mozilla.fenix.GleanMetrics.Autoplay
Expand All @@ -21,6 +22,7 @@ import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.Tip
import org.mozilla.fenix.GleanMetrics.ToolbarSettings
import org.mozilla.fenix.GleanMetrics.TopSites
import org.mozilla.fenix.GleanMetrics.TrackingProtection
import org.mozilla.fenix.R
import java.util.Locale
Expand Down Expand Up @@ -121,6 +123,8 @@ sealed class Event {
object NotificationMediaPlay : Event()
object NotificationMediaPause : Event()
object TopSiteOpenDefault : Event()
object TopSiteOpenFrecent : Event()
object TopSiteOpenPinned : Event()
object TopSiteOpenInNewTab : Event()
object TopSiteOpenInPrivateTab : Event()
object TopSiteRemoved : Event()
Expand Down Expand Up @@ -191,6 +195,16 @@ sealed class Event {

// Interaction events with extras

data class TopSiteSwipeCarousel(val page: Int) : Event() {
override val extras: Map<TopSites.swipeCarouselKeys, String>?
get() = hashMapOf(TopSites.swipeCarouselKeys.page to page.toString())
}

data class TopSiteLongPress(val type: TopSite.Type) : Event() {
override val extras: Map<TopSites.longPressKeys, String>?
get() = hashMapOf(TopSites.longPressKeys.type to type.name)
}

data class ProgressiveWebAppForeground(val timeForegrounded: Long) : Event() {
override val extras: Map<ProgressiveWebApp.foregroundKeys, String>?
get() = mapOf(ProgressiveWebApp.foregroundKeys.timeMs to timeForegrounded.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ private val Event.wrapper: EventWrapper<*>?
is Event.TopSiteOpenDefault -> EventWrapper<NoExtraKeys>(
{ TopSites.openDefault.record(it) }
)
is Event.TopSiteOpenFrecent -> EventWrapper<NoExtraKeys>(
{ TopSites.openFrecency.record(it) }
)
is Event.TopSiteOpenPinned -> EventWrapper<NoExtraKeys>(
{ TopSites.openPinned.record(it) }
)
is Event.TopSiteOpenInNewTab -> EventWrapper<NoExtraKeys>(
{ TopSites.openInNewTab.record(it) }
)
Expand All @@ -526,6 +532,14 @@ private val Event.wrapper: EventWrapper<*>?
is Event.TopSiteRemoved -> EventWrapper<NoExtraKeys>(
{ TopSites.remove.record(it) }
)
is Event.TopSiteLongPress -> EventWrapper(
{ TopSites.longPress.record(it) },
{ TopSites.longPressKeys.valueOf(it) }
)
is Event.TopSiteSwipeCarousel -> EventWrapper(
{ TopSites.swipeCarousel.record(it) },
{ TopSites.swipeCarouselKeys.valueOf(it) }
)
is Event.SupportTapped -> EventWrapper<NoExtraKeys>(
{ AboutPage.supportTapped.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ interface SessionControlController {
/**
* @see [TopSiteInteractor.onSelectTopSite]
*/
fun handleSelectTopSite(url: String, isDefault: Boolean)
fun handleSelectTopSite(url: String, type: TopSite.Type)

/**
* @see [OnboardingInteractor.onStartBrowsingClicked]
Expand Down Expand Up @@ -302,11 +302,14 @@ class DefaultSessionControlController(
metrics.track(Event.CollectionRenamePressed)
}

override fun handleSelectTopSite(url: String, isDefault: Boolean) {
override fun handleSelectTopSite(url: String, type: TopSite.Type) {
metrics.track(Event.TopSiteOpenInNewTab)
if (isDefault) {
metrics.track(Event.TopSiteOpenDefault)
when (type) {
TopSite.Type.DEFAULT -> metrics.track(Event.TopSiteOpenDefault)
TopSite.Type.FRECENT -> metrics.track(Event.TopSiteOpenFrecent)
TopSite.Type.PINNED -> metrics.track(Event.TopSiteOpenPinned)
}

if (url == SupportUtils.POCKET_TRENDING_URL) {
metrics.track(Event.PocketTopSiteClicked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ interface TopSiteInteractor {
* Selects the given top site. Called when a user clicks on a top site.
*
* @param url The URL of the top site.
* @param isDefault Whether or not the top site is a default one.
* @param type The type of the top site.
*/
fun onSelectTopSite(url: String, isDefault: Boolean)
fun onSelectTopSite(url: String, type: TopSite.Type)
}

/**
Expand Down Expand Up @@ -218,8 +218,8 @@ class SessionControlInteractor(
controller.handleRenameCollectionTapped(collection)
}

override fun onSelectTopSite(url: String, isDefault: Boolean) {
controller.handleSelectTopSite(url, isDefault)
override fun onSelectTopSite(url: String, type: TopSite.Type) {
controller.handleSelectTopSite(url, type)
}

override fun onStartBrowsingClicked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.viewpager2.widget.ViewPager2
import kotlinx.android.synthetic.main.component_top_sites_pager.view.*
import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
import org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.TopSitesPagerAdapter

Expand All @@ -21,10 +23,16 @@ class TopSitePagerViewHolder(

private val topSitesPagerAdapter = TopSitesPagerAdapter(interactor)
private val pageIndicator = view.page_indicator
private var currentPage = 0

private val topSitesPageChangeCallback = object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
if (currentPage != position) {
pageIndicator.context.components.analytics.metrics.track(Event.TopSiteSwipeCarousel(position))
}

pageIndicator.setSelection(position)
currentPage = position
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import kotlinx.android.synthetic.main.top_site_item.*
import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite.Type.DEFAULT
import mozilla.components.feature.top.sites.TopSite.Type.FRECENT
import mozilla.components.feature.top.sites.TopSite.Type.PINNED
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
Expand All @@ -32,10 +32,12 @@ class TopSiteItemViewHolder(

init {
top_site_item.setOnClickListener {
interactor.onSelectTopSite(topSite.url, topSite.type === DEFAULT)
interactor.onSelectTopSite(topSite.url, topSite.type)
}

top_site_item.setOnLongClickListener {
it.context.components.analytics.metrics.track(Event.TopSiteLongPress(topSite.type))

val topSiteMenu = TopSiteItemMenu(view.context, topSite.type != FRECENT) { item ->
when (item) {
is TopSiteItemMenu.Item.OpenInPrivateTab -> interactor.onOpenInPrivateTabClicked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.Engine
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -279,7 +280,7 @@ class DefaultSessionControlControllerTest {
fun handleSelectDefaultTopSite() {
val topSiteUrl = "mozilla.org"

controller.handleSelectTopSite(topSiteUrl, true)
controller.handleSelectTopSite(topSiteUrl, TopSite.Type.DEFAULT)
verify { metrics.track(Event.TopSiteOpenInNewTab) }
verify { metrics.track(Event.TopSiteOpenDefault) }
verify {
Expand All @@ -296,7 +297,7 @@ class DefaultSessionControlControllerTest {
fun handleSelectNonDefaultTopSite() {
val topSiteUrl = "mozilla.org"

controller.handleSelectTopSite(topSiteUrl, false)
controller.handleSelectTopSite(topSiteUrl, TopSite.Type.FRECENT)
verify { metrics.track(Event.TopSiteOpenInNewTab) }
verify {
tabsUseCases.addTab.invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class TopSiteItemViewHolderTest {
TopSiteItemViewHolder(view, interactor).bind(pocket)

view.top_site_item.performClick()
verify { interactor.onSelectTopSite("https://getpocket.com", isDefault = true) }
verify { interactor.onSelectTopSite("https://getpocket.com", TopSite.Type.DEFAULT) }
}
}
4 changes: 4 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@ The following metrics are added to the ping:
| tip.displayed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The tip was displayed |[1](https://github.com/mozilla-mobile/fenix/pull/9836)|<ul><li>identifier: The identifier of the tip displayed</li></ul>|2020-11-15 |2 |
| tip.pressed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The tip's button was pressed |[1](https://github.com/mozilla-mobile/fenix/pull/9836)|<ul><li>identifier: The identifier of the tip the action was taken on</li></ul>|2020-11-15 |2 |
| toolbar_settings.changed_position |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |The user selected a new position for the toolbar |[1](https://github.com/mozilla-mobile/fenix/pull/6608)|<ul><li>position: A string that indicates the new position of the toolbar TOP or BOTTOM </li></ul>|2020-11-15 |2 |
| top_sites.long_press |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user long pressed on a top site |[1](https://github.com/mozilla-mobile/fenix/pull/15136)|<ul><li>type: The type of top site. Options are: "FRECENCY," "DEFAULT," or "PINNED." </li></ul>|2021-03-15 |2 |
| top_sites.open_default |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a default top site |[1](https://github.com/mozilla-mobile/fenix/pull/10752)||2020-11-15 |2 |
| top_sites.open_frecency |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a frecency top site |[1](https://github.com/mozilla-mobile/fenix/pull/15136)||2021-03-15 |2 |
| top_sites.open_in_new_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opens a new tab based on a top site item |[1](https://github.com/mozilla-mobile/fenix/pull/7523)||2020-11-15 |2 |
| top_sites.open_in_private_tab |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opens a new private tab based on a top site item |[1](https://github.com/mozilla-mobile/fenix/pull/7523)||2020-11-15 |2 |
| top_sites.open_pinned |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a pinned top site |[1](https://github.com/mozilla-mobile/fenix/pull/15136)||2021-03-15 |2 |
| top_sites.remove |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user removes a top site item |[1](https://github.com/mozilla-mobile/fenix/pull/7523)||2020-11-15 |2 |
| top_sites.swipe_carousel |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user swiped to change the page of the top sites carousel |[1](https://github.com/mozilla-mobile/fenix/pull/15136)|<ul><li>page: The page number the carousel is now on </li></ul>|2021-03-15 |2 |
| tracking_protection.etp_setting_changed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user changed their tracking protection level setting to either strict, standard, or custom. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188), [2](https://github.com/mozilla-mobile/fenix/pull/11383)|<ul><li>etp_setting: The new setting for ETP: strict, standard, custom</li></ul>|2020-11-15 |2 |
| tracking_protection.etp_settings |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened tracking protection settings through settings. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-11-15 |2 |
| tracking_protection.etp_shield |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user pressed the tracking protection shield icon in toolbar. |[1](https://github.com/mozilla-mobile/fenix/pull/5414#issuecomment-532847188)||2020-11-15 |2 |
Expand Down

0 comments on commit 05f48de

Please sign in to comment.