-
Notifications
You must be signed in to change notification settings - Fork 3
Adnuntius Advertising
The way the SDK generates visible and viewable events is changing starting with SDK version 1.7.0
https://github.com/Adnuntius/android_sdk/wiki/Visible-and-Viewable-Event-Handling
<com.adnuntius.android.sdk.AdnuntiusAdWebView
android:id="@+id/adView"
android:layout_width="354dp"
android:layout_height="244dp"
android:layout_alignBottom="@+id/swipeRefreshLayout"
android:layout_centerHorizontal="true"
tools:ignore="MissingConstraints" />In the Activity class load the web view in the onCreate (after calling setContentView), and then load the ad in the onResume, this will ensure that ads are reloaded when the app is paused and resumed.
The loadAd method accepts a CompletionHandler. This completion handler callback will be called asynchronously when the ad is either loaded into the webview or not, or when an error occurs.
A basic api for simple ad integrations, uses adn.js internally to render the ad and fire off all the right events.
@Override
protected void onResume() {
super.onResume();
AdRequest request = new AdRequest("000000000006f450")
.noCookies()
.addKeyValue("version", "4.3");
adView.loadAd(request, false,
new LoadAdHandler() {
@Override
public void onAdResponse(AdnuntiusAdWebView view, AdResponseInfo info) {
}
@Override
public void onNoAdResponse(AdnuntiusAdWebView view) {
// do something where no ad matches
}
@Override
public void onFailure(AdnuntiusAdWebView view, String error) {
// do something on failure
}
});
}Its now possible to close a web view from an adnuntius layout via javascript.
If you want to be able to close ad view from javascript, its not possible to close the parent window from a layout due to the dreaded Scripts may close only the windows that were opened by them. So we have added a new method you can call from javascript which provides this functionality:
if (typeof parent.adnSdkHandler != "undefined") {
parent.adnSdkHandler.closeView();
}And the corresponding method in the LoadAdHandler:
@Override
public void onLayoutCloseView(AdnuntiusAdWebView view) {
finish();
}This is probably mostly useful for development, but if you want to force a line item / creative combo to appear in your web view.
AdRequest request = new AdRequest("000000000006f450")
.setWidth(300)
.setHeight(200)
.livePreview("line item id", "creative id")
.noCookies()
.addKeyValue("version", "4.3");Possible to configure parent request parameters such as userId, sessionId and consentString into an ad request.
These values are passed onto the ad server request.
- https://docs.adnuntius.com/adnuntius-advertising/requesting-ads/intro/adn-request#userid
- https://docs.adnuntius.com/adnuntius-advertising/requesting-ads/intro/adn-request#sessionid
- https://docs.adnuntius.com/adnuntius-advertising/requesting-ads/intro/adn-request#consentstring
You can also specify other parent request parameters, such as gdpr:
AdRequest request = new AdRequest("000000000006f450")
.livePreview("line item id", "creative id")
.userId("some user id")
.sessionId("some user id")
.consentString("some consent string")
.parentParameter("gdpr", "0")
.noCookies()
.addKeyValue("version", "4.3");An example app is available here: https://github.com/Adnuntius/android_sdk_examples