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

Track burl and nurl in Rendering API #1075

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions PrebidMobile/AdUnits/Native/NativeAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,39 @@ public class NativeAd: NSObject, CacheExpiryDelegate {
return nil
}

let macrosHelper = PBMORTBMacrosHelper(bid: rawBid)
rawBid.adm = macrosHelper.replaceMacros(in: rawBid.adm)
rawBid.nurl = macrosHelper.replaceMacros(in: rawBid.nurl)
let bid = Bid(bid: rawBid)

let ad = NativeAd()

let internalEventTracker = PrebidServerEventTracker()

if let impURL = rawBid.ext.prebid?.events?.imp {
if let impURL = bid.events?.imp {
let impEvent = ServerEvent(url: impURL, expectedEventType: .impression)
internalEventTracker.addServerEvents([impEvent])
}

if let winURL = rawBid.ext.prebid?.events?.win {
if let burl = bid.burl {
let billingEvent = ServerEvent(url: burl, expectedEventType: .impression)
internalEventTracker.addServerEvents([billingEvent])
}

if let winURL = bid.events?.win {
let winEvent = ServerEvent(url: winURL, expectedEventType: .prebidWin)
internalEventTracker.addServerEvents([winEvent])
}

if let nurl = bid.nurl {
let noticeEvent = ServerEvent(url: nurl, expectedEventType: .prebidWin)
internalEventTracker.addServerEvents([noticeEvent])
}

ad.eventManager.registerTracker(internalEventTracker)

// Track win event immediately
ad.eventManager.trackEvent(.prebidWin)

guard let nativeAdMarkup = NativeAdMarkup(jsonString: rawBid.adm) else {
Log.warn("Can't retrieve native ad markup from bid response.")
Log.error("SDK couldn't retrieve native ad markup from bid response.")
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ - (void)makeCreativesWithCreativeModels:(NSArray<PBMCreativeModel *> *)creativeM
self.currentTransaction = [[PBMTransaction alloc] initWithServerConnection:self.connection
adConfiguration:self.adConfiguration
models:creativeModels];

self.currentTransaction.skadnInfo = self.bid.skadn;
self.currentTransaction.impURL = self.bid.events.imp;
self.currentTransaction.winURL = self.bid.events.win;

self.currentTransaction.bid = self.bid;

self.currentTransaction.delegate = self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ - (instancetype)initWithCreativeModel:(PBMCreativeModel *)creativeModel
}

if(@available(iOS 14.5, *)) {
if (self.transaction.skadnInfo) {
SKAdImpression *imp = [PBMSkadnParametersManager getSkadnImpressionFor:self.transaction.skadnInfo];
if (self.transaction.bid.skadn) {
SKAdImpression *imp = [PBMSkadnParametersManager getSkadnImpressionFor:self.transaction.bid.skadn];
if (imp) {
PBMSkadnEventTracker *skadnTracker = [[PBMSkadnEventTracker alloc] initWith:imp];
[self.eventManager registerTracker:(id<PBMEventTrackerProtocol>) skadnTracker];
Expand All @@ -93,20 +93,27 @@ - (instancetype)initWithCreativeModel:(PBMCreativeModel *)creativeModel

PrebidServerEventTracker *internalEventTracker = [[PrebidServerEventTracker alloc] initWithServerEvents:@[]];

NSString *impURL = self.transaction.impURL;
NSString *impURL = self.transaction.bid.events.imp;

if (impURL) {
PBMServerEvent *impEvent = [[PBMServerEvent alloc] initWithUrl:impURL expectedEventType:PBMTrackingEventImpression];
[internalEventTracker addServerEvents:@[impEvent]];
}

NSString *winURL = self.transaction.winURL;
NSString *winURL = self.transaction.bid.events.win;

if (winURL) {
PBMServerEvent *winEvent = [[PBMServerEvent alloc] initWithUrl:winURL expectedEventType:PBMTrackingEventPrebidWin];
[internalEventTracker addServerEvents:@[winEvent]];
}

NSString * burl = self.transaction.bid.burl;

if (burl) {
PBMServerEvent *billingEvent = [[PBMServerEvent alloc] initWithUrl:burl expectedEventType:PBMTrackingEventImpression];
[internalEventTracker addServerEvents:@[billingEvent]];
}

if (internalEventTracker.serverEvents.count > 0) {
[self.eventManager registerTracker:(id<PBMEventTrackerProtocol>) internalEventTracker];
}
Expand Down Expand Up @@ -227,7 +234,7 @@ - (void)handleClickthrough:(NSURL*)url
return;
}
BOOL clickthroughOpened = NO;
PBMJsonDictionary * skadnetProductParameters = [PBMSkadnParametersManager getSkadnProductParametersFor:self.transaction.skadnInfo];
PBMJsonDictionary * skadnetProductParameters = [PBMSkadnParametersManager getSkadnProductParametersFor:self.transaction.bid.skadn];

if (skadnetProductParameters) {
clickthroughOpened = [self handleProductClickthrough:url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@protocol PBMTransactionDelegate;

@class Bid;
@class WKWebView;
@class UIView;
@class PBMModalManager;
Expand All @@ -41,9 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, nullable) PBMOpenMeasurementSession *measurementSession;
@property (nonatomic, strong) PBMOpenMeasurementWrapper *measurementWrapper;

@property (nonatomic, strong, nullable) PBMORTBBidExtSkadn *skadnInfo;
@property (nonatomic, strong, nullable) NSString *impURL; // bidResponse.ext.prebid.events.imp
@property (nonatomic, strong, nullable) NSString *winURL; // bidResponse.ext.prebid.events.win
@property (nonatomic, strong, nullable) Bid * bid;

@property (atomic, weak, nullable) id<PBMTransactionDelegate> delegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ @interface PBMCreativeViewabilityTracker()

@implementation PBMCreativeViewabilityTracker

- (instancetype)initWithView:(UIView *)view pollingTimeInterval:(NSTimeInterval)pollingTimeInterval onExposureChange:(PBMViewExposureChangeHandler)onExposureChange {
- (instancetype)initWithView:(UIView *)view
pollingTimeInterval:(NSTimeInterval)pollingTimeInterval
onExposureChange:(PBMViewExposureChangeHandler)onExposureChange {
self = [super init];
if (self) {
_checker = [[PBMViewExposureChecker alloc] initWithView:view];
Expand All @@ -74,7 +76,6 @@ - (instancetype)initWithCreative:(PBMAbstractCreative *)creative {
onExposureChange:^(PBMCreativeViewabilityTracker *tracker, PBMViewExposure *viewExposure)
{
@strongify(creative);
// BOOL const isVisible = viewExposure.exposureFactor > 0;
BOOL isVisible = [tracker isVisibleView:tracker.testedView];
[creative onViewabilityChanged:isVisible viewExposure:viewExposure];
}]) {
Expand Down
7 changes: 7 additions & 0 deletions PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/Bid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class Bid: NSObject {
/// Substitution macros (Section 4.4) may be included in both the URL and optionally returned markup.
@objc public private(set) var nurl: String?

/// Billing notice URL called by the exchange when a winning bid
/// becomes billable based on exchange-specific business policy
/// (e.g., typically delivered, viewed, etc.).
@objc public var burl: String? {
bid.burl
}

/// Optional means of conveying ad markup in case the bid wins; supersedes the win notice
/// if markup is included in both.
/// Substitution macros (Section 4.4) may be included.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ - (void)loadHTMLTransaction:(NSString *)adMarkup {
adConfiguration:self.adConfiguration.adConfiguration
models:creativeModels];

self.transaction.skadnInfo = self.bid.skadn;
self.transaction.impURL = self.bid.events.imp;
self.transaction.winURL = self.bid.events.win;
self.transaction.bid = self.bid;

self.transaction.delegate = self;
[self.transaction startCreativeFactory];
Expand Down