From Audience Network SDK version 6.2 and later, the AIR API is able to receive encrypted CPM when an impression event is created.
You need to subscribe to Audience Network SDK impression events to access the AIR API. The process for both iOS and Android is described in this section.
If you are using an SDK version earlier than 6.2, consult with your mediation partner to see if they support AIR.
You must implement the following protocol (available in FBAudienceNetwork/FBAdSDKNotificationManager.h
).
@protocol FBAdSDKNotificationListener <NSObject> /** Method to be called when some specific SDK event will happens @param event event type. Currently supported following events: "impression" happens every time when AD got an impression recorded on the SDK @param eventData is a payload associated with the event. Method would be called on the main queue when the SDK event happens. */ - (void)onFBAdEvent:(NSString *)event eventData:(NSDictionary<NSString *, NSString *> *)eventData; @end }
To subscribe to events, call the:
[FBAdSDKNotificationManager addFBAdSDKNotificationListener:]
method with the listener. Please note that we are holding only weak reference to the listener.
To unsubscribe from events, call:
[FBAdSDKNotificationManager removeFBAdSDKNotificationListener:]
Once subscribed, when an impression happens you will receive a message similar to the following:
static AdSDKNotificationManager.addSDKNotificationListener()
To start receiving encrypted CPMs, call the:
static AdSDKNotificationManager.addSDKNotificationListener()
method before any ad is loaded. The best place for this is Application.onCreate() method:
public class YourApplication extends Application { ... @Override public void onCreate() { super.onCreate(); // some code AdSDKNotificationManager.addSDKNotificationListener(new YourAdSDKNotificationListener()) } ... }
NOTE: AdSDKNotificationManager keeps a strong reference on registered AdSDKNotificationListeners, so be careful with using an anonymous class implementation of AdSDKNotificationListeners from Activity classes, to avoid memory leaks. For example:
ublic class YourActivity extends Activity { ... @Override public void onCreate() { super.onCreate(); // some code AdSDKNotificationManager.addSDKNotificationListener(new AdSDKNotificationListeners { // This will leak Activity! }); } ... }
We recommend writing a custom implementation of AdSDKNotificationListener in a separate class, or an internal static class as shown in Step 2.
Best practice is to add one single listener for your integration during the whole app lifetime.
Encrypted CPMs for all ad formats will be delivered to all registered AdSDKNotificationListeners using onAdEvent()
callback.
NOTE: This callback will be always called on the UI thread, so if you need to do any time-consuming processing of encrypted CPMs, pass it to the background thread.
public class YourAdSDKNotificationListener implements AdSDKNotificationListener { @Override public void onAdEvent(String event, Bundle data) { switch (event) { case AdSDKNotificationListener.IMPRESSION_EVENT: String encryptedCPM = data.getString(AdSDKNotificationListener.ENCRYPTED_CPM_KEY); if (encryptedCPM != null) { // your code here // use background thread for heavy operations } break; default: break; } } }
Currently AdSDKNotificationListener supports listening-only for impression events. For each event, encrypted CPM will be delivered inside the Bundle parameter +“data”. You can fetch this from the bundle using AdSDKNotificationListener.ENCRYPTED_CPM_KEY
.