Admob Installation

This forum contains topics that were moved from Get Satisfaction
Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Are you running this on a real device or the appery tester?

It must be a real device

Miguel Angel Dulcey Diaz
Posts: 0
Joined: Tue Aug 27, 2013 3:31 am

Admob Installation

Post by Miguel Angel Dulcey Diaz »

Real device

Miguel Angel Dulcey Diaz
Posts: 0
Joined: Tue Aug 27, 2013 3:31 am

Admob Installation

Post by Miguel Angel Dulcey Diaz »

If it works .... Thanks Mark

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Admob Installation

Post by asid »

Hi

I have followed your code well. I am getting an error
Uncaught ReferenceError: AdMob is not defined, on browser and on actual device no adds show.

Is the below correct? Image

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Hi Andrew
Firstly Admob does not work using the browser or the tester. It must be a real device with an apk/ipa file loaded.

yes that code is correct.

What code did you add to your Javascript file?

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Admob Installation

Post by asid »

Hi Mark

Yes I now about running in browser, but same error you posted so just wondering if related.
Is the way I am calling the code correct on device ready event?

Here is may js code...

//Mark 2 months ago
//Ok I figured it out. To help those who wish to add admob to their app without exporting to eclipse etc, here are the steps to follow:~

//1. import the plugin from github https://github.com/floatinghotpot/cor... to appery as explained here https://devcenter.appery.io/documenta...

//2.Create new-JavaScript (or open your existing one)

//3. add the following code to the file

// place our admob ad unit id here
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-5402440256548539/5068785402',
interstitial: 'ca-app-pub-5402440256548539/6545518607'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-5402440256548539/6545518607'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-5402440256548539/5068785402',

interstitial: 'ca-app-pub-5402440256548539/6545518607'
};
}

function onDeviceReady() {
if (! AdMob) { alert( 'admob plugin not ready' ); return; }

initAd();

// display a banner at startup
createSelectedBanner();
}

function initAd(){
AdMob.setOptions({
// adSize: 'SMART_BANNER',
// width: integer, // valid when set adSize 'CUSTOM'
// height: integer, // valid when set adSize 'CUSTOM'
position: AdMob.AD_POSITION.BOTTOM_CENTER,

// offsetTopBar: false, // avoid overlapped by status bar, for iOS7+
bgColor: 'black', // color name, or '#RRGGBB'
// x: integer, // valid when set position to 0 / POS_XY
// y: integer, // valid when set position to 0 / POS_XY
isTesting: true, // set to true, to receiving test ad for testing purpose
// autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
});

// new events, with variable to differentiate: adNetwork, adType, adEvent
$(document).on('onAdFailLoad', function(data){
alert('error: ' + data.error +
', reason: ' + data.reason +
', adNetwork:' + data.adNetwork +
', adType:' + data.adType +
', adEvent:' + data.adEvent); // adType: 'banner', 'interstitial', etc.
});
$(document).on('onAdLoaded', function(data){});
$(document).on('onAdPresent', function(data){});
$(document).on('onAdLeaveApp', function(data){});
$(document).on('onAdDismiss', function(data){});

function createSelectedBanner(){
AdMob.createBanner({
adId: admobid.banner,
overlap: $('#overlap').is(':checked'),
offsetTopBar: $('#offsetTopBar').is(':checked'),
adSize: $('#adSize').val(),
position: $('#adPosition').val(),
});
}

function showBannerAtPosition(){
AdMob.showBanner( $('#adPosition').val() );
}

$('#btn_create').click(createSelectedBanner);
$('#btn_remove').click(function(){
AdMob.removeBanner();
});

$('#btn_show').click(showBannerAtPosition);
$('#btn_hide').click(function(){
AdMob.hideBanner();
});

// create a banner on startup
createSelectedBanner();

// test interstitial ad
$('#btn_prepare').click(function(){
AdMob.prepareInterstitial({
adId:admobid.interstitial,
autoShow: $('#autoshow').is(':checked'),
});
});

$('#btn_showfull').click(function(){
AdMob.showInterstitial();
});

// test case for #256, https://github.com/floatinghotpot/cor...
$(document).on('backbutton', function(){
if(window.confirm('Are you sure to quit?')) navigator.app.exitApp();
});

// test case #283, https://github.com/floatinghotpot/cor...
$(document).on('resume', function(){
AdMob.showInterstitial();
});
}

// test the webview resized properly
$(window).resize(function(){
$('#textinfo').html('web view: ' + $(window).width() + " x " + $(window).height());
});

$(document).ready(function(){
// on mobile device, we must wait the 'deviceready' event fired by cordova
if(/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent)) {
document.addEventListener('deviceready', onDeviceReady, false);
} else {
onDeviceReady();
}
});

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Admob Installation

Post by asid »

Hi Mark, any suggestions?

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Hi Andrew
Your code is the same as mione. The only thing I forgot to ask was did you import Admob or Admob Pro. Admob Pro worked for me

Image

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Admob Installation

Post by asid »

I did import Admob Pro, now version 2.130. We don't put anything under the options button?

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

No.

I am going to use 2.130 on a test app now and will get back to you shortly

Post Reply