@empower-nokta/react-native-empower-mobile-ads
v0.4.0
Published
React Native bridge for Empower Mobile Ads SDK
Downloads
32
Maintainers
Readme
@empower-nokta/react-native-mobile-ads
React Native bridge for the Empower Mobile Ads SDK (Android).
Supports banner, interstitial, rewarded, app open, and preroll ad formats.
Requirements
- React Native 0.70+
- Android minSdkVersion 21 (Android 5.0)
- New Architecture: supported via React Native interop layer (0.74+)
Installation
npm install @empower-nokta/react-native-mobile-adsThe package supports auto-linking — no manual linking required for React Native 0.60+.
Android Setup
After installing, you need to configure 4 things in your Android project:
Step 1: Add Maven Repository
In android/build.gradle (project-level), add the Empower Maven repository:
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://maven.empower.net/release" }
}
}If your project uses
dependencyResolutionManagementinsettings.gradleinstead ofallprojects, add the Maven repository there:dependencyResolutionManagement { repositories { google() mavenCentral() maven { url "https://maven.empower.net/release" } } }
Step 2: Resolve Kotlin Version Conflict
The Empower SDK uses Kotlin 2.3.0, which may conflict with React Native's Kotlin version. Add these to your android/build.gradle (project-level):
allprojects {
configurations.all {
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlinVersion}"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.ext.kotlinVersion}"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.ext.kotlinVersion}"
}
}
}And in android/gradle.properties, add:
kotlin.suppressKotlinVersionCompatibilityCheck=2.3.0Step 3: Add Google Ad Manager Meta-Data
In android/app/src/main/AndroidManifest.xml, inside the <application> tag:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR_ADMOB_APP_ID"/>
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>Replace YOUR_ADMOB_APP_ID with your Google Ad Manager app ID (e.g., ca-app-pub-XXXXXXXX~XXXXXXXX).
Step 4: Build and Run
cd android && ./gradlew clean && cd ..
npx react-native run-androidUsage
Initialize the SDK
import { init, setDebugMode, setLogLevel } from '@empower-nokta/react-native-mobile-ads';
// Call early in your app (e.g., App.tsx useEffect)
async function initAds() {
setDebugMode(__DEV__);
setLogLevel(__DEV__ ? 'all' : 'none');
await init({
appAdIdentifier: 'YOUR_APP_IDENTIFIER',
});
}Banner Ads
import { EmpowerBannerAd } from '@empower-nokta/react-native-mobile-ads';
function MyScreen() {
return (
<EmpowerBannerAd
zoneId="YOUR_BANNER_ZONE_ID"
onAdStatusChanged={(e) => console.log('Banner:', e.nativeEvent)}
style={{ width: '100%', minHeight: 50 }}
/>
);
}Interstitial Ads
import {
loadInterstitialAd,
showInterstitial,
addEventListener,
EmpowerAdsEvents,
} from '@empower-nokta/react-native-mobile-ads';
// Listen for status changes
const unsubscribe = addEventListener(EmpowerAdsEvents.INTERSTITIAL_STATUS, (event) => {
console.log('Interstitial status:', event.status, event.zoneId);
});
// Preload
await loadInterstitialAd('YOUR_INTERSTITIAL_ZONE_ID');
// Show when ready
await showInterstitial('YOUR_INTERSTITIAL_ZONE_ID');
// Cleanup
unsubscribe();Rewarded Ads
import {
loadRewardedAd,
showRewarded,
addEventListener,
EmpowerAdsEvents,
} from '@empower-nokta/react-native-mobile-ads';
const unsubscribe = addEventListener(EmpowerAdsEvents.REWARDED_STATUS, (event) => {
if (event.status === 'REWARDED') {
// Grant reward to user
}
});
await loadRewardedAd('YOUR_REWARDED_ZONE_ID');
await showRewarded('YOUR_REWARDED_ZONE_ID');
unsubscribe();App Open Ads
import { loadAppOpenAd, showAppOpen } from '@empower-nokta/react-native-mobile-ads';
await loadAppOpenAd('YOUR_APP_OPEN_ZONE_ID');
await showAppOpen('YOUR_APP_OPEN_ZONE_ID');Settings
import {
setAdsDisabled,
setNonPersonalizedAds,
setDebugMode,
setLogLevel,
} from '@empower-nokta/react-native-mobile-ads';
setAdsDisabled(false);
setNonPersonalizedAds(true); // GDPR compliance
setDebugMode(true);
setLogLevel('all'); // 'all' | 'default' | 'error' | 'warning' | 'none'Shutdown
import { shutdown } from '@empower-nokta/react-native-mobile-ads';
shutdown();API Reference
| Function | Returns | Description |
|---|---|---|
| init(config) | Promise<boolean> | Initialize the SDK |
| isSdkInitialized() | Promise<boolean> | Check if SDK is ready |
| setAdsDisabled(bool) | void | Disable/enable all ads |
| setNonPersonalizedAds(bool) | void | GDPR non-personalized mode |
| setDebugMode(bool) | void | Toggle debug logging |
| setLogLevel(level) | void | Set log verbosity |
| loadInterstitialAd(zoneId) | Promise<boolean> | Preload interstitial |
| showInterstitial(zoneId) | Promise<boolean> | Show interstitial |
| loadRewardedAd(zoneId) | Promise<boolean> | Preload rewarded ad |
| showRewarded(zoneId) | Promise<boolean> | Show rewarded ad |
| loadAppOpenAd(zoneId) | Promise<boolean> | Preload app open ad |
| showAppOpen(zoneId) | Promise<boolean> | Show app open ad |
| pausePreroll(zoneId) | void | Pause preroll playback |
| resumePreroll(zoneId) | void | Resume preroll playback |
| destroyPreroll(zoneId) | void | Destroy preroll ad |
| shutdown() | void | Shutdown SDK |
| addEventListener(event, cb) | () => void | Subscribe to events |
Events
| Event | Payload |
|---|---|
| EmpowerAds_onSdkReady | {} |
| EmpowerAds_onSdkFailed | { error: string } |
| EmpowerAds_onBannerStatusChanged | { status, zoneId, adUnitId } |
| EmpowerAds_onInterstitialStatusChanged | { status, zoneId } |
| EmpowerAds_onRewardedStatusChanged | { status, zoneId } |
| EmpowerAds_onAppOpenStatusChanged | { status, zoneId } |
| EmpowerAds_onPrerollStatusChanged | { status, zoneId } |
Troubleshooting
"Could not resolve net.empower.mobile.ads:empower-mobile-ads"
You need to add the Empower Maven repository to your project-level android/build.gradle. See Step 1.
"Module compiled with an incompatible version of Kotlin"
Add the Kotlin version resolution strategy and suppressKotlinVersionCompatibilityCheck property. See Step 2.
TurboModuleRegistry.getEnforcing crash
This usually means Metro is serving a JS bundle from a different project. Make sure Metro is running from your project root:
npx react-native start --reset-cacheThe module is compatible with New Architecture via React Native's interop layer (RN 0.74+).
Banner ad loads but is not visible
Ensure the EmpowerBannerAd component has explicit dimensions:
<EmpowerBannerAd
zoneId="YOUR_ZONE_ID"
style={{ width: '100%', minHeight: 50 }}
/>"No fill" from Google Ad Manager
This means no ad is available for your ad unit. Check that your applicationId in build.gradle matches the package name configured in your Google Ad Manager account.
SDK initializes but init() Promise never resolves
The init() Promise resolves when the SDK is fully ready (including Google Mobile Ads initialization). This can take a few seconds. If it never resolves, check logcat for errors:
adb logcat | grep EmpowerAdsNotes
- Android only: iOS support is not included in this bridge.
- Preroll Ads: Preroll ads require a native
PlayerViewand are not yet bridged as a React component. UsepausePreroll/resumePreroll/destroyPrerollfor lifecycle management. - Min SDK: Android API 21+ (Android 5.0)
License
MIT
