The AdUnit class is the superclass of the BannerAdUnit and InterstitialAdUnit classes.
Create a new Banner Ad Unit or Interstitial Ad Unit with a Prebid Server configuration ID and a banner size if applicable.
Parameters
configId
: String containing the Prebid Server configuration ID.
size:
: CGSize conatining width and height of the AdUnit.
Properties
prebidConfigId
: String containing the Prebid Server configuration ID.
adSizes
: An Array of CGSizes to be used for AdUnit sizes.
Trigger a call to Prebid Server to retrieve demand for this Prebid Mobile ad unit.
Parameters
adObject
: adServer object to which the Prebid keys need to be attached.
completion
: Closure which receives one argument, the enum ResultCode
. There is no return value.
Obtains the user keyword and value for targeting of a Prebid Mobile ad unit. If the key already exists the value will be appended to the customKeywords
property. No duplicates will be added.
Parameters
key
: A String to be used to check if an existing value exists in the customKeywords
property.
value
: A String to be appended to the customKeywords
property.
Remove a key and all its associated values from customKeywords
of a given Prebid Mobile ad unit.
Parameters
forKey
: A string containing the key to remove from customKeywords
.
Remove all keys and all values from a given Prebid Mobile ad unit. </div>
If set on a given Prebid Mobile ad unit, the fetchDemand
function will be called every periodMillis
until stopAutoRefresh
is called. Each call to fetchDemand
will invoke the onComplete
function. This refresh only pertains to Prebid Mobile and not to any ad server refresh processes. It is suggested that the adServes refresh be turned off.
Starts the auto-refresh behavior for a given Prebid Mobile ad unit.
Halts the auto-refresh behavior for a given Prebid Mobile ad unit. If no auto-refresh behavior has been set, stopAutoRefresh
will be ignored.
Ad Unit context keywords object is a free form list of comma separated keywords about the app as defined in app.keyword in OpenRTB 2.5. The addContextKeyword
function adds a single keyword to the ad unit.
func addContextKeyword(_ newElement: String)
Ad Unit context keywords object is a free form list of comma separated keywords about the app as defined in app.keyword in OpenRTB 2.5. The addContextKeywords
function adds a multiple keyword to the ad unit.
func addContextKeywords(_ newElements: Set<String>)
func removeContextKeyword(_ element: String)
func clearContextKeywords()
First Party Data (FPD) is free form data supplied by the publisher to provide additional targeting of the user or inventory context, used primarily for striking PMP (Private MarketPlace) deals with Advertisers. Data supplied in the data parameters are typically not sent to DSPs whereas information sent in non-data objects (i.e. setYearOfBirth
, setGender
, etc.) will be. Access to FPD can be limited to a supplied set of Prebid bidders via an access control list.
Data is broken up into two different data types:
The below first party inventory context will apply to the specic ad unit the data object is applied to. For global user or inventory context level first party data, refer to first party data section of the Targeting page.
func addContextData(key: String, value: String)
Parameters
key
: string containing the key for the specific data object
value
: String containing the value for the supplied key
func updateContextData(key: String, value: Set<String>)
Parameters
key
: string containing the key for the specific data object
value
: String containing the value for the supplied key
func removeContextData(forKey: String)
Parameters
key
: string containing the key for the specific data object
value
: String containing the value for the supplied key
func clearContextData()
fetchDemand
Swift
func loadDFPBanner(bannerUnit : AdUnit){
let bannerUnit = BannerAdUnit(configId: "6ace8c7d-88c0-4623-8117-75bc3f0a2e45", size: CGSize(width: 300, height: 250))
let dfpBanner = DFPBannerView(adSize: kGADAdSizeMediumRectangle)
dfpBanner.adUnitID = "/19968336/PriceCheck_300x250"
dfpBanner.rootViewController = self
bannerView.addSubview(dfpBanner)
request.testDevices = [ kGADSimulatorID ]
// Do any additional setup after loading the view, typically from a nib.
bannerUnit.fetchDemand(adObject: self.request) { (ResultCode) in
print("Google Ad Manager banner bids fetch successfull")
dfpBanner.load(self.request)
}
}
Objective-C
-(void) loadDFPBanner {
self.bannerUnit = [[BannerAdUnit alloc] initWithConfigId:@"6ace8c7d-88c0-4623-8117-75bc3f0a2e45" size:CGSizeMake(300, 250)];
[self.bannerUnit setAutoRefreshMillisWithTime:35000];
self.dfpView = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeMediumRectangle];
self.dfpView.rootViewController = self;
self.dfpView.adUnitID = @"/19968336/PrebidMobileValidator_Banner_All_Sizes";
self.dfpView.delegate = self;
[self.bannerView addSubview:self.dfpView];
self.dfpView.backgroundColor = [UIColor redColor];
self.request = [[DFPRequest alloc] init];
self.request.testDevices = @[kDFPSimulatorID];
[self.bannerUnit fetchDemandWithAdObject:self.request completion:^(enum ResultCode result) {
NSLog(@"Prebid demand result %ld", (long)result);
dispatch_async(dispatch_get_main_queue(), ^{
[self.dfpView loadRequest:self.request];
});
}];
}
addKeyword
bannerUnit.addKeyword(key:"Sample", value:"Value to add")
removeUserKeyword
bannerUnit.removeUserKeyword(forKey:"sample")
clearUserKeywords
bannerUnit.clearUserKeywords()
setAutoRefreshMillis
bannerUnit.setAutoRefreshMillis(time:Double)
stopAutoRefresh
bannerUnit.stopAutoRefresh()
addContextKeyword
bannerAdUnit.addContextKeyword("adunitContextKeywordValue1")
bannerAdUnit.addContextKeyword("adunitContextKeywordValue2")
bannerAdUnit.addContextKeyword("adunitContextKeywordValue3")
addContextData
bannerAdUnit.addContextData(key: "adunitContextDataKey1", value: "adunitContextDataValue1")