Before You Start Make Sure:
- At least one App and Placement set up on Publisher Portal
- SDK is installed
- SDK is initialized
- Each Ad request has "Testing" status which enables it to test integrations.
1. Requesting Ads
To request an ad you should retrieve the placement object from the Controller.
Placement placement =
Controller.getInstance().getPlacement(placementId);
Note: You can find the Placement ID in your account on Developer Portal in the Application tab.
Then issue a new AdRequest object from the Placement object using the newAdRequest() method.To retrieve previously issued AdRequests, you may use the getLastAdRequest() and getAdRequestById() methods.
To execute an Ad Request call the AdRequest object’s requestAd() method.
Apply AdRequestListener to your AdRequest object to get callback with AdProvider object that enables access to the retrieved ad.
adRequest.setAdRequestListener(new AdRequestListener() {
@Override
public void onAdReceived(AdProvider adProvider) {
// integration code
}
@Override
public void onNoAds(DIOError error) {
// integration code
}
});
adRequest.requestAd();
You may add the context keywords of the application to the Ad Request.
// set content keywords
List<String> contentKeywords = new ArrayList<>();
contentKeywords.add("searching");
contentKeywords.add("computing");
adRequest.setContentKeywords(contentKeywords);
You can also set up labels for Ad Request in order to run A/B testing:
// set label(s) to ad request
String[] labels = new String[]{"blue, red"};
adRequest.setLabel(labels);
In case you are requesting Banner or Medium Rectangle ads - define the expected position of the ad on the screen as follows:
// set ad position
// 'ABOVE_THE_FOLD','BELOW_THE_FOLD'
adRequest.setPosition(Banner.Position.ABOVE_THE_FOLD);
Note: Ad Request data should be added prior to executing the Ad Request.
2. Loading Ads
On the AdRequest’s successful response the registered callback onAdReceived(AdProvider adProvider) will be called.
Load the ad by calling the AdProvider’s loadAd() method: As a best practice, you should apply an AdLoadListener to the AdProvider, in order to listen to the onLoaded and onFailedToLoad events.
adProvider.setAdLoadListener(new AdLoadListener() {
@Override
public void onLoaded(Ad ad) {
// integration code
}
@Override
public void onFailedToLoad(DIOError error) {
// integration code
}
});
try {
adProvider.loadAd();
} catch(DioSdkException e) {
// error handling
}
If the ad successfully loaded, the onLoaded() callback will be called along with the Ad object. Use reference to Ad for showing current ad to user.
Use methods getAdvertiserName() and getAdvertiserClickUrl() on Ad object to get the ad attributes if you set it within InitProperties before.
Note:
We provide GDPR compliance through the IAB’s GDPR Transparency and Consent framework. If you use a CMP that implements this IAB standard, we will be able to pick the consent state from your integrated CMP and apply it in our ad serving.
Next steps:
Now you can follow our integration guide to implement our supported Ad Units:
Comments
0 comments
Please sign in to leave a comment.