Testing with Client-Side Code Insertion

In this testing method, you insert code into your app that lets you see test ads. You must remove this code before publishing the app.

You should ensure that the user testing your app is added to a role on your app's Business Manager. This testing method as it lets you see production ads on physical devices. See the Testing With Production Ads section for more information on the recommended testing method.

However, as noted in the previous section, you may realize that it is not always possible to test the UI of production ads with your app's UI views. In addition, you cannot guarantee that the ad received by your app will be an image ad, video ad or carousel ad. Requesting production ads will not guarantee the content and format of the ad returned. What if you want to test with an ad that contains portrait video content to make sure it looks correct with your app's UI view?

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 distinquish a test build from a release build.

Test Ad Type Table

Test Ad Type Description Supported Ad Format

VID_HD_16_9_46S_APP_INSTALL

16x9 HD video 46 sec ad with app install CTA option

Interstitial, Rewarded Video, Native

VID_HD_16_9_46S_LINK

16x9 HD video 46 sec ad with link CTA option

Interstitial, Rewarded Video, Native

VID_HD_16_9_15S_APP_INSTALL

16x9 HD video 15 sec ad with app install CTA option

Interstitial, Rewarded Video, Native

VID_HD_16_9_15S_LINK

16x9 HD video 15 sec ad with link CTA option

Interstitial, Rewarded Video, Native

VID_HD_9_16_39S_APP_INSTALL

9x16 HD video 39 sec ad with app install CTA option

Interstitial, Rewarded Video, Native

VID_HD_9_16_39S_LINK

9x16 HD video 39 sec ad with link CTA option

Interstitial, Rewarded Video, Native

IMG_16_9_APP_INSTALL

16x9 image ad with app install CTA option

Banner, Interstitial, Native

IMG_16_9_LINK

16x9 image ad with link CTA option

Banner, Interstitial, Native

CAROUSEL_IMG_SQUARE_APP_INSTALL

carousel ad with square image and app install CTA option

Interstitial, Native

CAROUSEL_IMG_SQUARE_LINK

carousel ad with square image and link CTA option

Interstitial, Native

When testing your ad placements with test ad type, please pay attention to Supported Ad Format. For example, if you create Rewarded Video Instance to request ad with test ad type IMG_16_9_APP_INSTALL, you will get display error.

Example to request test ads in code on iOS devices

For example, to request a video test ad with a 9:16 aspect ratio and app install CTA button in your iOS app, you need to initialize an FBNativeAd object by adding following line of code:

[FBNativeAd *nativeAd = [[FBNativeAd alloc] initWithPlacementID:@"VID_HD_9_16_39S_APP_INSTALL#YOUR_PLACEMENT_ID"];

You can run the above code to request a test ad in NativeAdSample project from the Audience Network SDK sample folder.

Alternatively, if you need to request test ads with random content format, you will see a message like this printed in the Logcat when testing on a physical Android device:

#ifdef DEBUG
[FBAdSettings setLogLevel:FBAdLogLevelLog];
[FBAdSettings addTestDevice:@"HASHED_ID"];
#endif

You would see the following log message:

[FBAudienceNetworkLog/FBAdSettings:94] 
When testing your app with Facebook ad units,  
you must specify the device hashed ID to ensure the delivery of test ads, 
add the following code before loading an ad: `[FBAdSettings addTestDevice:@"HASHED_ID"]`
Test mode device hash: bd675f960298a92003630d76fa612b1706b745ab

Replace HASHED_ID with the test mode device hash printed in the log above.

When you are finished testing you should clear the test device setting using this line of code:

[FBAdSettings clearTestDevice:[FBAdSettings testDeviceHash]]; 

Example to request test ads in code on Android devices

To request a video test ad with a 9:16 aspect ratio and app install CTA button in your Android app, you need to initialize an NativeAd object by adding following line of code:

nativeAd = new NativeAd(this, "VID_HD_9_16_39S_APP_INSTALL#YOUR_PLACEMENT_ID");

Alternatively if you need to request test ads with random content format, you will see a message like this printed in the Logcat when testing on a physical Android device:

Log: Test mode device hash: HASHED_ID 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");

You can 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 simply 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();

Example to request test ads in mediation dashboard

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.