Admob with ionic2

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

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);

2 Likes

I always get the following TS-error:
image

thanks in advance

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:

Yeah it is a bit confusing ^^

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

1 Like