Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics: add Home, Saves, Archives and Reader impressions #1120

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PocketKit/Sources/Analytics/AppEvents/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ public extension Events {
}

public extension Events.Home {
/// User views the `Home` screen
static func homeScreenImpression() -> Impression {
return Impression(
component: .screen,
requirement: .viewable,
uiEntity: UiEntity(
.screen,
identifier: "global-nav.home"
)
)
}

/**
Fired when a card in the `Recent Saves` section scrolls into view
*/
Expand Down
12 changes: 12 additions & 0 deletions PocketKit/Sources/Analytics/AppEvents/Reader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ public extension Events {
}

public extension Events.Reader {
/// User views the `Reader` screen
static func readerScreenImpression() -> Impression {
return Impression(
component: .screen,
requirement: .viewable,
uiEntity: UiEntity(
.screen,
identifier: "article.screen"
)
)
}

/**
Fired when the user views an unsupported content cell in the `Reader`
*/
Expand Down
24 changes: 24 additions & 0 deletions PocketKit/Sources/Analytics/AppEvents/Saves.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ public extension Events {
}

public extension Events.Saves {
/// User views the `Saves` screen
static func savesScreenImpression() -> Impression {
return Impression(
component: .screen,
requirement: .viewable,
uiEntity: UiEntity(
.screen,
identifier: "global-nav.saves"
)
)
}

/// User views the `Archived Items` screen
static func archivesScreenImpression() -> Impression {
return Impression(
component: .screen,
requirement: .viewable,
uiEntity: UiEntity(
.screen,
identifier: "global-nav.archives"
)
)
}

/// Returns a ContentOpen event for a url that was opened within Saves
/// - Parameters:
/// - destination: Internal, or external, based on whether the content was opened in the reader or web view, respectively
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class ReadableViewController: UIViewController {
PocketTipEvents.showSwipeHighlightsTip.sendDonation()
displayTip(SwipeHighlightsTip(), configuration: nil, sourceView: nil)
}
readableViewModel.trackReaderScreenImpression()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ extension ReadableViewModel {

// MARK: - Analytics
extension ReadableViewModel {
/// Reader screen viewed
func trackReaderScreenImpression() {
tracker.track(event: Events.Reader.readerScreenImpression())
}
/// track when user views unsupported content cell
func trackUnsupportedContentViewed() {
tracker.track(event: Events.Reader.unsupportedContentViewed(url: url))
Expand Down
5 changes: 5 additions & 0 deletions PocketKit/Sources/PocketKit/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ class HomeViewController: UIViewController {
handleRefresh {}
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
model.trackHomeScreenImpression()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
9 changes: 8 additions & 1 deletion PocketKit/Sources/PocketKit/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ private extension HomeViewModel {
}
}

// MARK: Recommendations - Editor's Picks widget
// MARK: Recommendations - Recommendations widget
private extension HomeViewModel {
func updateRecommendationsWidget() {
guard let sections = recomendationsController.sections, !sections.isEmpty else {
Expand All @@ -1139,3 +1139,10 @@ private extension HomeViewModel {
recommendationsWidgetUpdateService.update([:])
}
}

// MARK: Screen impression
extension HomeViewModel {
func trackHomeScreenImpression() {
tracker.track(event: Events.Home.homeScreenImpression())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ struct HomeActions {

// MARK: Analytics
extension HomeActions {
func trackHomeScreenImpression() {
Task(priority: .background) {
let tracker = await Services.shared.tracker
tracker.track(event: Events.Home.homeScreenImpression())
}
}
func trackCardImpression(_ info: AnalyticsInfo) {
Task(priority: .background) {
let tracker = await Services.shared.tracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ struct HomeView: View {
.refreshable {
await homeActions.refreshRecommendations(isForced: true)
}
.onAppear {
homeActions.trackHomeScreenImpression()
}
.contentMargins(.bottom, -32)
.scrollIndicators(.hidden)
.background(Color(.ui.white1))
Expand Down
3 changes: 0 additions & 3 deletions PocketKit/Sources/PocketKit/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public struct MainView: View {
.sheet(isPresented: $model.isPresentingHooray) {
PremiumUpgradeSuccessView()
}
.task {
model.trackPremiumUpsellViewed()
}
}

func makeUIKitHome() -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ItemsListViewController<ViewModel: ItemsListViewModel>: UIViewController,
PocketTipEvents.showSwipeArchiveTip.sendDonation()
displayTip(SwipeArchiveTip(), configuration: nil, sourceView: nil)
}
model.trackScreenImpression()
}

override func loadView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ protocol ItemsListViewModel: AnyObject {
func prefetch(itemsAt: [IndexPath])

func reloadSnapshot(for identifiers: [ItemsListCell<ItemIdentifier>])

func trackScreenImpression()
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ class SavedItemsListViewModel: NSObject, ItemsListViewModel {
return snapshot
}

func trackScreenImpression() {
switch viewType {
case .saves:
tracker.track(event: Events.Saves.savesScreenImpression())
case .archive:
tracker.track(event: Events.Saves.archivesScreenImpression())
}
}

func willDisplay(_ cell: ItemsListCell<NSManagedObjectID>) {
if case .item = cell {
withSavedItem(from: cell) { [weak self] item in
Expand Down