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

Commit

Permalink
Fix #3235: Implement NTP-SI confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Feb 17, 2021
1 parent 862f3a7 commit ca0fbd2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Client/Frontend/Browser/HomePanel/NTPModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ class NTPBackground: Codable {
/// Required instead of `CGPoint` due to x/y being optionals
let focalPoint: FocalPoint?

// Only available for sponsored images, not normal wallpapers
let creativeInstanceId: String

/// Only available for normal wallpapers, not for sponsored images
let credit: Credit?

/// Whether the background is a packaged resource or a remote one, impacts how it should be loaded
let packaged: Bool?

init(imageUrl: String, focalPoint: FocalPoint?) {
init(imageUrl: String, focalPoint: FocalPoint?, creativeInstanceId: String) {
self.imageUrl = imageUrl
self.focalPoint = focalPoint
self.creativeInstanceId = creativeInstanceId
self.credit = nil
self.packaged = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ class NTPDownloader {
basePath: URL) -> [NTPBackground] {
backgrounds.map {
NTPBackground(imageUrl: basePath.appendingPathComponent($0.imageUrl).path,
focalPoint: $0.focalPoint)
focalPoint: $0.focalPoint,
creativeInstanceId: $0.creativeInstanceId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ class NewTabPageBackground: PreferencesObserver {
/// The current background image & possibly sponsor
private(set) var currentBackground: (wallpaper: NTPBackground, type: NTPDataSource.BackgroundType)? {
didSet {
wallpaperId = UUID()
changed?()
}
}
/// A unique wallpaper identifier
private(set) var wallpaperId: UUID?
/// The background/wallpaper image if available
var backgroundImage: UIImage? {
currentBackground?.wallpaper.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class NewTabPageViewController: UIViewController, Themeable {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

reportSponsoredImageBackgroundEvent(.viewed)
presentNotification()
}

Expand Down Expand Up @@ -392,6 +393,20 @@ class NewTabPageViewController: UIViewController, Themeable {
backgroundView.imageConstraints?.landscapeCenter.update(offset: inset)
}

private func reportSponsoredImageBackgroundEvent(_ event: NewTabPageAdEventType) {
guard let backgroundType = background.currentBackground?.type,
case .withBrandLogo = backgroundType,
let wallpaperId = background.wallpaperId?.uuidString,
let creativeInstanceId = background.currentBackground?.wallpaper.creativeInstanceId else {
return
}
rewards.ads.reportNewTabPageAdEvent(
wallpaperId,
creativeInstanceId: creativeInstanceId,
eventType: event
)
}

// MARK: - Notifications

private var notificationController: UIViewController?
Expand Down Expand Up @@ -665,6 +680,8 @@ class NewTabPageViewController: UIViewController, Themeable {
private func tappedSponsorButton(_ logo: NTPLogo) {
UIImpactFeedbackGenerator(style: .medium).bzzt()
delegate?.navigateToInput(logo.destinationUrl, inNewTab: false, switchingToPrivateMode: false)

reportSponsoredImageBackgroundEvent(.clicked)
}

private func tappedQRCode(_ code: String) {
Expand Down

0 comments on commit ca0fbd2

Please sign in to comment.