Capacitor plugin for Meta Audience Network ads integration with support for rewarded video and interstitial ads
npm install capacitor-meta-adsCapacitor plugin for Meta Audience Network ads integration with support for rewarded video and interstitial ads.
- ✅ Rewarded Video Ads - Show rewarded video ads and handle rewards
- ✅ Interstitial Ads - Display full-screen interstitial ads
- ✅ Test Mode Support - Easy testing with Meta's test ads
- ✅ Event Callbacks - Comprehensive ad lifecycle events
- ✅ Android Support - Full Android implementation
- ✅ iOS Support - Full iOS implementation with Meta Audience Network SDK
- ✅ AdMob Mediation - Compatible with AdMob mediation (bidding only)
``bash`
npm install capacitor-meta-ads
npx cap sync
1. Add Meta App ID to your android/app/src/main/AndroidManifest.xml:
`xml`
android:value="YOUR_META_APP_ID" />
2. For AdMob Mediation (optional - for maximum revenue):
- Add AdMob mediation dependency: implementation 'com.google.ads.mediation:facebook:6.11.0.1'
- Configure Meta as bidding source in AdMob console
- Use AdMob ad units instead of direct Meta placement IDs
1. Add Meta App ID to your ios/App/App/Info.plist:
`xml`
2. For AdMob Mediation (optional):
- Add AdMob mediation dependency in your Podfile
- Configure Meta as bidding source in AdMob console
- Use AdMob ad units instead of direct Meta placement IDs
`typescript
import { MetaAds } from 'capacitor-meta-ads';
// Initialize with your Meta App ID
await MetaAds.initialize({
appId: 'YOUR_META_APP_ID',
testMode: true, // Set to false in production
});
`
`typescript
// Load a rewarded video ad
await MetaAds.loadRewardedVideo({
placementId: 'YOUR_REWARDED_PLACEMENT_ID',
});
// Check if ad is loaded
const { loaded } = await MetaAds.isRewardedVideoLoaded();
if (loaded) {
// Show the ad
const result = await MetaAds.showRewardedVideo();
if (result.success && result.reward) {
console.log('Reward earned:', result.reward);
// Give reward to user
}
}
`
`typescript
// Load an interstitial ad
await MetaAds.loadInterstitial({
placementId: 'YOUR_INTERSTITIAL_PLACEMENT_ID',
});
// Check if ad is loaded
const { loaded } = await MetaAds.isInterstitialLoaded();
if (loaded) {
// Show the ad
const result = await MetaAds.showInterstitial();
if (result.success) {
console.log('Interstitial ad shown successfully');
}
}
`
`typescript
// Enable test mode (should be done before initialize)
await MetaAds.setTestMode({ enabled: true });
// Add test device
await MetaAds.addTestDevice({ deviceId: 'YOUR_TEST_DEVICE_ID' });
`
For testing, use Meta's test placement IDs:
- Rewarded Video: VID_HD_16_9_46S_APP_INSTALL#YOUR_PLACEMENT_IDIMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID
- Interstitial:
For AdMob Mediation Testing:
- Use AdMob test ad unit IDs
- Enable test mode in both AdMob and Meta consoles
- Register your test device in both platforms
* initialize(...)
* loadRewardedVideo(...)
* showRewardedVideo()
* isRewardedVideoLoaded()
* loadInterstitial(...)
* showInterstitial()
* isInterstitialLoaded()
* setTestMode(...)
* addTestDevice(...)
* Interfaces
`typescript`
initialize(options: { appId: string; testMode?: boolean; }) => Promise
Initialize Meta Audience Network SDK
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | { appId: string; testMode?: boolean; } |
--------------------
`typescript`
loadRewardedVideo(options: { placementId: string; }) => Promise
Load a rewarded video ad
| Param | Type |
| ------------- | ------------------------------------- |
| options | { placementId: string; } |
--------------------
`typescript`
showRewardedVideo() => Promise<{ success: boolean; reward?: RewardInfo; }>
Show a rewarded video ad
Returns: Promise<{ success: boolean; reward?: RewardInfo; }>
--------------------
`typescript`
isRewardedVideoLoaded() => Promise<{ loaded: boolean; }>
Check if rewarded video ad is loaded
Returns: Promise<{ loaded: boolean; }>
--------------------
`typescript`
loadInterstitial(options: { placementId: string; }) => Promise
Load an interstitial ad
| Param | Type |
| ------------- | ------------------------------------- |
| options | { placementId: string; } |
--------------------
`typescript`
showInterstitial() => Promise<{ success: boolean; }>
Show an interstitial ad
Returns: Promise<{ success: boolean; }>
--------------------
`typescript`
isInterstitialLoaded() => Promise<{ loaded: boolean; }>
Check if interstitial ad is loaded
Returns: Promise<{ loaded: boolean; }>
--------------------
`typescript`
setTestMode(options: { enabled: boolean; }) => Promise
Set test mode
| Param | Type |
| ------------- | ---------------------------------- |
| options | { enabled: boolean; } |
--------------------
`typescript`
addTestDevice(options: { deviceId: string; }) => Promise
Add test device
| Param | Type |
| ------------- | ---------------------------------- |
| options | { deviceId: string; } |
--------------------
#### RewardInfo
| Prop | Type |
| ------------ | ------------------- |
| type | string |
| amount | number |
- Android: API level 23+ (Android 6.0+)
- Meta Audience Network SDK: 6.17.0+
- Capacitor: 7.0.0+
- iOS: iOS 14.0+
✅ Fully Compatible - This plugin works with AdMob mediation:
- Meta Audience Network operates as bidding-only partner (no waterfall)
- Increases revenue through real-time bidding competition
- Improves fill rates across your ad inventory
- Configure in AdMob console, not directly in app code
Setup Steps:
1. Add mediation dependency to android/build.gradle`
2. Create mediation group in AdMob console
3. Add Meta as bidding source
4. Use AdMob ad unit IDs in your app
For Unity Ads integration, check out our companion plugin:
- Unity Ads Plugin: capacitor-unity-ads
Use both plugins together with AdMob mediation for maximum revenue!
MIT