Skip to content

Commit

Permalink
Add #9278 [v97]: Telemetry for tab toolbar navigation buttons (#9785)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant2718 authored Jan 18, 2022
1 parent f2b5b74 commit 8630b3d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Client/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Shared
import XCGLogger

fileprivate var debugTabCount = 0
fileprivate let log = Logger.browserLogger

func mostRecentTab(inTabs tabs: [Tab]) -> Tab? {
var recent = tabs.first
Expand Down Expand Up @@ -429,6 +430,7 @@ class Tab: NSObject {
restore(webView)

self.webView = webView
configureEdgeSwipeGestureRecognizers()
self.webView?.addObserver(self, forKeyPath: KVOConstants.URL.rawValue, options: .new, context: nil)
UserScriptManager.shared.injectUserScriptsIntoTab(self, nightMode: nightMode, noImageMode: noImageMode)
tabDelegate?.tab?(self, didCreateWebView: webView)
Expand Down Expand Up @@ -834,6 +836,34 @@ class Tab: NSObject {
}
}

extension Tab: UIGestureRecognizerDelegate {
// This prevents the recognition of one gesture recognizer from blocking another
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}

func configureEdgeSwipeGestureRecognizers() {
guard let webView = webView else {
log.info("Tab's edge swipe gesture recognizer was never added. This will affect Tab navigation telemetry!")
return
}

let edgeSwipeGesture = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(handleEdgeSwipeTabNavigation(_:)))
edgeSwipeGesture.edges = .left
edgeSwipeGesture.delegate = self
webView.addGestureRecognizer(edgeSwipeGesture)
}

@objc func handleEdgeSwipeTabNavigation(_ sender: UIScreenEdgePanGestureRecognizer) {
guard let webView = webView else { return }

if sender.state == .ended, (sender.velocity(in: webView).x > 150) {
TelemetryWrapper.recordEvent(category: .action, method: .swipe, object: .navigateTabHistoryBackSwipe)
}
}

}

extension Tab: TabWebViewDelegate {
fileprivate func tabWebView(_ tabWebView: TabWebView, didSelectFindInPageForSelection selection: String) {
tabDelegate?.tab(self, didSelectFindInPageForSelection: selection)
Expand Down
4 changes: 4 additions & 0 deletions Client/Frontend/Browser/TabToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ open class TabToolbarHelper: NSObject {

func didClickBack() {
toolbar.tabToolbarDelegate?.tabToolbarDidPressBack(toolbar, button: toolbar.backButton)
TelemetryWrapper.recordEvent(category: .action, method: .tap, object: .navigateTabHistoryBack)
}

func didLongPressBack(_ recognizer: UILongPressGestureRecognizer) {
if recognizer.state == .began {
toolbar.tabToolbarDelegate?.tabToolbarDidLongPressBack(toolbar, button: toolbar.backButton)
TelemetryWrapper.recordEvent(category: .action, method: .press, object: .navigateTabHistoryBack)
}
}

Expand All @@ -168,11 +170,13 @@ open class TabToolbarHelper: NSObject {

func didClickForward() {
toolbar.tabToolbarDelegate?.tabToolbarDidPressForward(toolbar, button: toolbar.forwardButton)
TelemetryWrapper.recordEvent(category: .action, method: .tap, object: .navigateTabHistoryForward)
}

func didLongPressForward(_ recognizer: UILongPressGestureRecognizer) {
if recognizer.state == .began {
toolbar.tabToolbarDelegate?.tabToolbarDidLongPressForward(toolbar, button: toolbar.forwardButton)
TelemetryWrapper.recordEvent(category: .action, method: .press, object: .navigateTabHistoryForward)
}
}

Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Browser/URLBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ extension URLBarView: TabLocationViewDelegate {
switch state {
case .reload:
delegate?.urlBarDidPressReload(self)
TelemetryWrapper.recordEvent(category: .action, method: .tap, object: .reloadFromUrlBar)
case .stop:
delegate?.urlBarDidPressStop(self)
case .disabled:
Expand Down
13 changes: 13 additions & 0 deletions Client/Telemetry/TelemetryWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ extension TelemetryWrapper {
case drag = "drag"
case drop = "drop"
case foreground = "foreground"
case swipe = "swipe"
case navigate = "navigate"
case open = "open"
case press = "press"
Expand Down Expand Up @@ -370,6 +371,9 @@ extension TelemetryWrapper {
case home = "home-page"
case blockImagesEnabled = "block-images-enabled"
case blockImagesDisabled = "block-images-disabled"
case navigateTabHistoryBack = "navigate-tab-history-back"
case navigateTabHistoryBackSwipe = "navigate-tab-history-back-swipe"
case navigateTabHistoryForward = "navigate-tab-history-forward"
case nightModeEnabled = "night-mode-enabled"
case nightModeDisabled = "night-mode-disabled"
case logins = "logins-and-passwords"
Expand All @@ -394,6 +398,7 @@ extension TelemetryWrapper {
case recentlySavedReadingItemImpressions = "recently-saved-reading-items-impressions"
case inactiveTabTray = "inactiveTabTray"
case reload = "reload"
case reloadFromUrlBar = "reload-from-url-bar"
}

public enum EventValue: String {
Expand Down Expand Up @@ -549,6 +554,14 @@ extension TelemetryWrapper {
GleanMetrics.Tabs.pullToRefresh.add()
case(.action, .navigate, .tab, _, _):
GleanMetrics.Tabs.normalAndPrivateUriCount.add()
case(.action, .tap, .navigateTabHistoryBack, _, _), (.action, .press, .navigateTabHistoryBack, _, _):
GleanMetrics.Tabs.navigateTabHistoryBack.add()
case(.action, .tap, .navigateTabHistoryForward, _, _), (.action, .press, .navigateTabHistoryForward, _, _):
GleanMetrics.Tabs.navigateTabHistoryForward.add()
case(.action, .swipe, .navigateTabHistoryBackSwipe, _, _):
GleanMetrics.Tabs.navigateTabBackSwipe.add()
case(.action, .tap, .reloadFromUrlBar, _, _):
GleanMetrics.Tabs.reloadFromUrlBar.add()
// Settings Menu
case (.action, .open, .settingsMenuSetAsDefaultBrowser, _, _):
GleanMetrics.SettingsMenu.setAsDefaultBrowserPressed.add()
Expand Down
48 changes: 48 additions & 0 deletions Client/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,54 @@ tabs:
notification_emails:
- [email protected]
expires: "2022-07-01"
navigate_tab_history_back:
type: counter
description: |
This counts the number of times a user taps the back
button on a tab's toolbar.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/9278
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/9785
notification_emails:
- [email protected]
expires: "2022-07-01"
navigate_tab_back_swipe:
type: counter
description: |
This counts the number of times a user navigates back in tab
history by swiping from the left edge of the device to the right.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/9278
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/9785
notification_emails:
- [email protected]
expires: "2022-07-01"
navigate_tab_history_forward:
type: counter
description: |
This counts the number of times a user taps the forward
button on a tab's toolbar.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/9278
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/9785
notification_emails:
- [email protected]
expires: "2022-07-01"
reload_from_url_bar:
type: counter
description: |
This counts the number of times a user taps the reload
button in the URL bar.
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/9278
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/9785
notification_emails:
- [email protected]
expires: "2022-07-01"

# Theme metrics
theme:
Expand Down

0 comments on commit 8630b3d

Please sign in to comment.