capacitor-meta-ads
v1.0.0
Published
Capacitor plugin for Meta Audience Network ads integration with support for rewarded video and interstitial ads
Maintainers
Readme
capacitor-meta-ads
Capacitor plugin for Meta Audience Network ads integration with support for rewarded video and interstitial ads.
Features
- ✅ 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)
Install
npm install capacitor-meta-ads
npx cap syncConfiguration
Android Setup
- Add Meta App ID to your
android/app/src/main/AndroidManifest.xml:
<application>
<!-- Meta Audience Network App ID -->
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="YOUR_META_APP_ID" />
</application>- 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
- Add AdMob mediation dependency:
iOS Setup
- Add Meta App ID to your
ios/App/App/Info.plist:
<key>FacebookAppID</key>
<string>YOUR_META_APP_ID</string>
<key>FacebookClientToken</key>
<string>YOUR_CLIENT_TOKEN</string>- 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
Usage
Initialize the SDK
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
});Rewarded Video Ads
// 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
}
}Interstitial Ads
// 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');
}
}Test Mode
// Enable test mode (should be done before initialize)
await MetaAds.setTestMode({ enabled: true });
// Add test device
await MetaAds.addTestDevice({ deviceId: 'YOUR_TEST_DEVICE_ID' });Test Placement IDs
For testing, use Meta's test placement IDs:
- Rewarded Video:
VID_HD_16_9_46S_APP_INSTALL#YOUR_PLACEMENT_ID - Interstitial:
IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID
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
API
initialize(...)loadRewardedVideo(...)showRewardedVideo()isRewardedVideoLoaded()loadInterstitial(...)showInterstitial()isInterstitialLoaded()setTestMode(...)addTestDevice(...)- Interfaces
initialize(...)
initialize(options: { appId: string; testMode?: boolean; }) => Promise<void>Initialize Meta Audience Network SDK
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | { appId: string; testMode?: boolean; } |
loadRewardedVideo(...)
loadRewardedVideo(options: { placementId: string; }) => Promise<void>Load a rewarded video ad
| Param | Type |
| ------------- | ------------------------------------- |
| options | { placementId: string; } |
showRewardedVideo()
showRewardedVideo() => Promise<{ success: boolean; reward?: RewardInfo; }>Show a rewarded video ad
Returns: Promise<{ success: boolean; reward?: RewardInfo; }>
isRewardedVideoLoaded()
isRewardedVideoLoaded() => Promise<{ loaded: boolean; }>Check if rewarded video ad is loaded
Returns: Promise<{ loaded: boolean; }>
loadInterstitial(...)
loadInterstitial(options: { placementId: string; }) => Promise<void>Load an interstitial ad
| Param | Type |
| ------------- | ------------------------------------- |
| options | { placementId: string; } |
showInterstitial()
showInterstitial() => Promise<{ success: boolean; }>Show an interstitial ad
Returns: Promise<{ success: boolean; }>
isInterstitialLoaded()
isInterstitialLoaded() => Promise<{ loaded: boolean; }>Check if interstitial ad is loaded
Returns: Promise<{ loaded: boolean; }>
setTestMode(...)
setTestMode(options: { enabled: boolean; }) => Promise<void>Set test mode
| Param | Type |
| ------------- | ---------------------------------- |
| options | { enabled: boolean; } |
addTestDevice(...)
addTestDevice(options: { deviceId: string; }) => Promise<void>Add test device
| Param | Type |
| ------------- | ---------------------------------- |
| options | { deviceId: string; } |
Interfaces
RewardInfo
| Prop | Type |
| ------------ | ------------------- |
| type | string |
| amount | number |
Requirements
- Android: API level 23+ (Android 6.0+)
- Meta Audience Network SDK: 6.17.0+
- Capacitor: 7.0.0+
- iOS: iOS 14.0+
AdMob Mediation Support
✅ 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:
- Add mediation dependency to
android/build.gradle - Create mediation group in AdMob console
- Add Meta as bidding source
- Use AdMob ad unit IDs in your app
Related Plugin
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!
License
MIT
