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

Commit

Permalink
For #5737: Adds telemetry for open links in a private tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Oct 23, 2019
1 parent c31adf2 commit 0c910ae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
18 changes: 17 additions & 1 deletion app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,18 @@ events:
preference_key:
description: "The preference key for the switch preference the user toggled. We currently track:
show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks,
search_browsing_history, show_clipboard_suggestions, and show_search_shortcuts"
search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, and open_links_in_a_private_tab"
enabled:
description: "Whether or not the preference is *now* enabled"
bugs:
- https://github.com/mozilla-mobile/fenix/issue/975
- https://github.com/mozilla-mobile/fenix/issue/5094
- https://github.com/mozilla-mobile/fenix/issues/5737
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/1896
- https://github.com/mozilla-mobile/fenix/pull/5704
- https://github.com/mozilla-mobile/fenix/pull/5886
- https://github.com/mozilla-mobile/fenix/pull/5975
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
Expand All @@ -138,6 +140,20 @@ events:
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"
opened_link:
type: event
description: >
A user opened a link with Fenix
extra_keys:
mode:
description: "The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'"
bugs:
- https://github.com/mozilla-mobile/fenix/issue/5737
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/5975
notification_emails:
- fenix-core@mozilla.com
expires: "2020-03-01"

search_shortcuts:
selected:
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import mozilla.components.feature.intent.processing.TabIntentProcessor
import mozilla.components.support.utils.Browsers
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.customtabs.AuthCustomTabActivity
import org.mozilla.fenix.customtabs.AuthCustomTabActivity.Companion.EXTRA_AUTH_CUSTOM_TAB
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
Expand Down Expand Up @@ -47,14 +50,26 @@ class IntentReceiverActivity : Activity() {
Which only appears if the user doesn't have a default set. */
if (didLaunchPrivateLink && Browsers.all(this).isDefaultBrowser) {
this.settings().openLinksInAPrivateTab = true
components.analytics.metrics.track(Event.PreferenceToggled(
preferenceKey = getString(R.string.pref_key_open_links_in_a_private_tab),
enabled = true,
context = applicationContext
))
} else if (!Browsers.all(this).isDefaultBrowser) {
/* If the user has unset us as the default browser, unset openLinksInAPrivateTab */
this.settings().openLinksInAPrivateTab = false
components.analytics.metrics.track(Event.PreferenceToggled(
preferenceKey = getString(R.string.pref_key_open_links_in_a_private_tab),
enabled = false,
context = applicationContext
))
}

val tabIntentProcessor = if (settings().openLinksInAPrivateTab || didLaunchPrivateLink) {
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.PRIVATE))
components.intentProcessors.privateIntentProcessor
} else {
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.NORMAL))
components.intentProcessors.intentProcessor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ private val Event.wrapper: EventWrapper<*>?
{ TrackingProtection.etpSettingChanged.record(it) },
{ TrackingProtection.etpSettingChangedKeys.valueOf(it) }
)
is Event.OpenedLink -> EventWrapper(
{ Events.openedLink.record(it) },
{ Events.openedLinkKeys.valueOf(it) }
)
// Don't record other events in Glean:
is Event.AddBookmark -> null
is Event.OpenedBookmark -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ sealed class Event {
context.getString(R.string.pref_key_search_bookmarks),
context.getString(R.string.pref_key_search_browsing_history),
context.getString(R.string.pref_key_show_clipboard_suggestions),
context.getString(R.string.pref_key_show_search_shortcuts)
context.getString(R.string.pref_key_show_search_shortcuts),
context.getString(R.string.pref_key_open_links_in_a_private_tab)
)

override val extras: Map<Events.preferenceToggledKeys, String>?
Expand All @@ -153,6 +154,12 @@ sealed class Event {
}
}

data class OpenedLink(val mode: Mode) : Event() {
enum class Mode { NORMAL, PRIVATE }
override val extras: Map<Events.openedLinkKeys, String>?
get() = hashMapOf(Events.openedLinkKeys.mode to mode.name)
}

data class TrackingProtectionSettingChanged(val setting: Setting) : Event() {
enum class Setting { STRICT, STANDARD }
override val extras: Map<TrackingProtection.etpSettingChangedKeys, String>?
Expand Down
3 changes: 2 additions & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ The following metrics are added to the ping:
| events.app_opened |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the app |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|<ul><li>source: The method used to open Fenix. Possible values are: `app_icon`, `custom_tab` or `link`</li></ul>|2020-03-01 |
| events.browser_menu_action |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A browser menu item was tapped |[1](https://github.com/mozilla-mobile/fenix/pull/1214#issue-264756708), [2](https://github.com/mozilla-mobile/fenix/pull/5098#issuecomment-529658996)|<ul><li>item: A string containing the name of the item the user tapped. These items include: Settings, Library, Help, Desktop Site toggle on/off, Find in Page, New Tab, Private Tab, Share, Report Site Issue, Back/Forward button, Reload Button, Quit </li></ul>|2020-03-01 |
| events.entered_url |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user entered a url |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|<ul><li>autocomplete: A boolean that tells us whether the URL was autofilled by an Autocomplete suggestion</li></ul>|2020-03-01 |
| events.opened_link |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a link with Fenix |[1](https://github.com/mozilla-mobile/fenix/pull/5975)|<ul><li>mode: The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'</li></ul>|2020-03-01 |
| events.performed_search |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user performed a search |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673), [2](https://github.com/mozilla-mobile/fenix/pull/1677)|<ul><li>source: A string that tells us how the user performed the search. Possible values are: * default.action * default.suggestion * shortcut.action * shortcut.suggestion </li></ul>|2020-03-01 |
| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a preference switch in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886)|<ul><li>enabled: Whether or not the preference is *now* enabled</li><li>preference_key: The preference key for the switch preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, and show_search_shortcuts</li></ul>|2020-03-01 |
| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a preference switch in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886), [4](https://github.com/mozilla-mobile/fenix/pull/5975)|<ul><li>enabled: Whether or not the preference is *now* enabled</li><li>preference_key: The preference key for the switch preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, and open_links_in_a_private_tab</li></ul>|2020-03-01 |
| events.search_bar_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the search bar |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|<ul><li>source: The view the user was on when they initiated the search (For example: `Home` or `Browser`)</li></ul>|2020-03-01 |
| events.whats_new_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the "what's new" page button |[1](https://github.com/mozilla-mobile/fenix/pull/5090)|<ul><li>source: The location from which the user selected the what's new button. Either 'about' or 'home'</li></ul>|2020-03-01 |
| find_in_page.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user closed the find in page UI |[1](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010)||2020-03-01 |
Expand Down

0 comments on commit 0c910ae

Please sign in to comment.