How to monetize a Ionic App?

Hi everyone! I searched in the forum, but I didn’t find a proper way to monetize a Ionic App…

I tried to use https://github.com/floatinghotpot/cordova-plugin-admob but I get a black rectangule… No ad is shown.

It would be wonderful that everybody can share their way to monetize your apps, in this forum.

Thanks in advance!

I use that plugin too and it works well.
Remember to call the plugin after deviceready event fires and call both createBannerView and requestAd functions.

@eugi , this is how I use it (it’s placed it in deviceready):

        if( window.plugins && window.plugins.AdMob ) {
            var admob_android_key = 'xxxxxxxxxx';
            var am = window.plugins.AdMob;

            am.createBannerView( 
            {
            'publisherId': admob_android_key,
            'adSize': am.AD_SIZE.BANNER,
            'bannerAtTop': false
            }, 
            function() {
                am.requestAd(
                    { 'isTesting':false}, 
                    function(){
                        am.showAd( true );
                    }, 
                    function(){ alert('failed to request ad'); }
                );
            }, 
            function(){ alert('failed to create banner view'); }
            );
        } else {
            alert('AdMob plugin not available/ready.');
        } 

Where xxxxxxxxxx refers to this: ca-app-pub-YYYYYYYYYYYYYY/xxxxxxxxxx

All this results into a black box without any ad…

I think you are using this framework: https://github.com/aliokan/cordova-plugin-admob
It’s not the same :stuck_out_tongue:

I use the same plugin as @masudjuan, and it works fine for me.

@masudjuan Does the isTesting flag change anything for you? No matter what I set it to, I never get test ads. I always get real ads.

The “thing” about isTesting , is that if you click an ad when testing:true, you won’t be “punished” for doing that. In real life, if you click your own ads you can be “punished” for doing that :mask: .

But my problem is that it doesn’t show any ads… It always shows me a black box, and nothing else :frowning: .

How do you manage to make it work? Can you help me or show me what you have done? @gki , I will really appreciate it.

I do use the first plugin you mentioned, and it works for me. The code is like yours, so there must be something else wrong.
Have you installed google play service plugin?
You can also try to see the log with adb logcat, maybe you notice something strange…

@masudjuan Here’s the code I’m using:

am.createBannerView(
  {
    'publisherId': MY_PUBLISHER_ID,
    'adSize': am.AD_SIZE.SMART_BANNER,
    'bannerAtTop': false
  },
  function() {
    am.requestAd(
      {
        'isTesting': true
      },
      function() {
        am.showAd(true);
      },
      function() {
        /* Handle error */
      }
    );
  },
  function() {
    /* Handle error */
  }
);

I have a call to this in $ionicPlatform.ready(function() { ... }).


I know what isTesting is supposed to be doing, but even after I set it to true AdMob was still tracking the ads and calculating revenue for it.

And I was seeing real ads from real products. I expect to see this:

admob text

Yes, I installed google play service plugin, but it is not working… I tried everything and I continue seeing a black box… I tried also what @gki post, and it’s not working for me… frowning

I can’t figure out what’s going on…

Try adb logcat to see if there is some error or such.
I usually do something like adb logcat | grep --line-buffered -i -e ads -e admob to see in realtime log messages related to ads or admob, then lunch the app.

If you’re talking about monetizing in general and not necessarily ads,
I use https://github.com/j3k0/PhoneGap-InAppPurchase-iOS in my apps for in app purchases.

I can’t get your logcat code work… But with adb logcat, I miraculously could see this:

TypeError: Cannot call method ‘showAd’ of undefined

What do you think that might be happening?

Sorry, grep only works in linux, I don’t know what is the equivalent in windows if you are using it.
Anyway, it seems that somewhere you are trying to call .showAd() function of something that does not exist (undefined). You should call it on window.plugins.AdMob.
Despite your code seems correct, try replace am.showAd(true) with window.plugins.AdMob.showAd(true) and make sure you are not calling showAd somewhere else.
If you want to debug a little further you can also try with Weinre.