Ionic Admob Free Plugin cordova-plugin-admob-free

I have tried to use this plugin in Ionic 2 as shown there and add inside of src/app/app.components.ts ;

    import { TabsPage } from '../pages/tabs/tabs';

import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = TabsPage;

  constructor(private admobFree: AdMobFree,platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();


      const bannerConfig: AdMobFreeBannerConfig = {
         id: 'ca-app-pub-MYCODE',
         isTesting: true,
         autoShow: true
        };
      this.admobFree.banner.config(bannerConfig);
      this.admobFree.banner.show();  


    });
  }
}

like that code.

Also I import module,add provider to src/app/app.module.ts ;

import { AdMobFree } from '@ionic-native/admob-free';

@NgModule({
  declarations: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    AdMobFree,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

And when I try in emulator application work fine but ads not coming. Am I do something wrong ?

1 Like

You mean that you do not see any banner or only test banner? I have problem that I do not see any banner, my code is this (only difference is use of .prepare() because there is autoshow: true, so I think that it should show immediately after .prepare()):

    const bannerConfig: AdMobFreeBannerConfig = {
      id: 'ca-app-pub-xxxx',
      isTesting: true,
      autoShow: true
    }
    this.admobFree.banner.config(bannerConfig);
    this.admobFree.banner.prepare();

I use the admob.pro plugin but the code should be the same

          let admobConf;
          if (this.platform.is('ios')) {
            admobConf= {
              adId: 'ca-app-pub-5903155652760586/5935864956',
              isTesting: false,
              adSize: 'SMART_BANNER',
              position: this.admob.AD_POSITION.BOTTOM_CENTER
            }
            this.admob.createBanner(admobId);
          } else if (this.platform.is('android')) {
            admobConf= {
              adId: 'ca-app-pub-5903155652760586/4459131752',
              isTesting: false,
              adSize: 'SMART_BANNER',
              position: this.admob.AD_POSITION.BOTTOM_CENTER
            }
            this.admob.createBanner(admobConf);
          }

There is a little bit different API:


However it does not show anything on Android mobile phone.

When I use recommeded code in docs:

this.admobFree.banner.prepare()
  .then(() => {

  });

There is error that “this.admobFree.banner.prepare().then(…) is not defined”

When I use only: this.admobFree.banner.prepare(); app works but no banner is shown.

I found an example in Github

So what is different to what you tried before?

1 Like

3 posts were split to a new topic: admobFree: cordova_not_available

Hi, I am having the same issue, the add works ok when running in emulator. However, it is not working in the published app.

Here is a sample code, could you help please?

var admobid: AdMobType;
if (/(android)/i.test(navigator.userAgent)) {
  admobid = { // for Android
    banner: 'ca-app-pub-XXXXXX'
  };
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
  admobid = { // for iOS
    banner: 'ca-app-pub-XXXXXX'
  };
} else {
  admobid = { // for Windows Phone
    banner: 'ca-app-pub-XXXXX'
  };
}

this.admob.createBanner({
  adId: admobid.banner,
  position: this.admob.AD_POSITION.BOTTOM_CENTER,
  overlap:true,
  //isTesting: true,// works on emulator
  autoShow: true
})

app: https://play.google.com/store/apps/details?id=com.pokethemeerkat

Thank you.

Hello,
how could I set the AppId with this plugin?


MobileAds.initialize(this, “YOUR_ADMOB_APP_ID”);
Or which AppId is sending to Admob?
Please have a look here https://support.google.com/admob/answer/7356427?hl=de&ref_topic=7384409
To initialize the ad, you need the Admob App-Id and the Banner-Id, but the cordova-plugin-admob-free plugin only set the Banner-Id.
How to set the Admob App-Id in a native App is described here

I discuss the topic with google support and the admob appid is required to initialize the banner.
The request of a Ad without AdMob App-Id could work, but will be discontinued soon.

@jneumann did you get any solution , how to use app id for admob in ionic2/ionic3 . I am not using app id , just banner id is working good … can you provide some sample code for using app id

I published an articule in medium that could help you,

I’m using it in production and it works like a charm :slight_smile: