Skip to content

Commit

Permalink
pixels for bookmarks > favorites tab (#3572)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/392891325557410/1208733952836859/f
Tech Design URL:
CC:

**Description**:
Pixels for bookmarks > favorites tab.

**Steps to test this PR**:
1. Change DailyPixel.swift so that `hasBeenFiredToday` returns false
2. Add some favorites
3. Go to the bookmarks UI and tap on the favourites tab
4. Tap on manage -> pixel should fire
`m_bookmarks_ui_favorites_manage_daily`
6. Exit edit mode
7. Edit a favorite -> pixel should fire
`m_bookmarks_ui_favorites_action_daily`
8. Move a favorite -> pixel should fire
`m_bookmarks_ui_favorites_action_daily`
9. Remove a favorite -> pixel should fire
`m_bookmarks_ui_favorites_action_daily`
10. Check that actions on the new tab page do not fire the above pixels
11. Check the overlay does not trigger these pixels to fire

---------

Co-authored-by: Mariusz Śpiewak <[email protected]>
  • Loading branch information
brindy and dus7 authored Nov 14, 2024
1 parent 8739310 commit 95897a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ extension Pixel {
case bookmarkAddFavoriteBySwipe
case bookmarkDeletedFromBookmark

case bookmarksUIFavoritesAction
case bookmarksUIFavoritesManage

case bookmarkImportSuccess
case bookmarkImportFailure
case bookmarkImportFailureParsingDL
Expand Down Expand Up @@ -968,6 +971,9 @@ extension Pixel.Event {
case .bookmarkAddFavoriteBySwipe: return "m_add_favorite_by_swipe"
case .bookmarkDeletedFromBookmark: return "m_bookmark_deleted_from_bookmark"

case .bookmarksUIFavoritesAction: return "m_bookmarks_ui_favorites_action_daily"
case .bookmarksUIFavoritesManage: return "m_bookmarks_ui_favorites_manage_daily"

case .homeScreenShown: return "mh"
case .homeScreenEditFavorite: return "mh_ef"
case .homeScreenDeleteFavorite: return "mh_df"
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/BookmarksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ class BookmarksViewController: UIViewController, UITableViewDelegate {
changeEditButtonToDone()
configureToolbarMoreItem()
refreshFooterView()

if !favoritesContainer.isHidden {
DailyPixel.fireDaily(.bookmarksUIFavoritesManage)
}
}

private func finishEditing() {
Expand Down
12 changes: 10 additions & 2 deletions DuckDuckGo/FavoritesHomeViewSectionRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class FavoritesHomeViewSectionRenderer {
guard let indexPath = collectionView.indexPath(for: cell),
let favorite = viewModel.favorite(at: indexPath.row) else { return }
Pixel.fire(pixel: .homeScreenDeleteFavorite)
fireActionPixel()
viewModel.removeFavorite(favorite)
WidgetCenter.shared.reloadAllTimelines()
collectionView.performBatchUpdates {
Expand All @@ -168,6 +169,7 @@ class FavoritesHomeViewSectionRenderer {
guard let indexPath = collectionView.indexPath(for: cell),
let favorite = viewModel.favorite(at: indexPath.row) else { return }
Pixel.fire(pixel: .homeScreenEditFavorite)
fireActionPixel()
controller?.favoritesRenderer(self, didRequestEdit: favorite)
}

Expand Down Expand Up @@ -272,7 +274,7 @@ class FavoritesHomeViewSectionRenderer {
let dragItem = coordinator.items.first?.dragItem,
let sourcePath = coordinator.items.first?.sourceIndexPath,
let destinationPath = coordinator.destinationIndexPath,
let cell = self.collectionView(collectionView, cellForItemAt: sourcePath) as? FavoriteHomeCell,
let cell = collectionView.cellForItem(at: sourcePath) as? FavoriteHomeCell,
let favorite = cell.favorite
else { return }

Expand All @@ -285,10 +287,11 @@ class FavoritesHomeViewSectionRenderer {

coordinator.drop(dragItem, toItemAt: destinationPath)

fireActionPixel()
}

func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
guard let cell = self.collectionView(collectionView, cellForItemAt: indexPath) as? FavoriteHomeCell else { return [] }
guard let cell = collectionView.cellForItem(at: indexPath) as? FavoriteHomeCell else { return [] }

if let size = cell.iconImage.image?.size.width, size <= 32 {
cell.iconBackground.backgroundColor = ThemeManager.shared.currentTheme.backgroundColor
Expand All @@ -314,4 +317,9 @@ class FavoritesHomeViewSectionRenderer {
return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}

/// Actions are only available from the bookmarks UI, so this is safe to send from here.
func fireActionPixel() {
DailyPixel.fire(pixel: .bookmarksUIFavoritesAction)
}

}

0 comments on commit 95897a7

Please sign in to comment.