Ionic doesn't work with AdMob?

Hello there , that’s my first post in the forum :slight_smile: So I have the following issue , I’ve started learning ionic framework 2 weeks ago , I’ve installed ionic with

npm install -g ionic

And now I’m trying to run video reward ad or banner ad via AdMob plugin , but it doesn’t work.

home.html

  <p>
  <button ion-button (click)="loadAd();">Show Ad</button>
  </p>

home.ts

import { Component } from '@angular/core';
import { AdMob } from '@ionic-native/admob';
import { Platform } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {

  constructor(private admob: AdMob , private platform: Platform) {

  }

  loadAd() {
    this.admob.createBanner({
      adId: 'ca-app-pub-1603379825259521/2476422091',
      adSize: 'SMART_BANNER',
      isTesting: false
    }).then(() => {
      this.admob.showBanner(8);
    });
  }

Then Im running my project via Genymotion ( ionic cordova run android ) and nothing happens when I click the button. Any suggestions ? I really want to learn how to place ads and work with AdMob and Ionic. Is the issue related that I am running ionic 3 ? ( ionic -v returns 3.4.0). Any help is appreciated , thanks :slight_smile:

P.s I’ve also tried to run AdMob as it’s mentioned in the docs , but that didn’t work too.

ionViewDidLoad() {
  this.admob.onAdDismiss()
    .subscribe(() => { console.log('User dismissed ad'); });
}

onClick() {
  let adId;
  if(this.platform.is('android')) {
    adId = 'YOUR_ADID_ANDROID';
  } else if (this.platform.is('ios')) {
    adId = 'YOUR_ADID_IOS';
  }
  this.admob.prepareInterstitial({adId: adId})
    .then(() => { this.admob.showInterstitial(); });
}

Experiencing similar problem, ads are shown in debug mode but not shown in production mode in both Admob Pro and Admob Free.
Please anyone help.

I have the same problem, on release and debug mode, ads working fine, but on production mode don’t.

I found a solution.
Add AdMob library and functions to app.component.ts not to home.ts.

2 Likes

just try this in the command line(put your app Id between “”):

cordova plugin add cordova-plugin-admob-free --save --variable ADMOB_APP_ID=" YOUR_APP_ID "

example :

cordova plugin add cordova-plugin-admob-free --save --variable ADMOB_APP_ID="ca-app-pub-90001987983570300~8789081597

I published a nice tutorial, you can check it in medium https://link.medium.com/sPyP2QuVP5