0

I'm moving some of our older Phonegap 3 apps into build.phonegap.com and rebuilding with Phonegap 4. Impressed so far, but this next app has AdMob which was previously set up in the Java files directly, so I'm trying to rework...

As far as I can tell, the best mechanism for this is the cordova-admobpro plugin, so I've added:

<plugin name="cordova-plugin-admobpro"/>

to the config.xml . I've then added a new JS tag after /body as per the documentation (also tried inside the body but after the cordova.js tag, and inside the head with the defer attribute):

<script type="text/javascript" src="js/admob.js"></script>

Finally, I've built admob.js as per the various examples:

var admobid = {};

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

function initApp() {
    if(AdMob) {
        // this will create a banner on startup
        AdMob.createBanner( {
            adId: admobid.banner,
            position: AdMob.AD_POSITION.BOTTOM_CENTER,
            overlap: false,
            offsetTopBar: false,
            bgColor: 'black'
        } );

        // this will load a full screen ad on startup
        AdMob.prepareInterstitial({
            adId: admobid.interstitial,
            autoShow: true
        });
    }
}

if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
    document.addEventListener('deviceready', initApp, false);
} else {
    initApp();
}

(Obviously the banner ID's are real in the actual app)

This isn't working though. When compiled and installed to a device, I'm seeing neither the startup ad or the banner ad. Testing in a browser and code inspecting is useless since AdMob isn't going to exist until the plugin references in config.xml is compiled in.

Am I missing something blindingly obvious?

Ric
  • 458
  • 1
  • 7
  • 23
  • Turns out the Interstitial ads are working now, though I haven't changed anything at all. This was a new ad block set up in the Admob panel so perhaps just a delay in activation. The banner ads however, still don't appear at all. – Ric Mar 17 '17 at 19:32
  • Could it be because the UI uses jQueryMobile? I've not found anything suggesting extra steps need to be applied if using jQueryMobile... – Ric Mar 17 '17 at 19:34

1 Answers1

0

Oh dear... Turns out there was simply an error in the adblock ID used, and the integration itself works fine!

Ric
  • 458
  • 1
  • 7
  • 23