To test your Audience Network implementation on the client-side, you temporarily insert code into your app. This code allows you to test production ads on your physical devices before releasing your app to the public. This testing allows you to test any type of ad; a carousel ad, an image ad, or a landscape or portrait video ad.
To request a test ad, you will use the following test ad type string to concatenate the placement ID with '#' when initializing any Facebook ad object. The placement ID template for requesting test ads is TEST_AD_TYPE#YOUR_PLACEMENT_ID.
You should never ship your app to the public with the above test code as it will cause only test ads to be shown. You should instead use a preprocessor macro such as DEBUG
or TESTING
and then use #ifdef
to distinguish a test build from a release build.
Test Ad Type | Description | Supported Ad Format |
---|---|---|
| carousel ad with square image and app install CTA option | Interstitial, Native |
| carousel ad with square image and link CTA option | Interstitial, Native |
| 16x9 image ad with app install CTA option | Banner, Interstitial, Native |
| 16x9 image ad with link CTA option | Banner, Interstitial, Native |
| Playable ad with app install CTA option | Interstitial, Rewarded Video |
| 9x16 HD video 39 sec ad with app install CTA option | Interstitial, Native, Rewarded Video |
| 9x16 HD video 39 sec ad with link CTA option | Interstitial, Native, Rewarded Video |
| 16x9 HD video 15 sec ad with app install CTA option | Interstitial, Native, Rewarded Video |
| 16x9 HD video 15 sec ad with link CTA option | Interstitial, Native, Rewarded Video |
| 16x9 HD video 46 sec ad with app install CTA option | Interstitial, Native, Rewarded Video |
| 16x9 HD video 46 sec ad with link CTA option | Interstitial, Native, Rewarded Video |
Be sure the format of the ad you are requesting is supported by the test ad type or you will get a Code=1011 “Display Format Mismatch”
error.
To test a native ad on your iOS device, you can initialize an FBNativeAd
object.
The following sample requests a video test ad with a 9:16 aspect ratio and an app install CTA button.
[FBNativeAd *nativeAd = [[FBNativeAd alloc] initWithPlacementID:@"VID_HD_9_16_39S_APP_INSTALL#{your-placement-id}"];
When testing your app with Facebook ad units, you must specify the device hashed ID to ensure the delivery of test ads.
#ifdef DEBUG [FBAdSettings setLogLevel:FBAdLogLevelLog]; [FBAdSettings addTestDevice:@"{hashed-id}"]; #endif
You can run the above code, substituting {your-placement-id}
with your placement ID and {hash-id}
with your test device hash ID, to request a test ad in the NativeAdSample project from the Audience Network SDK sample folder.
After you have finished testing you should clear the test device setting.
[FBAdSettings clearTestDevice:[FBAdSettings testDeviceHash]];
To test a native ad on your Android device, you can initialize a NativeAd
object.
The following sample requests a video test ad with a 9:16 aspect ratio and app install CTA button.
nativeAd = new NativeAd(this, "VID_HD_9_16_39S_APP_INSTALL#{your-placement-id}");
You can run the above code, substituting {your-placement-id}
with your placement ID.
Get the test device hashed ID from the Logcat. The log will look like the following:
Log: When testing your app with Facebook's ad units you must specify the device hashed ID to ensure the delivery of test ads, add the following code before loading an ad: `AdSettings.addTestDevice("{hashed-id}");`
Then, enable test ads on a device by adding the following line of code before loading an ad:
AdSettings.addTestDevice("{hashed-id}");
If you wish to add multiple test devices, then create a list of strings to be added before loading an ad.
List<String> testDevices = new ArrayList<>(); testDevices.add("{hashed-id-1}"); testDevices.add("{hashed-id-2}"); AdSettings.addTestDevices(testDevices);
When you are finished testing you should clear the test device setting using this line of code:
AdSettings.clearTestDevices();
In addition to requesting the test ad from code, you can configure the placement ID value with test ad type from your mediation dashboard if your app uses mediation. For example, if your app uses MoPub, you can edit Facebook network and set the placement ID value for the native ad to be VID_HD_9_16_39S_APP_INSTALL#{your-placement-id}
. Your app will receive a video test ad with a 9:16 aspect ratio and app install CTA button.