Back to Bidding-Only Integration
Integration example:
First, prepare the set of requested assets.
private var nativeRequestAssets: [NativeAsset] {
let image = NativeAssetImage(minimumWidth: 200, minimumHeight: 50, required: true)
image.type = ImageAsset.Main
let icon = NativeAssetImage(minimumWidth: 20, minimumHeight: 20, required: true)
icon.type = ImageAsset.Icon
let title = NativeAssetTitle(length: 90, required: true)
let body = NativeAssetData(type: DataAsset.description, required: true)
let cta = NativeAssetData(type: DataAsset.ctatext, required: true)
let sponsored = NativeAssetData(type: DataAsset.sponsored, required: true)
return [title, icon, image, sponsored, body, cta]
}
Then integrate the native style ad using GAM Banner ad unit
// 1. Create NativeRequest
nativeUnit = NativeRequest(configId: CONFIG_ID, assets: nativeRequestAssets)
nativeUnit.context = ContextType.Social
nativeUnit.placementType = PlacementType.FeedContent
nativeUnit.contextSubType = ContextSubType.Social
nativeUnit.eventtrackers = eventTrackers
// 2. Create GAMBannerView
gamBannerView = GAMBannerView(adSize: GADAdSizeFluid)
gamBannerView.adUnitID = storedImpNativeStyleBanner
gamBannerView.rootViewController = self
gamBannerView.delegate = self
bannerView.addSubview(gamBannerView)
// 3. Make a bid request
nativeUnit.fetchDemand(adObject: gamRequest) { [weak self] resultCode in
PrebidDemoLogger.shared.info("Prebid demand fetch for GAM \(resultCode.name())")
// 4. Load and GAM ad
self?.gamBannerView.load(self?.gamRequest)
}
Initialize the NativeRequest
with properties:
configId
- an ID of the Stored Impression on the Prebid Serverassets
- the array of NativeAsset
objects which describes your native ad.Type | Scope | Description |
---|---|---|
Main | Optional | The image that will be displayed in the native ad. Include a value for minimumWidth and minimumHeight . Ensure that the NativeAssetImage.type is set to ImageAsset.Main |
Icon | Optional | The icon that will be displayed with the native ad. Include a value for minimumWidth and minimumHeight . Ensure that the NativeAssetImage.type is set to ImageAsset.Icon. |
Type | Scope | Description |
---|---|---|
Description | Optional | The content to appear with the ad. Ensure that the type is set to DataAsset.description . |
ctatext | Optional | The text for the call to action button of the native ad. Ensure that the type is set to DataAsset.ctatext . |
Sponsored | Optional | The sponsor (brand) of the native ad. Ensure that the type is set to DataAsset.sponsored . |
Type | Scope | Description |
---|---|---|
Title | Optional | The title of the native ad. |
Using the NativeParameters
object (with the PrebidRequest object) or the NativeRequest
object, you can customize the bid request for native ads.
The array of requested asset objects. Prebid SDK supports all kinds of assets according to the IAB spec except video
.
The array of requested native trackers. Prebid SDK supports inly image
trackers according to the IAB spec.
Version of the Native Markup version in use. The default value is 1.2
The context in which the ad appears.
A more detailed context in which the ad appears.
The design/format/layout of the ad unit being offered.
The number of identical placements in this Layout.
0 for the first ad, 1 for the second ad, and so on.
Whether the supply source/impression supports returning an assetsurl instead of an asset object. 0 or the absence of the field indicates no such support.
Whether the supply source / impression supports returning a dco url instead of an asset object. 0 or the absence of the field indicates no such support.
Set to 1 when the native ad supports buyer-specific privacy notice. Set to 0 (or field absent) when the native ad doesn’t support custom privacy links or if support is unknown.
This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility beyond the standard defined in this specification
Just follow the GMA SDK documentation to integrate a banner ad unit.
The fetchDemand
method makes a bid request to the Prebid Server. You should provide a GAMRequest
object to this method so Prebid SDK sets the targeting keywords of the winning bid for future ad requests.
You should now request the ad from GAM. If the GAMRequest
contains targeting keywords the respective Prebid line item will be returned from GAM and GMA SDK will render its creative.
Be sure that you make the ad request with the same GAMRequest
object that you passed to the fetchDemand
method. Otherwise the ad request won’t contain targeting keywords and Prebid’s ad won’t ever be displayed.