Meta Ads Apis
Functions to display Meta Audience Network ads - banner, fullscreen (interstitial), and rewarded video inside your app.
The WebToNative Meta Ads plugin integrates the native Meta Audience Network Android and iOS SDKs, so ad requests, rendering, and lifecycle events all happen natively, and are reported back to your website through a JavaScript callback.
You'll need to import the javascript file in your website before starting from this link.
Platform support: Android and iOS.
setMetaAdsTestModecurrently only has an effect on Android see the note under setMetaAdsTestMode.
Setting Up Meta Audience Network
1. Create Your Audience Network Placements
Sign in to Meta Audience Network via your Facebook Business account.
Add your app under Apps and create one Placement per ad unit you want to show one for your banner, one for your fullscreen/interstitial, one for your rewarded video (placement IDs differ by ad format, e.g. an image-format ID can't be used for a rewarded video slot).
Copy your Facebook App ID and the Placement ID for each placement you created.
2. Enable the Add-on in WebToNative
Go to your WebToNative dashboard → Add-ons → Meta Ads and enable it.
Enter your Facebook App ID (Android also requires a Client Token, iOS also requires a Client Token both are found on the same Meta for Developers app dashboard as your App ID). WebToNative wires these into the platform-specific native config (
facebook_app_idon Android,FacebookAppID/FacebookClientTokeninInfo.pliston iOS) for you — you don't set these from JavaScript.
Android also requires at least one Placement Rule saved in the dashboard add-on, even if you only intend to trigger ads manually from JavaScript. If the add-on is disabled, or enabled with zero placement rules configured, every WTN.MetaAds.* call below silently does nothing no callback fires at all. Enter at least one placement (it doesn't have to be the one you actually trigger manually) to make the bridge available. iOS does not have this extra requirement enabling the add-on and setting the App ID/Client Token is enough.
JavaScript API Reference
showMetaBannerAd
Displays a banner ad docked to the top or bottom of the screen.
Parameters:
placementId
String
Yes
The Audience Network Placement ID for this banner, from the Meta Audience Network dashboard.
position
String
No
Where to dock the banner "TOP" or "BOTTOM". Defaults to "BOTTOM".
position is case-sensitive and only accepts uppercase "TOP" / "BOTTOM". Passing "top" or "bottom" in lowercase does not match on either platform and silently falls back to the bottom position.
showMetaFullscreenAd
Displays a fullscreen interstitial ad over your app.
Parameters:
placementId
String
Yes
The Audience Network Placement ID for this interstitial (must be a video- or image-format placement created for this slot).
showMetaRewardedAd
Displays a rewarded video ad. The user watches the full video in exchange for an in-app reward you grant yourself, the SDK only tells you the video was completed, it does not grant anything on your behalf.
Parameters:
placementId
String
Yes
The Audience Network Placement ID for this rewarded video slot.
Only onAdCompleted means the user watched the whole video. If the user closes the ad early, you get onAdClosed instead, with no onAdCompleted event, check specifically for onAdCompleted before granting a reward, don't grant on onAdClosed.
setMetaAdsTestMode
Toggles Meta Audience Network's test mode, so ad requests return Meta's shared test creatives instead of live ads, useful for development and app-review builds without registering individual device hashes.
Parameters:
state
String
Yes
"TRUE" to request test ads, "FALSE" to go back to live ads.
There is no callback for this function and no response is emitted.
Android only. setMetaAdsTestMode calls Meta's AdSettings.setTestMode() on Android, which affects every ad request made afterwards for the rest of the session. On iOS this call currently has no effect at all it's silently ignored. iOS instead auto-enables Meta's test device mode on its own, but only inside Debug builds, and this is not controllable from JavaScript. Don't rely on this function to turn test ads on/off on iOS.
Callback Response Format
All callbacks receive a JSON object. The type field always matches the function name that triggered the callback, so you can safely share one callback across multiple calls and branch on type.
Success Response
Error Response
error.message and error.code are passed straight through from Meta's own Audience Network SDK, so the exact set of codes/messages you may see is defined by Meta, not WebToNative, see Meta's Audience Network error codes for the full list.
All Possible status Values
onAdLoaded
Banner, Fullscreen, Rewarded
Ad has been successfully loaded and is ready.
onAdDisplayed
Fullscreen
Ad is now visible on screen. Banners do not emit this treat onAdLoaded as "visible" for banners.
onAdClicked
Banner, Fullscreen, Rewarded
User tapped/clicked the ad.
onAdDismissed
Fullscreen
User closed the interstitial.
onAdClosed
Rewarded
User closed the rewarded video (with or without finishing it, check onAdCompleted separately to know which).
onAdCompleted
Rewarded
User watched the full rewarded video. This is the only signal you should grant a reward on.
adError
Banner, Fullscreen, Rewarded
Ad failed to load or display see error object.
All Possible type Values
showMetaBannerAd
showMetaBannerAd()
showMetaFullscreenAd
showMetaFullscreenAd()
showMetaRewardedAd
showMetaRewardedAd()
Implementation Checklist
Meta Audience Network
WebToNative Dashboard
Your Website
Frequently Asked Questions
Why isn't my banner/interstitial/rewarded ad showing at all no callback fires?
On Android, the Meta Ads add-on must be enabled and have at least one Placement Rule saved in the WebToNative dashboard, or the native bridge for all four functions is never initialized every call silently no-ops with no callback. Add at least one placement in the dashboard, then retry.
Why does my banner never fire `onAdDisplayed`?
Banners only emit onAdLoaded, onAdClicked, and adError on both platforms there's no separate "displayed" event for banners in the underlying Audience Network SDK. Treat onAdLoaded as your signal that the banner is now visible.
Why does `position: "top"` show my banner at the bottom?
position is matched as an exact, case-sensitive string against "TOP" on both platforms. Any other casing (including "top" or "Top") doesn't match and falls back to the bottom position. Always send uppercase "TOP" or "BOTTOM".
Does `setMetaAdsTestMode` work on iOS?
No. It's fully functional on Android but currently has no effect on iOS the call is silently ignored there. On iOS, test ads are only enabled automatically in Debug builds, independent of this function.
How do I know when to grant the reward for a rewarded ad?
Only on status === "onAdCompleted". If the user closes the ad before it finishes, you get onAdClosed instead, with no onAdCompleted event don't grant a reward for that case.
What do the numeric `error.code` values mean?
They're Meta Audience Network's own error codes, passed straight through unchanged (e.g. 1001 = no fill). See Meta's Audience Network error code reference for the full, authoritative list.
Official References
Last updated