Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #2362: Adds telemetry for history
Browse files Browse the repository at this point in the history
sblatz committed Jul 16, 2019
1 parent 5792acf commit d6dc33f
Showing 5 changed files with 142 additions and 2 deletions.
59 changes: 58 additions & 1 deletion app/metrics.yaml
Original file line number Diff line number Diff line change
@@ -613,7 +613,7 @@ activation:
type: string
lifetime: ping
description: >
An hashed and salted version of the Google Advertising ID from the device.
A hashed and salted version of the Google Advertising ID from the device.
This will never be sent in a ping that also contains the client_id.
send_in_pings:
- activation
@@ -844,3 +844,60 @@ sync_account:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"

history:
opened:
type: event
description: >
A user opened the history screen
bugs:
- 2362
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3940
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
removed:
type: event
description: >
A user removed a history item
bugs:
- 2362
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3940
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
removed_all:
type: event
description: >
A user removed all history items
bugs:
- 2362
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3940
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
shared:
type: event
description: >
A user shared a history item
bugs:
- 2362
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3940
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
opened_item:
type: event
description: >
A user opened a history item
bugs:
- 2362
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3940
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
Original file line number Diff line number Diff line change
@@ -22,15 +22,16 @@ import org.mozilla.fenix.GleanMetrics.CustomTab
import org.mozilla.fenix.GleanMetrics.ErrorPage
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.FindInPage
import org.mozilla.fenix.GleanMetrics.History
import org.mozilla.fenix.GleanMetrics.Library
import org.mozilla.fenix.GleanMetrics.Metrics
import org.mozilla.fenix.GleanMetrics.Pings
import org.mozilla.fenix.GleanMetrics.QrScanner
import org.mozilla.fenix.GleanMetrics.QuickActionSheet
import org.mozilla.fenix.GleanMetrics.SearchDefaultEngine
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.GleanMetrics.SyncAccount
import org.mozilla.fenix.GleanMetrics.SyncAuth
import org.mozilla.fenix.ext.components

private class EventWrapper<T : Enum<T>>(
private val recorder: ((Map<T, String>?) -> Unit),
@@ -227,6 +228,21 @@ private val Event.wrapper
{ Events.preferenceToggled.record(it) },
{ Events.preferenceToggledKeys.valueOf(it) }
)
is Event.HistoryOpened -> EventWrapper<NoExtraKeys>(
{ History.opened.record(it) }
)
is Event.HistoryItemShared -> EventWrapper<NoExtraKeys>(
{ History.shared.record(it) }
)
is Event.HistoryItemOpened -> EventWrapper<NoExtraKeys>(
{ History.openedItem.record(it) }
)
is Event.HistoryItemRemoved -> EventWrapper<NoExtraKeys>(
{ History.removed.record(it) }
)
is Event.HistoryAllItemsRemoved -> EventWrapper<NoExtraKeys>(
{ History.removedAll.record(it) }
)

// Don't track other events with Glean
else -> null
Original file line number Diff line number Diff line change
@@ -93,6 +93,11 @@ sealed class Event {
object SyncAccountClosed : Event()
object SyncAccountSyncNow : Event()
object SyncAccountSignOut : Event()
object HistoryOpened : Event()
object HistoryItemShared : Event()
object HistoryItemOpened : Event()
object HistoryItemRemoved : Event()
object HistoryAllItemsRemoved : Event()

data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
private val switchPreferenceTelemetryAllowList = listOf(
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import org.mozilla.fenix.FenixViewModelProvider
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getHostFromUrl
import org.mozilla.fenix.ext.nav
@@ -69,6 +70,7 @@ class HistoryFragment : Fragment(), BackHandler {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requireComponents.analytics.metrics.track(Event.HistoryOpened)
setHasOptionsMenu(true)
}

@@ -209,6 +211,7 @@ class HistoryFragment : Fragment(), BackHandler {
}

private fun openItem(item: HistoryItem) {
requireComponents.analytics.metrics.track(Event.HistoryItemOpened)
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = item.url,
newTab = true,
@@ -226,6 +229,7 @@ class HistoryFragment : Fragment(), BackHandler {
setPositiveButton(R.string.history_clear_dialog) { dialog: DialogInterface, _ ->
emitChange { HistoryChange.EnterDeletionMode }
lifecycleScope.launch {
requireComponents.analytics.metrics.track(Event.HistoryAllItemsRemoved)
requireComponents.core.historyStorage.deleteEverything()
reloadData()
launch(Dispatchers.Main) {
@@ -279,13 +283,15 @@ class HistoryFragment : Fragment(), BackHandler {
selected: List<HistoryItem>,
components: Components = requireComponents
) {
requireComponents.analytics.metrics.track(Event.HistoryItemRemoved)
val storage = components.core.historyStorage
for (item in selected) {
storage.deleteVisit(item.url, item.visitedAt)
}
}

private fun share(url: String? = null, tabs: List<ShareTab>? = null) {
requireComponents.analytics.metrics.track(Event.HistoryItemShared)
val directions =
HistoryFragmentDirections.actionHistoryFragmentToShareFragment(
url = url,
56 changes: 56 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
@@ -706,6 +706,62 @@ tracking_protection</td>
</pre>


## history

<pre>
<table style="width: 100%">
<tr>
<th>key</th>
<th>type</th>
<th>description</th>
<th>data deview</th>
<th>extras</th>
<th>expires</th>
</tr>
<tr>
<td>opened</td>
<td>event</td>
<td>A user opened the history screen</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3940">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>removed</td>
<td>event</td>
<td>A user removed a history item</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3940">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>removed_all</td>
<td>event</td>
<td>A user removed all history items</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3940">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>shared</td>
<td>event</td>
<td>A user shared a history item</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3940">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>opened_item</td>
<td>event</td>
<td>A user opened a history item</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3940">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
</table>
</pre>


## Metrics

Items that are added to the metrics ping

0 comments on commit d6dc33f

Please sign in to comment.