Admob not working in beta10 version why?

Property ‘AdMob’ does not exist on type ‘Window’.
Cannot find name ‘AdMob’.

I have used admob from below tutorial

It was working previous version, but not working in new ionic2 version. What is the solution ??

This blog post is rather old and out of date.

If you need to setup admob, you can use the Admob class in ionic native.

1 Like

I have also tried

 import {
     Component
 } from '@angular/core';
 import {
     Platform,
     ionicBootstrap
 } from 'ionic-angular';
 import {
     StatusBar
 } from 'ionic-native';
 import {
     TabsPage
 } from './pages/tabs/tabs';


 @Component({
     template: '<ion-nav [root]="rootPage"></ion-nav>'
 })
 export class MyApp {

     private rootPage: any;
     admobid;
     AdMob;
     constructor(private platform: Platform) {
         this.rootPage = TabsPage;

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

             var admobid = {};
             if (/(android)/i.test(navigator.userAgent)) { // for android & amazon-fireos
                 admobid = {
                     banner: 'ca-app-pub-4223239210107153/9484228125', // or DFP format "/6253334/dfp_example_ad"
                     interstitial: 'ca-app-pub-4223239210107153/1960961324'
                 };
             } else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios
                 admobid = {
                     banner: 'ca-app-pub-4223239210107153/9484228125', // or DFP format "/6253334/dfp_example_ad"
                     interstitial: 'ca-app-pub-4223239210107153/1960961324'
                 };
             } else { // for windows phone
                 admobid = {
                     banner: 'ca-app-pub-4223239210107153/9484228125', // or DFP format "/6253334/dfp_example_ad"
                     interstitial: 'ca-app-pub-4223239210107153/1960961324'
                 };
             }
             if (AdMob) AdMob.createBanner({
                 adId: admobid.banner,
                 position: AdMob.AD_POSITION.TOP_CENTER,
                 autoShow: true
             });
             if (AdMob) AdMob.prepareInterstitial({
                 adId: admobid.interstitial,
                 autoShow: false
             });
             if (AdMob) AdMob.showInterstitial();

         });
     }
 }
 ionicBootstrap(MyApp)

but it shows error

TypeScript error: app/app.ts(40,6): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(40,13): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(41,17): Error TS2339: Property 'banner' does not exist on type '{}'.
TypeScript error: app/app.ts(42,13): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(44,6): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(44,13): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(44,54): Error TS2339: Property 'interstitial' does not exist on type '{}'.
TypeScript error: app/app.ts(45,6): Error TS2304: Cannot find name 'AdMob'.
TypeScript error: app/app.ts(45,13): Error TS2304: Cannot find name 'AdMob'.

That POC works for me:

1) Create project:

ionic start ionic2admob tabs --v2

cd ionic2admob 	

2) Add android platform:

ionic platform add android

3) Add ios platform:

ionic platform add ios

4) Add AdMob plugin:

ionic plugin add cordova-plugin-admobpro

5) Import AdMob in app.ts:

import {StatusBar, AdMob} from 'ionic-native';

6) Add code to platform.ready().then(() => { … } in App.ts:

var admobid = {};
// select the right Ad Id according to platform
if (/(android)/i.test(navigator.userAgent)) {
admobid = { // for Android
  banner: 'ca-app-pub-6869992474017983/9375997553',
  interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
  banner: 'ca-app-pub-6869992474017983/4806197152',
  interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
} else {
admobid = { // for Windows Phone
  banner: 'ca-app-pub-6869992474017983/8878394753',
  interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
}

AdMob.createBanner({
isTesting: true,
autoShow: true
});

7) Build Android:

ionic build android

8) Copy .apk to Android device and install it.

1 Like

How do we define where the banner should show? If I try “position: AdMob.AD_POSITION.BOTTOM_CENTER,” it says "AD_POSITION does not exist on type ‘typeof AdMob’ " and if I build it, the app won’t start then?

Hi hackepeterie,
I’ve got the same error: Property ‘AD_POSITION’ does not exist on type ‘typeof AdMob’.
I’ve got around it by changing position: AdMob.AD_POSITION.BOTTOM_CENTER, to position: 8,

You can find the integer value in plugin.js
AD_POSITION = {
NO_CHANGE: 0,
TOP_LEFT: 1,
TOP_CENTER: 2,
TOP_RIGHT: 3,
LEFT: 4,
CENTER: 5,
RIGHT: 6,
BOTTOM_LEFT: 7,
BOTTOM_CENTER: 8,
BOTTOM_RIGHT: 9,
POS_XY: 10
};

       .AD_SIZE = {
       SMART_BANNER: 'SMART_BANNER',
       BANNER: 'BANNER',
       MEDIUM_RECTANGLE: 'MEDIUM_RECTANGLE',
       FULL_BANNER: 'FULL_BANNER',
       LEADERBOARD: 'LEADERBOARD',
       SKYSCRAPER: 'SKYSCRAPER'
       };

Hope it helps,

1 Like

Thanks a lot, Ben_c! I was having the same problem and your workaround saved me!

Now I got another problem… on the page construction I prepare an interestial ad, and show it after a certain action. What is happening is that it’s being shown only once! When I repeat the action, it was supposed to be showed again. This behavior is desired because this action will not be repeated many times… and what is happening is that I have to close the app, kill it, open it again, do the action, and only at this moment the interestial ad shows up again. Can anybody help me?