npm.io
3.0.4 • Published 2 months ago

emi-indo-cordova-plugin-admob

Licence
MIT
Version
3.0.4
Deps
0
Size
233 kB
Vulns
0
Weekly
0
Stars
21

emi-indo-cordova-plugin-admob

NPM version Downloads License

The Future is Here: AdMob Next Gen

While this plugin (emi-indo) remains actively maintained and supported for existing users, we are developing the next evolution of AdMob integration at SwapLab Engine.

Check out cordova-plugin-admob-nextgen

Check out capacitor-admob-nextgen

  • New Projects: We highly recommend using the Next Gen plugin for modern architecture and long-term stability.
  • Existing Projects: You are safe to stay here, updates will continue as usual.

Cordova/Quasar/Capacitor Plugin for AdMob (Android & iOS)

This plugin supports the latest Mobile Ads SDK, User Messaging Platform (UMP), CMP, and various ad formats including Collapsible Banners.

Revenue Policy:

  • No Ad-Sharing: This plugin is purely rewritten and clean of 3rd party revenue-sharing code.
  • 100% Revenue: All ad revenue goes directly to you.
  • No Remote Control: You have full control over your implementation.

New Milestone 2026


Cloud Build (Quick Test)

Fastest test (APK Debug): With github action (Optional)


Features & Methods

  • Core: initialize, targeting, globalSettings
  • Privacy & Consent:
    • AppTrackingTransparency (ATT)
    • CMP SDK (IAB TCF v2.2)
    • UMP SDK
    • CustomConsentManager
  • Ad Formats:
    • App Open Ads
    • Banner Ads (including Collapsible & Adaptive)
    • Interstitial Ads
    • Rewarded Ads
    • Rewarded Interstitial Ads
  • Revenue & Advanced:
    • AdSense Support
    • Mediation (Meta, Unity, AppLovin, etc.)
    • Impression-level ad revenue
    • Targeting Request (targetingAdRequest, setPersonalizationState, setPPS)

Version 2.9.+ - 3+ Highlights

Current SDK Versions (Maintained & Up-to-Date)

This plugin is regularly updated to support the latest standards.

Component Platform Version Release Notes
Mobile Ads SDK Android 25.3.0 View Notes
UMP SDK Android 4.0.0 View Notes
Mobile Ads SDK iOS 13.3.0 View Notes
UMP SDK iOS 3.1.0 View Notes

Supported Frameworks

This plugin works seamlessly with the following frameworks:


Installation Cordova

1. Install Plugin

Android Only:

cordova plugin add emi-indo-cordova-plugin-admob --save --variable APP_ID_ANDROID=ca-app-pub-xxx~xxx

iOS Only:

cordova plugin add emi-indo-cordova-plugin-admob --save --variable APP_ID_IOS=ca-app-pub-xxx~xxx

Both Platforms (Recommended):

cordova plugin add emi-indo-cordova-plugin-admob --save --variable APP_ID_ANDROID=ca-app-pub-xxx~xxx --variable APP_ID_IOS=ca-app-pub-xxx~xxx

Remove Plugin:

cordova plugin rm emi-indo-cordova-plugin-admob
2. Important Steps for iOS

To prevent Xcode warnings or errors:

  1. After adding the platform/plugin, go to your project root and run: cordova prepare
  2. Navigate to the iOS folder: cd platforms/ios
  3. Run Pod install: pod install --repo-update

Screenshots & Demos

Video Demos:

Banner Ad: No Overlapping

The body height is reduced by the height of the banner. Auto-detects full-screen mode.

Banner Ad Collapsible (Non Full-Screen) Collapsible (Closed) Collapsible (Full-Screen) Collapsible (Closed FS)
Banner Ad Banner Ad Banner Ad Banner Ad
Banner Ad: Overlapping

The banner overlaps on top of the body. Auto-detects full-screen mode.

Banner Ad Collapsible (Full-Screen) Collapsible (Closed FS) Collapsible (Non Full-Screen) Collapsible (Closed)
Banner Ad Banner Ad Banner Ad Banner Ad
Other Formats
App Open Ad Interstitial Ad Rewarded Ad AdSense
App Open Ad Interstitial Ad Rewarded Ad AdSense

API & Usage Guide

1. Initialization (Required)

You must initialize the plugin before using any ads.

document.addEventListener("deviceready", function(){

    // 0. Method optional: cordova.plugins.emiAdmobPlugin.targeting({...})

    // 1. Initialize
    cordova.plugins.emiAdmobPlugin.initialize({
        isUsingAdManagerRequest: false, // true = AdManager | false = AdMob (Default false)
        isResponseInfo: false,          // Default false (Debug true)
        isConsentDebug: false,          // Default false (Debug true)
        
        // Targeting can be combined here. 
        // childDirectedTreatment: null, // true|false default: null (Enable COPPA true)
        // underAgeOfConsent: null, // true || false default: null (Enable teen privacy/TFUA true)
        // contentRating: "", // value: G | MA | PG | T | default: ""
    });

    // 2. Listen for SDK Ready
    document.addEventListener('on.sdkInitialization', (data) => {
        // Data available: version, adapters, consentStatus, gdprApplies, etc.
        console.log("On Sdk Initialization version: " + data.version);
        console.log("On Consent Status: " + data.consentStatus);
    });


     
     /*
          If you want to experiment,
          you can use the development method cordova.plugins.emiAdmobPlugin.consentReset()
          or option cordova.plugins.emiAdmobPlugin.showPrivacyOptionsForm()
     */
     // Optional New version 2.7.9+
     document.addEventListener('on.personalization.state', (data) => {
          // https://developers.google.com/admob/android/privacy/ad-serving-modes
          /*
          const personalizationState = data.personalizationState;
          const purposeConsents = data.purposeConsents;
          const gdprApplies = data.gdprApplies;
          */
         //  [INFO:CONSOLE:140] "on personalization state: {"isTrusted":false,"personalizationState":"PERSONALIZED","purposeConsents":"11111111111","gdprApplies":1}"
         console.log("on personalization state: " + JSON.stringify(data))

         if (data.personalizationState === "PERSONALIZED"){
            console.log("PERSONALIZED")
         } else if (data.personalizationState === "NON_PERSONALIZED"){
            console.log("NON_PERSONALIZED")
         } if (data.personalizationState === "LIMITED_OR_NO_ADS"){
           console.log("LIMITED_OR_NO_ADS")
        } else {
          console.log("UNKNOWN")
        }

 });



}, false);

Privacy & Consent (UMP/CMP/ATT):

// Show Privacy Options Form
cordova.plugins.emiAdmobPlugin.showPrivacyOptionsForm();

// Reset Consent (For testing)
cordova.plugins.emiAdmobPlugin.consentReset();

// iOS: Request App Tracking Transparency (ATT)
cordova.plugins.emiAdmobPlugin.requestIDFA();

// CMP SDK 2.2 (Get Data)
// Optional
cordova.plugins.emiAdmobPlugin.getIabTfc((IABTFC) => { 
    console.log(JSON.stringify(IABTFC)); 
});
View Consent Events
// Optional
document.addEventListener('on.get.consent.status', () => {
   console.log("on get consent status");
});
// Optional
document.addEventListener('on.TCString.expired', () => {
   console.log("on TCString expires 360 days");
   cordova.plugins.emiAdmobPlugin.consentReset();
});
2. Banner Ads
  • New large banner size adaptive: (Android | IOS)
  • large_anchored_adaptive
  • large_portrait_anchored_adaptive
  • large_landscape_anchored_adaptive
  • current_orientation_inline_adaptive
const bannerConfig = {
   adUnitId: "ca-app-pub-xxx/xxx", 
   position: "bottom-center", //  bottom-center | top-center
   size: "adaptive", // adaptive | banner | large_banner | full_banner | leaderboard | default: adaptive
   collapsible: false, // default false
   autoShow: true, // default false
   isOverlapping: false, // The height of the body is reduced by the height of the banner.
// padding: 0, // Optional: only isOverlapping: false, Extra 20px distance between WebView and Banner
// loadInterval: 5 // Opsional: Anti-Flicker/Spam, Default interval 5 seconds, disable 0
}

// Load
cordova.plugins.emiAdmobPlugin.loadBannerAd(bannerConfig);

// Other Methods
cordova.plugins.emiAdmobPlugin.showBannerAd();
cordova.plugins.emiAdmobPlugin.hideBannerAd();
cordova.plugins.emiAdmobPlugin.removeBannerAd();
Banner Events
on.banner.load
on.banner.failed.load
on.banner.click
on.banner.close
on.banner.impression
on.banner.open
on.banner.revenue
on.banner.remove
on.banner.hide
on.is.collapsible
on.bannerAd.responseInfo

// Example:
document.addEventListener('on.is.collapsible', function(event) {
    console.log("Collapsible Status: " + event.collapsible);
});
3. Interstitial Ads
// Load
cordova.plugins.emiAdmobPlugin.loadInterstitialAd({ 
    adUnitId: "ca-app-pub-xxx/xxx", 
    autoShow: true,
 // loadInterval: 5 // Opsional: Anti Spam, Default interval 5 seconds, disable 0 
});

// Show manually (if autoShow is false)
cordova.plugins.emiAdmobPlugin.showInterstitialAd();
Interstitial Events
on.interstitial.loaded
on.interstitial.failed.load
on.interstitial.click
on.interstitial.dismissed
on.interstitial.failed.show
on.interstitial.impression
on.interstitial.show
on.interstitial.revenue
on.interstitialAd.responseInfo

// Reload after dismiss:
document.addEventListener('on.interstitial.dismissed', () => {
   console.log("Ad dismissed. Reloading...");
   // loadInterstitialAd(...);
});
4. Rewarded Ads
// Load
cordova.plugins.emiAdmobPlugin.loadRewardedAd({ 
    adUnitId: "ca-app-pub-xxx/xxx", 
    autoShow: true,
// loadInterval: 5 // Opsional: Anti Spam, Default interval 5 seconds, disable 0  
});

// Show
cordova.plugins.emiAdmobPlugin.showRewardedAd();
Rewarded Events
on.rewarded.loaded
on.rewarded.failed.load
on.rewarded.click
on.rewarded.dismissed
on.rewarded.failed.show
on.rewarded.impression
on.rewarded.show
on.reward.userEarnedReward
on.rewarded.revenue
on.rewarded.ad.skip
on.rewardedAd.responseInfo
5. Rewarded Interstitial Ads
// Load
cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd({ 
    adUnitId: "ca-app-pub-xxx/xxx", 
    autoShow: true,
// loadInterval: 5 // Opsional: Anti Spam, Default interval 5 seconds, disable 0 
});

Supports similar events to Rewarded Ads (replace rewarded with rewardedInt).

6. App Open Ads
cordova.plugins.emiAdmobPlugin.loadAppOpenAd({ 
    adUnitId: "ca-app-pub-xxx/xxx", 
    autoShow: true,
// loadInterval: 5 // Opsional: Anti Spam, Default interval 5 seconds, disable 0 
});
7. Advanced Configuration (Android Only)

Targeting & PPS:

// Optional
// 1. Targeting Request
const configAdRequest = {
    customTargetingEnabled: false,
    categoryExclusionsEnabled: false,
    ppIdEnabled: false,
    contentURLEnabled: false,
    brandSafetyEnabled: false,
    customTargetingValue: ["24", "25"], 
    categoryExclusionsValue: "automobile",
    ppIdValue: "AB123456789",
    contentURLValue: "[https://www.example.com](https://www.example.com)"
}
cordova.plugins.emiAdmobPlugin.targetingAdRequest(configAdRequest);

// 2. Personalization State
// Optional
cordova.plugins.emiAdmobPlugin.setPersonalizationState({
    setPersonalizationState: "disabled" // "disabled" | "enabled"
});

// 3. PPS
// Optional
cordova.plugins.emiAdmobPlugin.setPPS({
    ppsEnabled: true,
    iabContent: "IAB_AUDIENCE_1_1", 
    ppsArrValue: [6,284]
});
8. Advanced Configuration (iOS Only)

Force Privacy Form Display: Useful if TCString is null due to ATT status.

// Optional
document.addEventListener('on.sdkInitialization', (data) => {
    let userGdpr = data.gdprApplies;
    let userTCString = data.consentTCString;

    if (userGdpr === 1 && userTCString === null){
        cordova.plugins.emiAdmobPlugin.forceDisplayPrivacyForm();
    }
});

Mediation Support

Click to view Mediation Adapters & Installation
1. Meta Audience Network
  • Default Adapter: 6.13.7.0
cordova plugin add emi-indo-cordova-plugin-mediation-meta
2. Unity Ads
  • Default Adapter: 4.6.1.0
cordova plugin add emi-indo-cordova-plugin-mediation-unity
3. AppLovin
  • Default Adapter: 11.8.2.0
cordova plugin add emi-indo-cordova-plugin-mediation-applovin
4. AdColony
  • Default Adapter: 4.8.0.1
cordova plugin add emi-indo-cordova-plugin-mediation-adcolony
5. Chartboost
  • Default Adapter: 9.2.1.0
cordova plugin add emi-indo-cordova-plugin-mediation-chartboost
6. ironSource
  • Default Adapter: 7.2.7.0
cordova plugin add emi-indo-cordova-plugin-mediation-ironsource
Locking Adapter Versions

To ensure stability, you can lock specific adapter versions using variables:

CLI Example:

cordova plugin add emi-indo-cordova-plugin-mediation-meta --save --variable META_ADAPTER_VERSION="xxxxx" --variable IOS_META_ADAPTER_VERSION="xxxxx"

Config.xml Example:

<preference name="META_ADAPTER_VERSION" value="xxxxx" />
<preference name="IOS_META_ADAPTER_VERSION" value="xxxxx" />

Available Variables:

  • META_ADAPTER_VERSION / IOS_META_ADAPTER_VERSION
  • UNITY_ADAPTER_VERSION / IOS_UNITY_ADAPTER_VERSION
  • APPLOVIN_ADAPTER_VERSION / IOS_APPLOVIN_ADAPTER_VERSION
  • ADCOLONY_ADAPTER_VERSION / IOS_ADCOLONY_ADAPTER_VERSION
  • CHARTBOOST_ADAPTER_VERSION / IOS_CHARTBOOST_ADAPTER_VERSION
  • IRONSOURCE_ADAPTER_VERSION / IOS_IRONSOURCE_ADAPTER_VERSION

Older Versions / History

Click to view details for older plugin versions
Minimum Engines
  • cordova-android version = 12.0.0
  • cordova-ios version = 7.0.0
iOS Notes
  • iOS 18 Support: Discussion #42
  • Mobile Ads SDK iOS 11.12.0: Requires cocoapods 1.16.2+
  • Xcode: Minimum 15.3+
  • macOS: Minimum 14.4+
  • Swift: 5.10+
Video Tests (Old Versions)

Support the Project

This plugin is developed and maintained in my free time. If it saved you hours of work, consider supporting the development!

Buy Me A Coffee

Your support helps me keep the dependencies updated and the cleaner script running smoothly.

Other Plugins by EMI-INDO

Keywords