How do I show ads in Phonegap Build using the Phonegap-admob plugin?

90 Views Asked by At

I've been trying to make an app using HTML, CSS, and JS using Phonegap Build, but admob ads will not show up. My JS code for showing ads is:

<script src="code.js"></script>
        <script type="text/javascript">
            function onDeviceReady() {
      document.removeEventListener('deviceready', onDeviceReady, false);

      // Set AdMobAds options:
      admob.setOptions({
        publisherId:           "ca-app-pub-3940256099942544/6300978111",  // Required
        interstitialAdId:      "ca-app-pub-3940256099942544/1033173712",  // Optional
        autoShowBanner:        true,                                      // Optional
        autoShowRInterstitial: false,                                     // Optional
      });

      // Start showing banners (atomatic when autoShowBanner is set to true)
      admob.createBannerView();

      // Request interstitial ad (will present automatically when autoShowInterstitial is set to true)
    function showad(){
         admob.requestInterstitialAd();
    }

    }
    document.addEventListener("deviceready", onDeviceReady, false);
        </script>

I also have the Phonegap Build plugin inside my config.xml file along with support for the gap tag, but ads just won't show, when everything else is working fine. Please help.

1

There are 1 best solutions below

0
Miquel On

Here the author of phonegap-admob plugin.

Your config.xml should look like this:

<gap:plugin name="phonegap-admob" source="npm"/>

Normally it takes some days until you can start to see ads. Some things you could verify:

  • Seen a typo on admob.setOptions: autoShowRInterstitial --> autoShowInterstitial ('R' is incorrect)
  • publisherId is deprecated in the latest version, please use bannerAdId instead (even though it should work anyway)
  • Have you tried with test ads? What does it show? (https://admob-phonegap.com/set-options#baseoptions)
      admob.setOptions({
        bannerAdId:            "ca-app-pub-3940256099942544/6300978111",  // Required
        interstitialAdId:      "ca-app-pub-3940256099942544/1033173712",  // Optional
        autoShowBanner:        true,                                      // Optional
        autoShowInterstitial:  false,                                     // Optional
        isTesting:             true,                                      // Optional
      });

You can find complete documentation in https://admob-phonegap.com