Skip to content

Commit

Permalink
Add FXIOS-10719 [sponsored tiles] Integrate clicks and impressions (#…
Browse files Browse the repository at this point in the history
…23477)

Integrate clicks and impressions
  • Loading branch information
lmarceau authored Nov 29, 2024
1 parent b421b9a commit 3e5b6f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions firefox-ios/Client/Frontend/Home/TopSites/TopSite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Storage
import Shared

// Top site UI class, used in the home top site section
final class TopSite {
final class TopSite: FeatureFlaggable {
var site: Site
var title: String

Expand Down Expand Up @@ -52,11 +52,15 @@ final class TopSite {

// MARK: Telemetry

func impressionTracking(position: Int) {
func impressionTracking(position: Int, unifiedAdsTelemetry: UnifiedAdsCallbackTelemetry) {
// Only sending sponsored tile impressions for now
guard let tile = site as? SponsoredTile else { return }

SponsoredTileTelemetry.sendImpressionTelemetry(tile: tile, position: position)
if featureFlags.isFeatureEnabled(.unifiedAds, checking: .buildOnly) {
unifiedAdsTelemetry.sendImpressionTelemetry(tile: tile)
} else {
SponsoredTileTelemetry.sendImpressionTelemetry(tile: tile, position: position)
}
}

func getTelemetrySiteType() -> String {
Expand Down
13 changes: 10 additions & 3 deletions firefox-ios/Client/Frontend/Home/TopSites/TopSitesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class TopSitesViewModel {
private let topSiteHistoryManager: TopSiteHistoryManager
private let googleTopSiteManager: GoogleTopSiteManager
private var wallpaperManager: WallpaperManager
private let unifiedAdsTelemetry: UnifiedAdsCallbackTelemetry

init(profile: Profile,
isZeroSearch: Bool = false,
theme: Theme,
wallpaperManager: WallpaperManager) {
wallpaperManager: WallpaperManager,
unifiedAdsTelemetry: UnifiedAdsCallbackTelemetry = DefaultUnifiedAdsCallbackTelemetry()) {
self.profile = profile
self.isZeroSearch = isZeroSearch
self.theme = theme
Expand All @@ -49,6 +51,7 @@ class TopSitesViewModel {
googleTopSiteManager: googleTopSiteManager)
topSitesDataAdaptor = adaptor
self.wallpaperManager = wallpaperManager
self.unifiedAdsTelemetry = unifiedAdsTelemetry
adaptor.delegate = self
}

Expand All @@ -61,7 +64,7 @@ class TopSitesViewModel {

func sendImpressionTelemetry(_ homeTopSite: TopSite, position: Int) {
guard !hasSentImpressionForTile(homeTopSite) else { return }
homeTopSite.impressionTracking(position: position)
homeTopSite.impressionTracking(position: position, unifiedAdsTelemetry: unifiedAdsTelemetry)
}

private func topSitePressTracking(homeTopSite: TopSite, position: Int) {
Expand Down Expand Up @@ -91,7 +94,11 @@ class TopSitesViewModel {

// Sponsored tile specific telemetry
if let tile = homeTopSite.site as? SponsoredTile {
SponsoredTileTelemetry.sendClickTelemetry(tile: tile, position: position)
if featureFlags.isFeatureEnabled(.unifiedAds, checking: .buildOnly) {
unifiedAdsTelemetry.sendClickTelemetry(tile: tile)
} else {
SponsoredTileTelemetry.sendClickTelemetry(tile: tile, position: position)
}
}
}

Expand Down

0 comments on commit 3e5b6f2

Please sign in to comment.