Burak Güneli
Burak Güneli

Reputation: 124

interstitial ad don't show up (AngularJs)

my app.js :

$ionicPlatform.ready(function() {
   var admobid = {};
    // select the right Ad Id according to platform
    if( /(android)/i.test(navigator.userAgent) ) { 
        admobid = { // for Android
            interstitial: 'ca-app-pub-3940256099942544/1033173712'
        };
    } else {
        admobid = { // for Windows Phone
            interstitial: 'ca-app-pub-3940256099942544/1033173712'
        };
    }

   if(window.AdMob) AdMob.prepareInterstitial({
        adId:admobid.interstitial,
        isTesting:true,
        autoShow:false
   });

my controller.js :

.controller('ChatsCtrl', function($scope, Chats) {


  $scope.$on('$ionicView.beforeEnter', function(e) {
    if (window.AdMob) AdMob.showInterstitial();
  });

  $scope.$on('$ionicView.beforeLeave', function(e) {
    if (window.AdMob) AdMob.showInterstitial();
  });

})

I'm building an ionic framework app for android and i need to add it a interstitial ad, it should run whenever user enters chats tab.

Here is my code, i copied most part of it from http://pointdeveloper.com/how-to-add-interstitial-ads-on-navigation-to-ionic-framework-apps/ .

I changed interstitial: 'ca-app-pub-3940256099942544/1033173712' parts with my own key but it didn't work. Where is the problem?

(I'm testing it in both my android phone(Nexus 5) and Genymotion android emulator)

Upvotes: 1

Views: 209

Answers (1)

Miquel
Miquel

Reputation: 8979

The internal life cicle for interstitial ads when requestInterstitialAd is called is the following one, you can read more here: https://github.com/appfeel/admob-google-cordova/wiki/requestInterstitialAd

requestInterstitialAd();
options.autoShowInterstitial == true ? showInterstitial : raise(admob.events.onAdLoaded)

So if you have set options.autoShowInterstitial = true, then it should be automatically shown, otherwiese, you should call admob.requestInterstitialAd and wait for admob.events.onAdLoaded with atType === 'interstitial' to be raised. Then you should do something like:

document.addEventListener(admob.events.onAdLoaded, function (e) {
    if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
        admob.showInterstitialAd();
    }
});

Upvotes: 1

Related Questions