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

Commit

Permalink
For #969: Adds telemetry for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored and boek committed Jul 18, 2019
1 parent e544827 commit 01aa528
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 1 deletion.
111 changes: 111 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -940,4 +940,115 @@ reader_mode:
- https://github.com/mozilla-mobile/fenix/pull/3941
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"

collections:
renamed:
type: event
description: >
A user renamed a collection
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
tab_restored:
type: event
description: >
A user restored a tab from collection tab list
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
all_tabs_restored:
type: event
description: >
A user tapped "open tabs" from collection menu
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
tab_removed:
type: event
description: >
A user tapped remove tab from collection tab list
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
shared:
type: event
description: >
A user tapped share collection
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
removed:
type: event
description: >
A user tapped delete collection from collection menu
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
saved:
type: event
description: >
A user saved a list of tabs to a new collection
extra_keys:
tabs_open:
description: "The number of tabs open in the current session"
tabs_selected:
description: "The number of tabs added to the collection"
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
tabs_added:
type: event
description: >
A user saved a list of tabs to an existing collection
extra_keys:
tabs_open:
description: "The number of tabs open in the current session"
tabs_selected:
description: "The number of tabs added to the collection"
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
tab_select_opened:
type: event
description: >
A user opened the select tabs screen (the first step of the collection creation flow)
bugs:
- 969
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/3935
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import kotlinx.coroutines.Job
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.android.view.showKeyboard
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.urlToTrimmedHost
import org.mozilla.fenix.home.sessioncontrol.Tab
Expand Down Expand Up @@ -124,6 +126,8 @@ class CollectionCreationUIView(

when (it.saveCollectionStep) {
is SaveCollectionStep.SelectTabs -> {
view.context.components.analytics.metrics.track(Event.CollectionTabSelectOpened)

view.tab_list.isClickable = true

back_button.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.mozilla.fenix.FenixViewModelProvider
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.home.sessioncontrol.Tab
Expand Down Expand Up @@ -122,6 +123,11 @@ class CreateCollectionFragment : DialogFragment() {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
context.components.core.tabCollectionStorage.createCollection(it.name, sessionBundle)
}

context.components.analytics.metrics.track(
Event.CollectionSaved(context.components.core.sessionManager.size, sessionBundle.size)
)

closeTabsIfNecessary(it.tabs)
}
}
Expand All @@ -133,13 +139,19 @@ class CreateCollectionFragment : DialogFragment() {
context.components.core.tabCollectionStorage
.addTabsToCollection(it.collection, sessionBundle)
}

context.components.analytics.metrics.track(
Event.CollectionTabsAdded(context.components.core.sessionManager.size, sessionBundle.size)
)

closeTabsIfNecessary(it.tabs)
}
}
is CollectionCreationAction.RenameCollection -> {
dismiss()
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
requireComponents.core.tabCollectionStorage.renameCollection(it.collection, it.name)
requireComponents.analytics.metrics.track(Event.CollectionRenamed)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ 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.Collections
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),
Expand Down Expand Up @@ -243,6 +244,27 @@ private val Event.wrapper
is Event.HistoryAllItemsRemoved -> EventWrapper<NoExtraKeys>(
{ History.removedAll.record(it) }
)
is Event.CollectionRenamed -> EventWrapper<NoExtraKeys>(
{ Collections.renamed.record(it) }
)
is Event.CollectionTabRestored -> EventWrapper<NoExtraKeys>(
{ Collections.tabRestored.record(it) }
)
is Event.CollectionAllTabsRestored -> EventWrapper<NoExtraKeys>(
{ Collections.allTabsRestored.record(it) }
)
is Event.CollectionTabRemoved -> EventWrapper<NoExtraKeys>(
{ Collections.tabRemoved.record(it) }
)
is Event.CollectionShared -> EventWrapper<NoExtraKeys>(
{ Collections.shared.record(it) }
)
is Event.CollectionRemoved -> EventWrapper<NoExtraKeys>(
{ Collections.removed.record(it) }
)
is Event.CollectionTabSelectOpened -> EventWrapper<NoExtraKeys>(
{ Collections.tabSelectOpened.record(it) }
)

// Don't track other events with Glean
else -> null
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ sealed class Event {
object ReaderModeAvailable : Event()
object ReaderModeOpened : Event()
object ReaderModeAppearanceOpened : Event()
object CollectionRenamed : Event()
object CollectionTabRestored : Event()
object CollectionAllTabsRestored : Event()
object CollectionTabRemoved : Event()
object CollectionShared : Event()
object CollectionRemoved : Event()
object CollectionTabSelectOpened : Event()

data class PreferenceToggled(val preferenceKey: String, val enabled: Boolean, val context: Context) : Event() {
private val switchPreferenceTelemetryAllowList = listOf(
Expand All @@ -124,6 +131,22 @@ sealed class Event {
}

// Interaction Events
data class CollectionSaved(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() {
override val extras: Map<String, String>?
get() = mapOf(
"tabs_open" to tabsOpenCount.toString(),
"tabs_selected" to tabsSelectedCount.toString()
)
}

data class CollectionTabsAdded(val tabsOpenCount: Int, val tabsSelectedCount: Int) : Event() {
override val extras: Map<String, String>?
get() = mapOf(
"tabs_open" to tabsOpenCount.toString(),
"tabs_selected" to tabsSelectedCount.toString()
)
}

data class LibrarySelectedItem(val item: String) : Event() {
override val extras: Map<String, String>?
get() = mapOf("item" to item)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ class HomeFragment : Fragment(), AccountObserver {
setPositiveButton(R.string.tab_collection_dialog_positive) { dialog: DialogInterface, _ ->
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
requireComponents.core.tabCollectionStorage.removeCollection(tabCollection)
requireComponents.analytics.metrics.track(Event.CollectionRemoved)
}.invokeOnCompletion {
dialog.dismiss()
}
Expand Down Expand Up @@ -516,6 +517,7 @@ class HomeFragment : Fragment(), AccountObserver {
)
(activity as HomeActivity).openToBrowser(BrowserDirection.FromHome)
}
requireComponents.analytics.metrics.track(Event.CollectionTabRestored)
}
is CollectionAction.OpenTabs -> {
invokePendingDeleteJobs()
Expand All @@ -540,15 +542,18 @@ class HomeFragment : Fragment(), AccountObserver {
delay(ANIM_SCROLL_DELAY)
sessionControlComponent.view.smoothScrollToPosition(0)
}
requireComponents.analytics.metrics.track(Event.CollectionAllTabsRestored)
}
is CollectionAction.ShareTabs -> {
val shareTabs = action.collection.tabs.map { ShareTab(it.url, it.title) }
share(tabs = shareTabs)
requireComponents.analytics.metrics.track(Event.CollectionShared)
}
is CollectionAction.RemoveTab -> {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
requireComponents.core.tabCollectionStorage.removeTabFromCollection(action.collection, action.tab)
}
requireComponents.analytics.metrics.track(Event.CollectionTabRemoved)
}
}
}
Expand Down
92 changes: 92 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,98 @@ tracking_protection</td>
</table>
</pre>

## collections

<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>renamed</td>
<td>event</td>
<td>A user renamed a collection</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>tab_restored</td>
<td>event</td>
<td>A user restored a tab from collection tab list</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>all_tabs_restored</td>
<td>event</td>
<td>A user tapped "open tabs" from collection menu</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>tab_removed</td>
<td>event</td>
<td>A user tapped remove tab from collection tab list</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>shared</td>
<td>event</td>
<td>A user tapped share collection</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>removed</td>
<td>event</td>
<td>A user tapped delete collection from collection menu</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
<tr>
<td>saved</td>
<td>event</td>
<td>A user saved a list of tabs to a new collection</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td>tabs_open: The number of tabs open in the current session
tabs_selected: The number of tabs added to the collection
</td>
<td>2020-03-01</td>
</tr>
<tr>
<td>tabs_added</td>
<td>event</td>
<td>A user saved a list of tabs to an existing collection</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td>tabs_open: The number of tabs open in the current session
tabs_selected: The number of tabs added to the collection
</td>
<td>2020-03-01</td>
</tr>
<tr>
<td>tab_select_opened</td>
<td>event</td>
<td>A user opened the select tabs screen (the first step of the collection creation flow)</td>
<td><a href="https://github.com/mozilla-mobile/fenix/pull/3935">link</a></td>
<td></td>
<td>2020-03-01</td>
</tr>
</table>
</pre>


## Metrics

Items that are added to the metrics ping
Expand Down

0 comments on commit 01aa528

Please sign in to comment.