sunnycupertino / cordova-plugin-admob-simple

Cordova plugin allowing Admob interstitials and banner ads.
MIT License
164 stars 150 forks source link

Help to show banner #7

Closed Ogaiht10 closed 7 years ago

Ogaiht10 commented 8 years ago

I am new to android development with Cordova, I registered on AdMob, coded like the example "CODING DETAILS (Load interstitial first, show it later)" and called the "showBannerFunc ()" function. But nothing happened, the announcement did not show.

Can someone help me?

sunnycupertino commented 8 years ago

Sure, can you post your javascript file here please so we can check it.

Ogaiht10 commented 8 years ago

js.js:

document.getElementById('btnShow').addEventListener("click", Iniciar); function Iniciar() { showBannerFunc(); }

index.js:

(function () { "use strict"; document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false ); function onDeviceReady() { document.addEventListener( 'pause', onPause.bind( this ), false ); document.addEventListener( 'resume', onResume.bind( this ), false );
var parentElement = document.getElementById('deviceready'); initAd(); };

} )();

adMob.js :

//initialize the goodies function initAd(){ if ( window.plugins && window.plugins.AdMob ) { var ad_units = { ios : { banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE }, android : { banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE } }; var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;

        window.plugins.AdMob.setOptions( {
            publisherId: admobid.banner,
            interstitialAdId: admobid.interstitial,
            adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
            bannerAtTop: false, // set to true, to put banner at top
            overlap: true, // banner will overlap webview 
            offsetTopBar: false, // set to true to avoid ios7 status bar overlap
            isTesting: false, // receiving test ad
            autoShow: false // auto show interstitial ad when loaded
        });

        registerAdEvents();
        window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown
        window.plugins.AdMob.requestInterstitialAd();

    } else {
        //alert( 'admob plugin not ready' );
    }

} //functions to allow you to know when ads are shown, etc. function registerAdEvents() { document.addEventListener('onReceiveAd', function(){}); document.addEventListener('onFailedToReceiveAd', function(data){}); document.addEventListener('onPresentAd', function(){}); document.addEventListener('onDismissAd', function(){ }); document.addEventListener('onLeaveToAd', function(){ }); document.addEventListener('onReceiveInterstitialAd', function(){ }); document.addEventListener('onPresentInterstitialAd', function(){ }); document.addEventListener('onDismissInterstitialAd', function(){ window.plugins.AdMob.createInterstitialView(); //REMOVE THESE 2 LINES IF USING AUTOSHOW window.plugins.AdMob.requestInterstitialAd(); //get the next one ready only after the current one is closed }); }

//display the banner function showBannerFunc(){ window.plugins.AdMob.createBannerView(); } //display the interstitial function showInterstitialFunc(){ window.plugins.AdMob.showInterstitialAd(); }

sunnycupertino commented 8 years ago

Ok several questions: -Did you fill in your admob code here 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'? -Can you verify that both the initAd() function and also showBannerFunc() are being called? -Our plugin has a file called AdMob.js, but I see you have one called adMob.js. It would be wise to call your function something else. -Did you include all your javascript files in the top of the index.html?

Ogaiht10 commented 8 years ago

-Did you fill in your admob code here 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'? yes, only the banner: var ad_units = { //ios: { // banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE // interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE //}, android: { banner: 'ca-app-pub-8777866873579970/2002814268', //PUT ADMOB ADCODE HERE interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE } };

-Can you verify that both the initAd() function and also showBannerFunc() are being called? yes, they are being called

-Our plugin has a file called AdMob.js, but I see you have one called adMob.js. It would be wise to call your function something else. They are in different directories. Does the problem is this?

-Did you include all your javascript files in the top of the index.html? yes, but it includes at the end of index.html:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="scripts/platformOverrides.js"></script>
<script type="text/javascript" src="scripts/admob.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="scripts/jquery.min.js"></script>    
<script type="text/javascript" src="scripts/js.js"></script>
sunnycupertino commented 8 years ago

Ok put a code in for the interstitial also.

The javascript declarations should be at the top of the file.

Change the name of your admob.js file just to be safe.

Check the console for errors.

Ogaiht10 commented 8 years ago

I did everything but msm so the ads do not show.

the line "isTesting: false, // receiving test ad" has something to do with it? already tested it with true and false but none worked.

sunnycupertino commented 8 years ago

I have no idea, i suggest you start from scratch and put our code into the .js file cordova created without changing anything else, and you will see it does work.

Ogaiht10 commented 7 years ago

I was thinking maybe the ads do not work because I was running on "Ripple", so I tried to run the "device" to see if it worked. But when I tried to run on the device happened compilation error:

Severity Code Description Project File Line Suppression State Error FAILURE: Build failed with an exception. Pokemon JS 1
Error * What went wrong: Pokemon JS 1
Error A problem occurred configuring root project 'android'. Pokemon JS 1
Error > Could not resolve all dependencies for configuration ':_debugCompile'. Pokemon JS 1
Error > Could not find any version that matches com.google.android.gms:play-services-base:+. Pokemon JS 1
Error Searched in the following locations: Pokemon JS 1
Error https://repo1.maven.org/maven2/com/google/android/gms/play-services-base/maven-metadata.xml Pokemon JS 1
Error https://repo1.maven.org/maven2/com/google/android/gms/play-services-base/ Pokemon JS 1
Error file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-base/maven-metadata.xml Pokemon JS 1
Error file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-base/ Pokemon JS 1
Error Required by: Pokemon JS 1
Error :android:unspecified Pokemon JS 1
Error > Could not find any version that matches com.google.android.gms:play-services-ads:+. Pokemon JS 1
Error Searched in the following locations: Pokemon JS 1
Error https://repo1.maven.org/maven2/com/google/android/gms/play-services-ads/maven-metadata.xml Pokemon JS 1
Error https://repo1.maven.org/maven2/com/google/android/gms/play-services-ads/ Pokemon JS 1
Error file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-ads/maven-metadata.xml Pokemon JS 1
Error file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-ads/ Pokemon JS 1
Error Required by: Pokemon JS 1
Error :android:unspecified Pokemon JS 1
Error * Try: Pokemon JS 1
Error Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Pokemon JS 1
Error Error code 1 for command: cmd with args: /s,/c,""d:\projetos\Pokemon JS\Pokemon JS\platforms\android\gradlew" cdvBuildDebug -b "d:\projetos\Pokemon JS\Pokemon JS\platforms\android\build.gradle" -Dorg.gradle.daemon=true -Pandroid.useDeprecatedNdk=true" Pokemon JS 1

"Pokemon JS" is the name of my app

sunnycupertino commented 7 years ago

Is this in Android Studio or eclipse?

It seems the play libraries are not installed on your system. Read the last part of our instructions here https://github.com/sunnycupertino/cordova-plugin-admob-simple

Ogaiht10 commented 7 years ago

Is Microsoft Visual Studio 2015!

sunnycupertino commented 7 years ago

Oh I don't know about that. It's hard to get support for developing Android on that platform as most people use Android Studio or Eclipse. I would recommend you use one of them, or find out how to integrate the play-services into Visual Studio.

Can I close this thread as it is a configuration issue with your development environment, which we do not support.

Ogaiht10 commented 7 years ago

ok can close,, thank you

rlam3 commented 6 years ago

@Ogaiht10 were you able to get this to work? I'm in a similar situation. Are you doing a cordova hybrid app? If so, do you mind sharing how you were able to get this to work?Thanks!