(Can be used on v2.9.1 or later)
RFP iOS SDK provides API RFPVisibilityTracker
to support viewable impression for advertisements.
Please call RFPVisibilityTracker.init(startTrackingAdView: UIView, infoModel: RFPInstreamInfoModel)
and pass in the advertisement’s UIView instance and RFPInstreamInfoModel’s instance which keeps your advertisement’s data to init the tracker for tracking the advertisement’s viewable impression. The tracker will send impression event from the SDK when the advertisement satisfy the viewable impression conditions.
We use NSTimer in RFPVisibilityTracker
. Please deallocate RFPVisibilityTracker
’s instance when deinit is called.
class YourViewController: UIViewController, RFPInstreamAdLoaderDelegate {
//for tracking adView's visibility impression
var visibilityTracker: RFPVisibilityTracker?
//a uiview for displaying ad's contents
var adView: UIView
//Ad's data for displaying
var infoModel: RFPInstreamInfoModel
//Add ad's uiview to your view hierarchy
func addAdView() {
self.view.addSubview(adView)
}
.
.
.
//Add ad's uiview and data to track ad's view's visibility
func startToTrackAdView() {
self.visibilityTracker = RFPVisibilityTracker.init(startTrackingAdView: yourAdView, infoModel: yourAdInfoModel)
}
//Must set tracker to nil when stop tracking
deinit {
self.visiblilityTracker = nil
}
}
Impression’s results could be received by set RFPVisibilityTrackerDelegate
.
override func viewDidLoad() {
super.viewDidLoad()
// (1) set delegate
visibilityTracker.delegate = self
}
// (2) called when imp sent finished
func rfpVisibilityTrackerDidSentImp() {
}
// (3) called when imp sent failed
func rfpVisibilityTrackerFailedToSendImpWithError(_ error: Error!) {
}