Admob with ionic2


#1

Is anyone successfully using admob with ionic 2? Somehow it fails for me already just to place the banner on the bottom (No option seems to be available for putting on the bottom). If anyone was successful would be cool to see some code and/or feedback. thanks in advance


#2

Yea i do.

in your app.ts

declare var AdMob: any;
      initAdMob() {
        if (this.platform.is('ios')) {
          this.admobId = {
            banner: 'ca-app-pub-5903155652760586/XXX',
            interstitial: 'ca-app-pub-5903155652760586/XXX'
          };
        }
        if (this.platform.is('android')) {
          this.admobId = {
            banner: 'ca-app-pub-5903155652760586/XXX',
            interstitial: 'ca-app-pub-5903155652760586/XXX'
          }
        }
        if (this.platform.is('windows')) {
          this.admobId = {
            banner: 'ca-app-pub-5903155652760586/XXX',
            interstitial: 'ca-app-pub-5903155652760586/XXX'
          }
        }
      }


  createBanner() {
    if (AdMob) {
      AdMob.prepareInterstitial({
        adId: this.admobId.interstitial,
        autoShow: false,
        isTesting: true
      });
      AdMob.createBanner({
        adId: this.admobId.banner,
        autoShow: false,
        isTesting: true
      });
    }
  }

Now you can create a banner like this:

AdMob.showBanner(AdMob.AD_POSITION.BOTTOM_CENTER);


#3

I always get the following TS-error:

thanks in advance


#4

Got it - my fault was that I tried to import AdMob from ionic-native instead of just declare it on top as variable. Works now! :slight_smile:


#5

Yeah it is a bit confusing ^^


#6

Hello LoLStats,

I am using the latest version of ionic 2. I do not see an app.ts file. What file should this code goto?

Thank you