Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Bug 1459010 - Add UI event telemetry for Downloads (#3905)
Browse files Browse the repository at this point in the history
  • Loading branch information
justindarc committed May 11, 2018
1 parent fe300ed commit f3a2f40
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Expand Up @@ -2438,6 +2438,7 @@ extension BrowserViewController: ContextMenuHelperDelegate {
let downloadAction = UIAlertAction(title: downloadTitle, style: .default) { _ in
self.pendingDownloadURL = url
currentTab.webView?.evaluateJavaScript("window.__firefox__.download('\(url.absoluteString)', '\(UserScriptManager.securityToken)')")
UnifiedTelemetry.recordEvent(category: .action, method: .tap, object: .downloadLinkButton)
}
actionSheetController.addAction(downloadAction)

Expand Down
Expand Up @@ -52,6 +52,7 @@ extension BrowserViewController: DownloadQueueDelegate {
let downloadCompleteToast = ButtonToast(labelText: download.filename, imageName: "check", buttonText: Strings.DownloadsButtonTitle, completion: { buttonPressed in
if buttonPressed {
self.openURLInNewTab(HomePanelType.downloads.localhostURL, isPrivate: self.tabManager.selectedTab?.isPrivate ?? false, isPrivileged: true)
UnifiedTelemetry.recordEvent(category: .action, method: .view, object: .downloadsPanel, value: .downloadCompleteToast)
}
})

Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Browser/DownloadToast.swift
Expand Up @@ -172,6 +172,7 @@ class DownloadToast: Toast {
alert.addAction(UIAlertAction(title: Strings.CancelDownloadDialogCancel, style: .default, handler: { action in
self.completionHandler?(true)
self.dismiss(true)
UnifiedTelemetry.recordEvent(category: .action, method: .cancel, object: .download)
}))

viewController?.present(alert, animated: true, completion: nil)
Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Browser/OpenInHelper.swift
Expand Up @@ -109,6 +109,7 @@ class DownloadHelper: NSObject, OpenInHelper {

let downloadFileItem = PhotonActionSheetItem(title: Strings.OpenInDownloadHelperAlertDownloadNow, iconString: "download") { _ in
self.browserViewController.downloadQueue.enqueueDownload(download)
UnifiedTelemetry.recordEvent(category: .action, method: .tap, object: .downloadNowButton)
}

let actions = [[filenameItem], [downloadFileItem]]
Expand Down
4 changes: 4 additions & 0 deletions Client/Frontend/Home/DownloadsPanel.swift
Expand Up @@ -374,6 +374,8 @@ class DownloadsPanel: UIViewController, UITableViewDelegate, UITableViewDataSour
tableView.deselectRow(at: indexPath, animated: true)

if let downloadedFile = downloadedFileForIndexPath(indexPath) {
UnifiedTelemetry.recordEvent(category: .action, method: .tap, object: .download, value: .downloadsPanel)

guard downloadedFile.canShowInWebView else {
shareDownloadedFile(downloadedFile, indexPath: indexPath)
return
Expand Down Expand Up @@ -406,12 +408,14 @@ class DownloadsPanel: UIViewController, UITableViewDelegate, UITableViewDataSour
self.tableView.deleteRows(at: [indexPath], with: .right)
self.tableView.endUpdates()
self.updateEmptyPanelState()
UnifiedTelemetry.recordEvent(category: .action, method: .delete, object: .download, value: .downloadsPanel)
}
}
})
let share = UITableViewRowAction(style: .normal, title: shareTitle, handler: { (action, indexPath) in
if let downloadedFile = self.downloadedFileForIndexPath(indexPath) {
self.shareDownloadedFile(downloadedFile, indexPath: indexPath)
UnifiedTelemetry.recordEvent(category: .action, method: .share, object: .download, value: .downloadsPanel)
}
})
share.backgroundColor = view.tintColor
Expand Down
2 changes: 2 additions & 0 deletions Client/Frontend/Home/HomePanelViewController.swift
Expand Up @@ -206,6 +206,8 @@ class HomePanelViewController: UIViewController, UITextFieldDelegate, HomePanelD
delegate?.homePanelViewController(self, didSelectPanel: index)
if selectedPanel == .bookmarks {
UnifiedTelemetry.recordEvent(category: .action, method: .view, object: .bookmarksPanel, value: .homePanelTabButton)
} else if selectedPanel == .downloads {
UnifiedTelemetry.recordEvent(category: .action, method: .view, object: .downloadsPanel, value: .homePanelTabButton)
}
break
}
Expand Down
1 change: 1 addition & 0 deletions Client/Frontend/Widgets/PhotonActionSheetProtocol.swift
Expand Up @@ -64,6 +64,7 @@ extension PhotonActionSheetProtocol {

let openDownloads = PhotonActionSheetItem(title: Strings.AppMenuDownloadsTitleString, iconString: "menu-panel-Downloads") { action in
tab.loadRequest(PrivilegedRequest(url: HomePanelType.downloads.localhostURL) as URLRequest)
UnifiedTelemetry.recordEvent(category: .action, method: .view, object: .downloadsPanel, value: .appMenu)
}

let openHomePage = PhotonActionSheetItem(title: Strings.AppMenuOpenHomePageTitleString, iconString: "menu-Home") { _ in
Expand Down
8 changes: 8 additions & 0 deletions Client/Telemetry/UnifiedTelemetry.swift
Expand Up @@ -119,6 +119,7 @@ extension UnifiedTelemetry {
public enum EventMethod: String {
case add = "add"
case background = "background"
case cancel = "cancel"
case change = "change"
case delete = "delete"
case drag = "drag"
Expand All @@ -127,6 +128,7 @@ extension UnifiedTelemetry {
case open = "open"
case press = "press"
case scan = "scan"
case share = "share"
case tap = "tap"
case view = "view"
case applicationOpenUrl = "application-open-url"
Expand All @@ -136,6 +138,10 @@ extension UnifiedTelemetry {
case app = "app"
case bookmark = "bookmark"
case bookmarksPanel = "bookmarks-panel"
case download = "download"
case downloadLinkButton = "download-link-button"
case downloadNowButton = "download-now-button"
case downloadsPanel = "downloads-panel"
case keyCommand = "key-command"
case locationBar = "location-bar"
case qrCodeText = "qr-code-text"
Expand All @@ -157,6 +163,8 @@ extension UnifiedTelemetry {
case awesomebarResults = "awesomebar-results"
case bookmarksPanel = "bookmarks-panel"
case browser = "browser"
case downloadCompleteToast = "download-complete-toast"
case downloadsPanel = "downloads-panel"
case homePanel = "home-panel"
case homePanelTabButton = "home-panel-tab-button"
case markAsRead = "mark-as-read"
Expand Down

0 comments on commit f3a2f40

Please sign in to comment.