Skip to content

Commit

Permalink
For mozilla-mobile#19931: Add telemetry probes for recent bookmarks o…
Browse files Browse the repository at this point in the history
…n home screen (mozilla-mobile#20316)

* Add telemetry probes for recent bookmarks on home screen. Tests for controller.

* Make the events into counters in the metrics ping

Update tests to reflect new metrics

Add data review link for new metrics

Mock new settings for startup metrics tests

Update metrics

Add test for recent bookmark glean events

* Recent bookmarks controller tests
  • Loading branch information
eliserichards committed Aug 24, 2021
1 parent 09e8d34 commit 4182502
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
38 changes: 38 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5750,3 +5750,41 @@ recent_tabs:
notification_emails:
- android-probes@mozilla.com
expires: "2022-06-23"

recent_bookmarks:
bookmark_clicked:
type: counter
lifetime: application
description: |
A counter that indicates the number of times that a user
has clicked on a recently saved bookmark from the home
screen.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/19931
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/20316#issuecomment-888291843
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-02-01"
show_all_bookmarks:
type: counter
lifetime: application
description: |
A counter that indicates the number of times that a user
has clicked the show all button for recently saved bookmarks
on the home screen.
send_in_pings:
- metrics
bugs:
- https://github.com/mozilla-mobile/fenix/issues/19931
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/20316#issuecomment-888291843
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: "2022-02-01"
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ sealed class Event {
object OpenRecentTab : Event()
object OpenInProgressMediaTab : Event()

// Recent bookmarks
object BookmarkClicked : Event()
object ShowAllBookmarks : Event()

// Android Autofill
object AndroidAutofillUnlockSuccessful : Event()
object AndroidAutofillUnlockCanceled : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.mozilla.fenix.GleanMetrics.PrivateBrowsingMode
import org.mozilla.fenix.GleanMetrics.PrivateBrowsingShortcut
import org.mozilla.fenix.GleanMetrics.ProgressiveWebApp
import org.mozilla.fenix.GleanMetrics.ReaderMode
import org.mozilla.fenix.GleanMetrics.RecentBookmarks
import org.mozilla.fenix.GleanMetrics.RecentTabs
import org.mozilla.fenix.GleanMetrics.SearchShortcuts
import org.mozilla.fenix.GleanMetrics.SearchSuggestions
Expand Down Expand Up @@ -853,6 +854,14 @@ private val Event.wrapper: EventWrapper<*>?
{ RecentTabs.showAllClicked.record(it) }
)

is Event.BookmarkClicked -> EventWrapper<NoExtraKeys>(
{ RecentBookmarks.bookmarkClicked.add() }
)

is Event.ShowAllBookmarks -> EventWrapper<NoExtraKeys>(
{ RecentBookmarks.showAllBookmarks.add() }
)

is Event.AndroidAutofillRequestWithLogins -> EventWrapper<NoExtraKeys>(
{ AndroidAutofill.requestMatchingLogins.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import mozilla.components.concept.storage.BookmarkNode
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor

Expand Down Expand Up @@ -47,9 +49,11 @@ class DefaultRecentBookmarksController(
newTab = true,
from = BrowserDirection.FromHome
)
activity.components.core.metrics.track(Event.BookmarkClicked)
}

override fun handleShowAllBookmarksClicked() {
activity.components.core.metrics.track(Event.ShowAllBookmarks)
dismissSearchDialogIfDisplayed()
navController.navigate(
HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.mozilla.fenix.GleanMetrics.Awesomebar
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.History
import org.mozilla.fenix.GleanMetrics.RecentBookmarks
import org.mozilla.fenix.GleanMetrics.SyncedTabs
import org.mozilla.fenix.GleanMetrics.TabsTray
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
Expand Down Expand Up @@ -277,4 +278,15 @@ class GleanMetricsServiceTest {
gleanService.track(Event.DefaultBrowserNotifTapped)
assertTrue(Events.defaultBrowserNotifTapped.testHasValue())
}

@Test
fun `Home screen recent bookmarks events are correctly recorded`() {
assertFalse(RecentBookmarks.bookmarkClicked.testHasValue())
gleanService.track(Event.BookmarkClicked)
assertTrue(RecentBookmarks.bookmarkClicked.testHasValue())

assertFalse(RecentBookmarks.showAllBookmarks.testHasValue())
gleanService.track(Event.ShowAllBookmarks)
assertTrue(RecentBookmarks.showAllBookmarks.testHasValue())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
Expand All @@ -24,6 +25,9 @@ import org.junit.Test
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksController

Expand All @@ -37,12 +41,18 @@ class DefaultRecentBookmarksControllerTest {

private val activity: HomeActivity = mockk(relaxed = true)
private val navController: NavController = mockk(relaxUnitFun = true)
private val metrics: MetricController = mockk(relaxed = true)

private lateinit var controller: DefaultRecentBookmarksController

@Before
fun setup() {
every { activity.openToBrowserAndLoad(any(), any(), any()) } just Runs
every { activity.components.core.metrics } returns metrics

every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment
}
every { navController.navigateUp() } returns true

controller = spyk(
Expand Down Expand Up @@ -85,13 +95,14 @@ class DefaultRecentBookmarksControllerTest {
from = BrowserDirection.FromHome
)
}
verify { metrics.track(Event.BookmarkClicked) }
verify(exactly = 0) {
navController.navigateUp()
}
}

@Test
fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() {
fun `WHEN show all recently saved bookmark is clicked THEN the bookmarks root is opened`() = runBlockingTest {
every { navController.currentDestination } returns mockk {
every { id } returns R.id.homeFragment
}
Expand All @@ -100,8 +111,8 @@ class DefaultRecentBookmarksControllerTest {

val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id)
verify {
controller.dismissSearchDialogIfDisplayed()
navController.navigate(directions)
metrics.track(Event.ShowAllBookmarks)
}
verify(exactly = 0) {
navController.navigateUp()
Expand All @@ -117,10 +128,12 @@ class DefaultRecentBookmarksControllerTest {
controller.handleShowAllBookmarksClicked()

val directions = HomeFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id)

verify {
controller.dismissSearchDialogIfDisplayed()
navController.navigateUp()
navController.navigate(directions)
metrics.track(Event.ShowAllBookmarks)
}
}
}

0 comments on commit 4182502

Please sign in to comment.