diff --git a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Actions/ActionProviderBuilder.swift b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Actions/ActionProviderBuilder.swift index 16ee86f14e7e..f0ae81d389b2 100644 --- a/firefox-ios/Client/Frontend/Browser/BrowserViewController/Actions/ActionProviderBuilder.swift +++ b/firefox-ios/Client/Frontend/Browser/BrowserViewController/Actions/ActionProviderBuilder.swift @@ -11,6 +11,7 @@ import Storage class ActionProviderBuilder { private var actions = [UIAction]() private var taskId = UIBackgroundTaskIdentifier(rawValue: 0) + private let bookmarksTelemetry = BookmarksTelemetry() func build() -> [UIAction] { return actions @@ -44,12 +45,9 @@ class ActionProviderBuilder { title: .ContextMenuBookmarkLink, image: UIImage.templateImageNamed(StandardImageIdentifiers.Large.bookmark), identifier: UIAction.Identifier("linkContextMenu.bookmarkLink") - ) { _ in + ) { [weak self] _ in addBookmark(url.absoluteString, title, nil) - TelemetryWrapper.recordEvent(category: .action, - method: .add, - object: .bookmark, - value: .contextMenu) + self?.bookmarksTelemetry.addBookmark(eventLabel: .contextMenu) } ) } @@ -60,12 +58,9 @@ class ActionProviderBuilder { title: .RemoveBookmarkContextMenuTitle, image: UIImage.templateImageNamed(StandardImageIdentifiers.Large.cross), identifier: UIAction.Identifier("linkContextMenu.removeBookmarkLink") - ) { _ in + ) { [weak self] _ in removeBookmark(url, title, nil) - TelemetryWrapper.recordEvent(category: .action, - method: .delete, - object: .bookmark, - value: .contextMenu) + self?.bookmarksTelemetry.deleteBookmark(eventLabel: .contextMenu) } ) } diff --git a/firefox-ios/Client/Frontend/Home/HomepageContextMenuHelper.swift b/firefox-ios/Client/Frontend/Home/HomepageContextMenuHelper.swift index f383337de236..a27fb448e5ce 100644 --- a/firefox-ios/Client/Frontend/Home/HomepageContextMenuHelper.swift +++ b/firefox-ios/Client/Frontend/Home/HomepageContextMenuHelper.swift @@ -37,6 +37,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol, weak var browserNavigationHandler: BrowserNavigationHandler? weak var delegate: ContextHelperDelegate? var getPopoverSourceRect: ((UIView?) -> CGRect)? + private let bookmarksTelemetry = BookmarksTelemetry() init( viewModel: HomepageViewModel, @@ -208,8 +209,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol, let url = URL(string: site.url) self.delegate?.homePanelDidRequestBookmarkToast(url: url, action: .remove) - - TelemetryWrapper.recordEvent(category: .action, method: .delete, object: .bookmark, value: .activityStream) + self.bookmarksTelemetry.deleteBookmark(eventLabel: .activityStream) }) } @@ -234,8 +234,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol, site.setBookmarked(true) self.delegate?.homePanelDidRequestBookmarkToast(url: nil, action: .add) - - TelemetryWrapper.recordEvent(category: .action, method: .add, object: .bookmark, value: .activityStream) + self.bookmarksTelemetry.addBookmark(eventLabel: .activityStream) }) } diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksTelemetry.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksTelemetry.swift index a6ba1867106c..b13f3b574963 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksTelemetry.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksTelemetry.swift @@ -11,26 +11,35 @@ struct BookmarksTelemetry { enum EventLabel: String { case bookmarksPanel = "bookmarks-panel" case topSites = "top-sites" + case activityStream = "activity-stream" + case contextMenu = "page-action-menu" } init(gleanWrapper: GleanWrapper = DefaultGleanWrapper()) { self.gleanWrapper = gleanWrapper } - func addBookmarkFolder() { - gleanWrapper.recordEvent(for: GleanMetrics.Bookmarks.folderAdd) + func addBookmark(eventLabel: EventLabel) { + gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.add, + label: eventLabel.rawValue) } - func deleteBookmark() { + func deleteBookmark(eventLabel: EventLabel) { gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.delete, - label: EventLabel.bookmarksPanel.rawValue) + label: eventLabel.rawValue) } func openBookmarksSite(eventLabel: EventLabel) { - gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.open, label: eventLabel.rawValue) + gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.open, + label: eventLabel.rawValue) } func editBookmark(eventLabel: EventLabel) { - gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.edit, label: eventLabel.rawValue) + gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.edit, + label: eventLabel.rawValue) } + + func addBookmarkFolder() { + gleanWrapper.recordEvent(for: GleanMetrics.Bookmarks.folderAdd) + } } diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift index 26cc67340f5b..621f0d78d6fe 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift @@ -557,7 +557,7 @@ class BookmarksViewController: SiteTableViewController, guard let strongSelf = self else { completion(false); return } strongSelf.deleteBookmarkNodeAtIndexPath(indexPath) - strongSelf.bookmarksTelemetry.deleteBookmark() + strongSelf.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel) completion(true) } @@ -734,7 +734,7 @@ extension BookmarksViewController: LibraryPanelContextMenu { iconString: StandardImageIdentifiers.Large.bookmarkSlash, tapHandler: { _ in self.deleteBookmarkNodeAtIndexPath(indexPath) - self.bookmarksTelemetry.deleteBookmark() + self.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel) }).items actions.append(removeAction) diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/Legacy/LegacyBookmarksPanel.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/Legacy/LegacyBookmarksPanel.swift index 0f9a0727d24b..5d83ffe33cf0 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/Legacy/LegacyBookmarksPanel.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/Legacy/LegacyBookmarksPanel.swift @@ -483,7 +483,7 @@ class LegacyBookmarksPanel: SiteTableViewController, guard let strongSelf = self else { completion(false); return } strongSelf.deleteBookmarkNodeAtIndexPath(indexPath) - strongSelf.bookmarksTelemetry.deleteBookmark() + strongSelf.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel) completion(true) } @@ -551,7 +551,7 @@ extension LegacyBookmarksPanel: LibraryPanelContextMenu { iconString: StandardImageIdentifiers.Large.bookmarkSlash, tapHandler: { [weak self] _ in self?.deleteBookmarkNodeAtIndexPath(indexPath) - self?.bookmarksTelemetry.deleteBookmark() + self?.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel) }).items actions.append(removeAction)