This article is for publishers who want to use the DT FairBid SDK to load and display ads from Amazon Publisher Services (APS).
APS currently supports the following ad types:
- Banner
- Interstitial
- Rewarded
For more information about the varioius types of ads and their specifications, see Ad Types and Specifications.
To integrate APS as an mediated ad network with DT:
- Step 1: Retrieve APS Information.
- Step 2: Add APS as a mediated network.
- Step 3: Initialize the APS SDK.
- Step 4: Add the APS SDK to your integration.
- Step 5: Test your integration.
Step 1: Retrieve APS Information
Before retrieving your APS information, complete the following tasks to create APS ad unit inventory to mediate with DT. For more information about how to create APS inventory, see the APS Portal documentation.
- Create an APS account.
Note
Amazon Publisher Services (APS) is an invitation-only program. To create an APS account, request an invitation from APS. Once approved, APS sends an invitation with instructions on creating an your APS account.
- Add your app to the APS Portal.
- Add Slots for your app.
- Update your
App-ads.txt
file to include the APS Portal.
Once you have created APS inventory, locate the following information in the APS Portal. This information is required later in Step 2 to set up APS as a DT mediated network.
APS INFO | DESCRIPTION | RETRIEVAL INSTRUCTIONS |
---|---|---|
Price Point Mapping | CSV file containing ad unit pricing. | Download CSV file. For more information about where to find the file, see the APS Portal documentation. |
UUID |
Unique ID assigned to your APS ad slot. | For more information about how to locate UUIDs, see the APS Portal documentation on UUIDs. |
Step 2: Add APS as a Mediated Network
Before you add APS as a DT mediated network:
- Ensure that you have access to the APS Portal information you retrieved in Step 1.
- Add your App to the DT Console. For more information about how to add an app in the DT Console, see Adding Your App.
- Ensure that you have a DT Placement for each APS ad type you want to mediate with DT. For more information about adding placements in the DT Console, see Creating Placements.
To add APS as a DT mediated network:
- Log in to the DT Console, and click App Management.
- Using the APS Price Point CSV file you downloaded in Step 1, add APS as a mediated network for your app. For more information about how to add a mediated network, see Adding Mediated Networks.
Note
DT uses the price point mapping across your entire account. If you update your price points in APS, ensure that you upload an updated CSV file in the DT Console.
- For each Placement that you want to mediate with DT, create an ad network instance for APS with the following settings:
- Use the APS UUID you retrieved in Step 1 as the Instance ID.
- Turn off the Auto CPM function. For more information about how to turn off Auto CPM, see Auto CPM.
For more information about how to add instances to a Placement, see Creating Instances.
Step 3: Initialize the APS SDK
Initialize the APS SDK within your app so that DT can mediate your APS inventory.
Initializing the APS SDK on iOS
The following process is recommended for initializing the APS SDK in Objective–C implementations on the iOS platform.
- Start the FairBid SDK.
+ [FairBid startWithAppId:options:]
- Start the APS SDK with the
APP_KEY
from the APS Portal.
- [DTBAds setAppKey:<<APP_KEY>>];
- Create an object that conforms to the
id <FYBAPSSlotLoader>
protocol, and assign it to the[FairBid apsAdapter].slotLoader
property.
- Implement a Banner ad callback to trigger whenever you call
+ [FYBBanner showBannerInView:position:options:]
for a placement with an APS instance in the waterfall.
-loadAPSBannerSlot:width:height:
- Implement a Rewarded ad callback to trigger whenever you call
+ [FYBRewarded request:placementId]
for a placement with an APS instance in the waterfall.
-loadAPSRewardedSlot:(NSString *)slotUUID
- Implement a Interstitial ad callback to trigger whenever you call
+ [FYBInterstitial request:placementId]
for a placement with an APS instance in the waterfall.
-loadAPSInterstitialSlot:(NSString *)slotUUID
Example: iOS Ad Slot Loader
#import <FairBidSDK/FairBidSDK.h>
#import <DTBiOSSDK/DTBiOSSDK.h>
@interface APSSlotLoader : NSObject <FYBAPSSlotLoader, DTBAdCallback>
@end
@implementation APSSlotLoader
// 4. Load Banner ad type callback
- (void)loadAPSBannerSlot:(nonnull NSString *)slotUUID width:(NSInteger)width height:(NSInteger)height {
NSLog(@"[APS] loadAPSBannerSlot: %@, width: %li, height: %li", slotUUID, (long)width, (long)height);
DTBAdLoader *loader = [DTBAdLoader new];
DTBAdSize *size = [[DTBAdSize alloc] initBannerAdSizeWithWidth:width height:height andSlotUUID:slotUUID];if (!size) {
NSLog(@"[APS] Failed to create DTBAdSize object: (width: %li, height: %li, andSlotUUID: %@)", (long)width, (long)height, slotUUID);
return;
}
[loader setAdSizes:@[size]];
[loader loadAd:self];
}
// 5. Load Rewarded ad type callback
- (void)loadAPSRewardedSlot:(NSString *)slotUUID {
NSLog(@"[APS] loadAPSRewardedSlot: %@", slotUUID;
DTBAdLoader *loader = [DTBAdLoader new];
DTBAdSize *size = [[DTBAdSize alloc] initVideoAdSizeWithPlayerWidth:320 height:480 andSlotUUID:slotUUID];;
[loader setAdSizes:@[size]];
[loader loadAd:self];
}
// 6. Load Interstitials ad type callback
- (void)loadAPSInterstitialSlot:(NSString *)slotUUID {
NSLog(@"[APS] loadAPSInterstitialSlot: %@", slotUUID;
DTBAdLoader *loader = [DTBAdLoader new];
DTBAdSize *size = [[DTBAdSize alloc] interstitialAdSizeWithSlotUUID:slotUUID];
[loader setAdSizes:@[size]];
[loader loadAd:self];
}
@end
- Create object that conforms to
id <DTBAdCallback>
protocol.
- Implement the
-onSuccess:
callback, and pass the following parameters back to FairBidSDK by calling-[[FairBid apsAdapter] setBidInfo:encodedPricePoint:slotUUID:]
.adResponse.bidInfo
adResponse.amznSlots
adResponse.adSize.slotUUID
- (Optional) Implement the
-onFailure:
callback to receive error messages when APS cannot fill a slot.
Example: iOS Ad Callbacks
// 7. DTBAdCallback
// 8. onSuccess callback
- (void)onSuccess:(DTBAdResponse *)adResponse {
NSLog(@"[APS] onSuccess: %@", adResponse);
[[FairBid apsAdapter] setBidInfo:adResponse.bidInfo
encodedPricePoint:adResponse.amznSlots
slotUUID:adResponse.adSize.slotUUID];
}
// 9. onFailure callback
- (void)onFailure:(DTBAdError *)error {
NSLog(@"[APS] onFailure: %@", error);
}
Initializing the APS SDK on Android
The following process is recommended for initializing the APS SDK in either Java or Kotlin implementations on the Android platform.
- Start DT FairBid SDK with your DT
APP_ID
.
FairBid.start(<<APP_ID>>, activity);
FairBid.start(<<APP_ID>>, activity)
- Start the APS SDK with the
APP_KEY
configured on your APS Portal.
AdRegistration.getInstance(<<APP_KEY>>, context);
AdRegistration.getInstance(<<APP_KEY>>, context)
- Create an object that implements the
SlotLoader
interface, and register it to DT FairBid SDK withAPSAdapter.slotLoader
.
- Implement a Banner ad callback to trigger whenever you call
Banner.show(placementId, activity)
for a placement configured with an APS instance in the waterfall.
loadAPSBannerSlot(String slotUUID, int width, int height))
loadAPSBannerSlot(slotUUID: String, width: Int, height: Int)
- Implement an Interstitial ad callback to trigger whenever you call
Interstitiat.request(placementId)
for a placement configured with an APS instance in the waterfall.
loadAPSInterstitialSlot(String slotUUID)
loadAPSInterstitialSlot(slotUUID: String)
- Implement a Rewarded ad callback to trigger whenever you call
Rewarded.request(placementId)
for a placement configured with an APS instance in the waterfall.
loadAPSRewardedSlot(String slotUUID)
loadAPSRewardedSlot(slotUUID: String)
- Create an object that implements the
DTBAdCallback
.
- Implement the
onSuccess
callback, and extract the following parameters and pass them back to FairBid viaAPSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo)
:- Encoded price points
- Bid info
onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
onSuccess(dtbAdResponse: DTBAdResponse) {
Log.d("[APS] onSuccess: $slotUUID")
val encodedPricePoints: String = SDKUtilities.getPricePoint(dtbAdResponse)
val bidInfo = SDKUtilities.getBidInfo(dtbAdResponse)
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo)
- (Optional) Implement the
onFailure
callback to receive error messages when APS cannot fill a slot.
onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
onFailure(adError: AdError) {
Log.d("[APS] onFailure: Amazon APS error: ${adError.message}")
Example: Android Implementation
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import com.amazon.device.ads.AdError;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.DTBAdCallback;
import com.amazon.device.ads.DTBAdRequest;
import com.amazon.device.ads.DTBAdResponse;
import com.amazon.device.ads.DTBAdSize;
import com.amazon.device.ads.SDKUtilities;
import com.fyber.FairBid;
import com.fyber.fairbid.adapters.APSAdapter;
// 3. Create object with slotLoader interface
public class AmazonAPS implements APSAdapter.SlotLoader {
private static AmazonAPS INSTANCE = new AmazonAPS();
private AmazonAPS() {}
public static void start(String appKey, Context context) {
// extra check to perform this only once
if (!AdRegistration.isInitialized()) {
// 2. Start APS SDK
AdRegistration.getInstance(appKey, context);
// 3. Register slotLoader to FairBid instance
APSAdapter.setSlotLoader(INSTANCE);
}
}
// 4. Load Banner Ad Type
@Override
public void loadAPSBannerSlot(@NonNull String slotUUID, int width, int height) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize(width, height, slotUUID));
// 7. Implement callback
adRequest.loadAd(new DTBAdCallback() {
// 9. Implement onFailure
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
// 8. Implement onSuccess callback
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
}
// 5. Load Interstitial Ad Type
@Override
public void loadAPSInterstitialSlot(@NonNull String slotUUID) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize.DTBInterstitialAdSize(slotUUID));
// 7. Implement callback
adRequest.loadAd(new DTBAdCallback() {
// 9. Implement onFailure
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
// 8. Implement onSuccess callback
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
}
// 6. Load Rewarded Ad Type
@Override
public void loadAPSRewardedSlot(@NonNull String slotUUID) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize.DTBVideo(320,480, slotUUID));
// 7. Implement callback
adRequest.loadAd(new DTBAdCallback() {
// 9. Implement onFailure
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
// 8. Implement onSuccess callback
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
}
}
// ... inside your code
// 1. start DT FairBid SDK
FairBid.start("APP_ID", activity);
// and also start APS through the helper class above
AmazonAPS.start("APP_KEY", context);
import android.content.Context
import android.util.Log
import androidx.annotation.NonNull
import com.amazon.device.ads.AdError
import com.amazon.device.ads.AdRegistration
import com.amazon.device.ads.DTBAdCallback
import com.amazon.device.ads.DTBAdRequest
import com.amazon.device.ads.DTBAdResponse
import com.amazon.device.ads.DTBAdSize
import com.amazon.device.ads.SDKUtilities
import com.fyber.FairBid
import com.fyber.fairbid.adapters.APSAdapter
// 3. Create object with slotLoader interface
class AmazonAPS private constructor() : APSAdapter.slotLoader {
companion object {
private val instance: AmazonAPS by lazy {
AmazonAPS()
}
fun start(appKey: String, context: Context) {
// extra check to perform this only once
if (!AdRegistration.isInitialized()) {
// 2. Start APS SDK
AdRegistration.getInstance(appKey, context)
// 3. Register slotLoader to FairBid instance
APSAdapter.slotLoader = instance
}
}
}
// 4. Load Banner Ad Type
override fun loadAPSBannerSlot(slotUUID: String, width: Int, height: Int) {
DTBAdRequest().apply {
setSizes(DTBAdSize(width, height, slotUUID))
// 7. Implement callback
loadAd(object : DTBAdCallback {
// 9. Implement onFailure
override fun onFailure(adError: AdError) {
Log.d("[APS] onFailure: Amazon APS error: ${adError.message}")
}
//8. Implement onSuccess callback
override fun onSuccess(dtbAdResponse: DTBAdResponse) {
Log.d("[APS] onSuccess: $slotUUID")
val encodedPricePoints: String = SDKUtilities.getPricePoint(dtbAdResponse)
val bidInfo = SDKUtilities.getBidInfo(dtbAdResponse)
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo)
}
})
}
}
// 5. Load Interstitial Ad Type
override fun loadAPSInterstitialSlot(slotUUID: String) {
DTBAdRequest().apply {
setSizes(DTBAdSize.DTBInterstitialAdSize(slotUUID))
// 7. Implement callback
loadAd(object : DTBAdCallback {
// 9. Implement onFailure
override fun onFailure(adError: AdError) {
Log.d("[APS] onFailure: Amazon APS error: ${adError.message}"
}
// 8. Implement onSuccess callback
override fun onSuccess(dtbAdResponse: DTBAdResponse) {
Log.d("[APS] onSuccess: $slotUUID")
val encodedPricePoints: String = SDKUtilities.getPricePoint(dtbAdResponse)
val bidInfo = SDKUtilities.getBidInfo(dtbAdResponse)
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo)
}
})
}
}
// 6. Load Rewarded Ad Type
override fun loadAPSRewardedSlot(slotUUID: String) {
DTBAdRequest().apply {
setSizes(DTBAdSize.DTBVideo(320,480, slotUUID))
// 7. Implement Callback
loadAd(object : DTBAdCallback {
// 9. Implement OnFailure
override fun onFailure(adError: AdError) {
Log.d("[APS] onFailure: Amazon APS error: ${adError.message}"
}
// 8. Implement OnSuccess callback
override fun onSuccess(dtbAdResponse: DTBAdResponse) {
Log.d("[APS] onSuccess: $slotUUID")
val encodedPricePoints: String = SDKUtilities.getPricePoint(dtbAdResponse)
val bidInfo = SDKUtilities.getBidInfo(dtbAdResponse)
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo)
}
}
})
}
}
// ... inside your code
// 1. Start DT FairBid SDK
FairBid.start(APP_ID, activity)
// and also start APS through the helper class above
AmazonAPS.start(APP_KEY, context)
Initializing the APS SDK on Unity
The following process is recommended for initializing the APS SDK on the Unity platform.
- Add the following dependencies to
mainTemplate.gradle
:implementation 'com.amazon.android:aps-sdk:9.9.2' implementation 'androidx.appcompat:appcompat:1.6.1' compileOnly 'com.fyber:fairbid-sdk:3.55.0'
Note
FairBid is already added as a dependency; however, to access the APIs from the unityLibrary project, add them as a compileOnly dependency.
- To avoid conflicts with duplicate entries for
META-INF/com.android.tools/proguard/coroutines.pro
, add the following code tolauncherTemplate.gradle
:android { packagingOptions { exclude 'META-INF/com.android.tools/proguard/coroutines.pro' } }
- If your minimum API level is below 19, add the following snippet to
LauncherManifest.xml
:
<uses-sdk tools:overrideLibrary="com.amazon.aps.ads" />
- Create the
Assets/APS Compat
directory, and addAmazonAPS.java
(provided below) to the directory.
package com.fyber.aps.compat;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import com.amazon.device.ads.AdError;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.DTBAdCallback;
import com.amazon.device.ads.DTBAdRequest;
import com.amazon.device.ads.DTBAdResponse;
import com.amazon.device.ads.DTBAdSize;
import com.amazon.device.ads.SDKUtilities;
import com.fyber.fairbid.adapters.APSAdapter;
import androidx.annotation.NonNull;
public class AmazonAPS implements APSAdapter.SlotLoader {
private static AmazonAPS INSTANCE = new AmazonAPS();
private AmazonAPS() {
}
public static void start(String appKey, Context context) {
// extra check to perform this only once
if (!AdRegistration.isInitialized()) {
AdRegistration.getInstance(appKey, context);
APSAdapter.setSlotLoader(INSTANCE);
}
}
@Override
public void loadAPSBannerSlot(@NonNull String slotUUID, int width, int height) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize(width, height, slotUUID));
adRequest.loadAd(new DTBAdCallback() {
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
@Override
public void loadAPSInterstitialSlot(@NonNull String slotUUID) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize.DTBInterstitialAdSize(slotUUID));
adRequest.loadAd(new DTBAdCallback() {
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
@Override
public void loadAPSRewardedSlot(@NonNull String slotUUID) {
DTBAdRequest adRequest = new DTBAdRequest();
adRequest.setSizes(new DTBAdSize.DTBVideo(320, 480, slotUUID));
adRequest.loadAd(new DTBAdCallback() {
@Override
public void onFailure(@NonNull AdError adError) {
Log.d("APS", "onFailure: Amazon APS error: " + adError.getMessage());
}
@Override
public void onSuccess(@NonNull DTBAdResponse dtbAdResponse) {
Log.d("APS", "onSuccess: " + slotUUID);
String encodedPricePoints = SDKUtilities.getPricePoint(dtbAdResponse);
String bidInfo = SDKUtilities.getBidInfo(dtbAdResponse);
APSAdapter.setBidInfo(slotUUID, encodedPricePoints, bidInfo);
}
});
}
}
- Open the Unity Inspector, and check Android on the Select plafforms for plugin pane.
- Start APS by adding the
start
call inside any of your methods in the C#. For example, you can add it right after starting FairBid.
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass jc = new AndroidJavaClass("com.fyber.aps.compat.AmazonAPS");
jc.CallStatic("start", "YOUR APP KEY HERE", activity);
- Build and run your app.
Step 4: Add the APS SDK to your Integration
To integrate the APS SDK, follow the instructions on the Supported Networks page.
Step 5: Test Your Integration
Use the DT Test Suite to verify that you have set up your app properly for FairBid mediation. The DT Test Suite is available for Android, iOS, and Unity apps. For more information about using the DT Test Suite, see Test Suite.