npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-ads

v2.0.5

Published

Cordova plugin to add ads into an app. Use javascript to request ads by AdMob.

Downloads

34

Readme

Cordova-Plugin-Ads

jump to: PLUGIN USAGE | Cordova | ADD ADS | More | cozycode.ca | Open Source License

Updated 2023 for Cordova with tracking consent:

To include ads without any tracking, see: cordova-plugin-ads-donottrack

Cordova plugin to add ads (by Google AdMob) into an app. Use JavaScript to include ads in your app.

If you notice any issues, submit here: github issues

Have a good one!

PLUGIN USAGE

Add these calls inside of your cordova JavaScript to show ads:

banner ads adMob.banner(bannerId,adMob.ad_sizes.RESIZE,adMob.ad_positions.TOP) adMob.removeBanner()

full screen ads adMob.interstitial(interstitialId) adMob.showInterstitial()

rewarded video ads adMob.rewarded(rewardedId) adMob.showRewarded()

rewarded full screen video ads (new, and better supported than rewarded ads) adMob.rewardedInterstitial(rewardedInterstitialId) adMob.showRewardedInterstitial()

The plugin creates an adMob object that can request to load new ads. Note: to fund the development of the plugin, the plugin requests 2% of ads for the plugin developer. It seems there are a lot of Cordova ad plugins that request this lol, it can there even if not said.

CREATE AN APP WITH CORDOVA

How to create a Cordova app:

npm install -g cordova
cordova create directory_name com.your_name_or_company.your_app_name

Cordova is an open source project maintained by Apache that lets you make apps written in HTML, css, and JavaScript. You can create cross-platform apps to publish on the Google Play Store for Android, and the Appstore for iOS, MacOS, and Apple devices.

ADD ADS

  1. Add the plugin
cordova plugin add cordova-plugin-ads
  1. Test that ads are working using test ads. Use the id "test" to load test ads from the plugin.
var test_ad_id = "test";

async function runAllOfTheAds(){
    await adMob.banner(test_ad_id).then(function(){
        alert("loaded banner ads");
    }).catch(function(err){
        alert("unable to load ads: "+JSON.stringify(err));
    });
    
    await adMob.interstitial(test_ad_id).then(function(){
        alert("loaded interstitial ads");;
        return adMob.showInterstitial();
    }).then(function(){
        alert("showed interstitial ads");
    }).catch(function(err){
        alert("unable to load ads: "+JSON.stringify(err));
    });
    
    await adMob.rewarded(test_ad_id).then(function(){
        console.log("loaded rewarded ads");
        return adMob.showRewarded();
    }).then(function(reward){
        alert("showed rewarded ads"+JSON.stringify(reward));
    }).catch(function(err){
        alert("unable to load rewarded ads: "+JSON.stringify(err));
    });
    
    await adMob.rewardedInterstitial(test_ad_id).then(function(){
        alert("loaded rewarded ads");
        return adMob.showRewardedInterstitial();
    }).then(function(reward){
        alert("showed rewarded ads"+JSON.stringify(reward));
    }).catch(function(err){
        alert("unable to load rewarded ads: "+JSON.stringify(err));
    });

}

function onDeviceReady() {
    runAllOfTheAds();
}
  1. In your Google AdMob account, create ad units for your apps - note that the ads may return LOAD_AD_ERRORS errors (especially iOS) until the app has been approved, or while during testing
var admob_ids = {
    'android' : {
        'banner': "ca-app-pub-4029587076166791/6431168058",
        'interstitial': "ca-app-pub-4029587076166791/1370413062",
        'rewarded': "ca-app-pub-4029587076166791/9712771663",
        'rewardedInterstitial': "ca-app-pub-4029587076166791/3530506691"
    }, 'ios' : {
        'banner': "ca-app-pub-4029587076166791/6694891931",
        'interstitial': "ca-app-pub-4029587076166791/2436352227",
        'rewarded': "ca-app-pub-4029587076166791/5286441495",
        'rewardedInterstitial': "ca-app-pub-4029587076166791/2300620853"
    }
};

adMob.banner(admob_ids).then(function(){
    console.log("loaded banner ad");
}).catch(function(err){
    console.log("unable to load banner ad: "+JSON.stringify(err));
});
    
adMob.interstitial(admob_ids).then(function(){
    console.log("loaded interstitial ads");;
    return adMob.showInterstitial();
}).then(function(){
    console.log("showed interstitial ads");
}).catch(function(err){
    console.log("unable to load interstitial ads: "+JSON.stringify(err));
});

adMob.rewarded(admob_ids).then(function(){
    console.log("loaded rewarded ads");
    return adMob.showRewarded();
}).then(function(reward){
    console.log("showed rewarded ads"+JSON.stringify(reward));
}).catch(function(err){
    console.log("unable to load rewarded ads: "+JSON.stringify(err));
});

adMob.rewardedInterstitial(admob_ids).then(function(){
    console.log("loaded rewarded ads");
    return adMob.showRewardedInterstitial();
}).then(function(reward){
    console.log("showed rewarded ads"+JSON.stringify(reward));
}).catch(function(err){
    console.log("unable to load rewarded ads: "+JSON.stringify(err));
});

More on the plugin:

  • wait for deviceready to fire before calling any functions
  • errors can be automatically retried after a timeout or ignored
  • adMob uses a promise-based API to load ads
  • since the API returns a promise, it is asynchronous... call it and continue with other actions, or await for it to finish from within an async function to wait for the call to finish

More from cozycode.ca

Open Source License

MIT Licensed (MIT)

Copyright © 2023 cozycode.ca

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.