Mediator SDK Integration
Banner ads and Interstitial ads from the Amazon Mobile Ad Network can also be retrieved through select mediator SDKs. General guidelines for integration are listed below.
Integrating through Amazon Mediation Adapters
To simplify the integration process the SDK is now distributed with adapters and sample apps for integrating with select mediator SDKs.
Executing Sample Apps
The sample apps provided for mediation adapters are implemented to easily import into Android Studio for testing. After downloading the SDK, the adapters directory contains a folder for each mediator supported by Amazon. From Android Studio, select “Import project”. Through the file browser select the directory for the desired sample app. The sample apps are implemented using gradle with JCenter so they do not require additional steps to incorporate the SDK into the project. Follow the instructions below for integrating the adapter with the sample app.
To display Amazon ads through an adapter, your application must include the Amazon Ads SDK. Follow the directions in the Quick Start Guide for integrating the Amazon Ads SDK into your application. Rather than implementing the steps for adding the amazon ad to your app follow the directions below for adding the adapter source code.
Note: MoPub adapters are supported for Amazon Ads SDK version 5.7.1 and above. This is a custom adapter that is solely supported by Amazon. Please contact Amazon for any questions.
In order for your application to load Amazon ads through the MoPub adapter your application must include the MoPub SDK. Follow the integration instructions provided by MoPub.
Adding the Adapter Source Code
First, create a java package "com.mopub.mobileads" in the sample application. Note that MoPub requires adapter code to be in the "com.mopub.mobileads" package. Once the package is created, copy the java source file for the desired adapter(s) into the java package.
For banner ads, it is recommended to configure the MoPubView with layout_width as match_parent and layout_height as wrap_content to allow support for Auto Ad Size.
<com.mopub.mobileads.MoPubView android:id="@+id/adview" android:layout_width="match_parent" android:layout_height="wrap_content" />
To display Amazon banner ads through MoPub, the MoPub web interface needs to be configured to execute the Amazon banner ads adapter. Loading Amazon ads requires the creation of a “Custom Native Network”, see the MoPub documentation for setting up a Custom Native Network. Once the network is created, the “Custom Event Class” column will need to be populated with the adapter class “com.mopub.mobileads.AmazonEventBanner”. See “MoPub Custom Event Class Data”, below, for information on adapter parameters that can be setup through the MoPub server.
After the MoPub web interface is configured to call the Amazon adapter, your application will need to execute the MoPub banner ad implementation. Follow the instructions for displaying a MoPub banner ad here.
To display Amazon interstitial ads through MoPub, the MoPub web interface needs to be configured to execute the Amazon banner ads adapter. Loading Amazon ads requires the creation of a “Custom Native Network”, see the MoPub documentation for setting up a Custom Native Network. Once the network is created, the “Custom Event Class” column will need to be populated with the adapter class “com.mopub.mobileads.AmazonEventInterstitial”. See “MoPub Custom Event Class Data”, below, for information on adapter parameters that can be setup through the MoPub server.
After the MoPub web interface is configured to call the Amazon adapter, your application will need to execute the MoPub interstitial ad implementation. Follow the instructions for displaying a MoPub interstitial ad here.
MoPub Custom Event Class Data
The “Custom Event Class Data” should be populated with the following JSON:
The fields available are as follows:
· appKey – Your Amazon application id for loading ads.
· advOptions – JSON representation of a key-value map used for AdTargetingOptions.
· testingEnabled – Enables testing mode for your application. This should be true when testing integration with the Amazon Ad SDK and false in your production application.
· loggingEnabled – Enables Amazon’s Ad SDK logging to display detailed logging for debugging and testing.
· geolocationEnabled – Enables latitude and longitude data to be submitted with each ad request. Note that enabling geolocation requires your application to have ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions
The only required field in the JSON configuration is the appKey, without it your application will be unable to load ads. The advOptions field will have no effect if omitted or empty. The remaining fields, testingEnabled, loggingEnabled, and geolocationEnabled, will be set to false if they are not specified.
Banner ads have one additional field, scalingEnabled, which tells the SDK whether to scale the ad to the device’s screen size. The default and recommended functionality is to have scaling disabled.
Integrating with Other Mediator SDKs
Note: The following guidelines only apply to users attempting to load banner ads from the Amazon Mobile Ad Network through a third-party mediator SDK.
1) Apps that reload ads in such a way that new ads replace existing ads on the same screen (for example, apps that reload ads on a time interval) will need to take special measures to ensure that new ads cannot load while the user is already interacting with an expanded rich media ad. This can be accomplished in a number of ways:
- (RECOMMENDED) Introduce logic to prevent ad loading actions from initiating if an ad has expanded. For example, you can define a boolean variable
isExpandedthat is set to true upon ad expansion and set to false upon ad collapse, and you can then check to make sure that
isExpandedequals false as a condition for requesting an ad from the mediator SDK. You will need to combine this solution with one of the others listed below to handle the case where an ad begins loading before the current ad is expanded.
- (RECOMMENDED) Load new ads in a separate, invisible ad view, swapping that ad view with the current one only after the ad has finished loading. We recommend you combine this solution with the above solution to ensure that new ads do not begin loading while the current ad is expanded.
- (RECOMMENDED) Remove automatic ad refresh behavior except in cases where the parent view is destroyed.
- Destroy the existing ad view when loading a new ad.
- Disable clicking while an ad is in the process of loading, and re-enable only after a new ad has loaded.
2) You must ensure that the
AdActivity activity is declared in your
AndroidManifest.xml file. See Step 2 of the Quick Start Guide for details.
3) Remember that all apps utilizing the Amazon Mobile Ad Network, even those that do so through a mediator's SDK, must pass the criteria outlined in the Developer Launch Checklist prior to submission. You will need to contact your mediator to enable Amazon Test ads before testing starts, and you will also need to contact your mediator to disable Amazon Test ads after testing has been completed. Please contact your mediator for specific supplemental information regarding integrating the Amazon Mobile Ad Network through its SDK.
Loading Ads from Multiple SDKs
The Amazon Mobile Ads API for Android can be used in conjunction with other advertising SDKs. We recommend providing the Amazon Mobile Ad Network with the first look. Before loading an Amazon Ad you'll want to implement an
AdListener, which has callbacks for success and failure. If no ads were available from the Amazon Mobile Ad Network, then the
AdListener.onAdFailedToLoad callback method can be used to call another ad SDK.
Below is a simple example of a program that first tries to load an ad from the Amazon Ad Network. On failure, it makes a second ad request via AdMob's SDK.