admob is not defined on phonegap

322 Views Asked by At

I have a simple test project phonegap based, i want to test my AdMob account.
I executed all the follow instructions by nodeJS command line:

D:\prova>cordova create prova2 io.prova.prova ProvaApp Creating a new cordova project.

D:\prova>cd prova2

D:\prova\prova2>cordova plugin add cordova-plugin-admobpro Adding cordova-plugin-admobpro to package.json Saved plugin info for "cordova-plugin-admobpro" to config.xml

D:\prova\prova2>

After build on line and the installation in my device, it returns the error :"admob is not defined" this is the code of my Html page:

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Security-Policy" content="default-src * data: content: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>  


<script>

function initAds() {
      if (admob) {
        var adPublisherIds = {
          ios : {
            banner : "ca-app-pub-2598287637019590/*********",
            interstitial : "ca-app-pub-2598287637019590/*********"
          },
          android : {
            banner : "ca-app-pub-2598287637019590/*******",
            interstitial : "ca-app-pub-2598287637019590/******"
          }
        };
       
        var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
            
        admob.setOptions({
          publisherId:      admobid.banner,
          interstitialAdId: admobid.interstitial,
        //  tappxIdiOS:       "/XXXXXXXXX/Pub-XXXX-iOS-IIII",
         // tappxIdAndroid:   "/XXXXXXXXX/Pub-XXXX-Android-AAAA",
          tappxShare:       0.5
        });

        registerAdEvents();
        
      } else {
        alert('AdMobAds plugin not ready');
      }
    }
    
    function onAdLoaded(e) {
      if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
        admob.showInterstitialAd();
        showNextInterstitial = setTimeout(function() {
          admob.requestInterstitialAd();
        }, 2 * 60 * 1000); // 2 minutes
      }
    }
    
    // optional, in case respond to events
    function registerAdEvents() {
      document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
      document.addEventListener(admob.events.onAdFailedToLoad, function (e) {});
      document.addEventListener(admob.events.onAdOpened, function (e) {});
      document.addEventListener(admob.events.onAdClosed, function (e) {});
      document.addEventListener(admob.events.onAdLeftApplication, function (e) {});
      document.addEventListener(admob.events.onInAppPurchaseRequested, function (e) {});
    }
        
    function onDeviceReady() {
      document.removeEventListener('deviceready', onDeviceReady, false);
   try {

   
      initAds();
 }
 catch(err) {
     alert(err.message);
 }
      // display a banner at startup
      admob.createBannerView();
        
      // request an interstitial
      admob.requestInterstitialAd();
    }
    
    document.addEventListener("deviceready", onDeviceReady, false);
 
</script>


</head>
<body>
 
    

</body>
</html>

what is wrong here?

0

There are 0 best solutions below