Software Archive
Read-only legacy content
17060 Discussions

Admob interstitial after button click?

John_E_2
New Contributor I
869 Views

Hello can someone help me?

Now i have a banner and a interstitial that shows up when i start the app, i want the interstitial to show up after a button click not after 2-3 seconds after app start?

is this possible? 

this is the code iam using

<script src='cordova.js'></script>
    <script type="text/javascript">
        
        var onDeviceReady=function(){
            navigator.splashscreen.hide();
            initAdMob();
            showAdMobInterstitial();
            showAdMobBanner();
        };
        document.addEventListener("deviceready",onDeviceReady,false);
        
        function initAdMob(){
            if ( window.plugins && window.plugins.AdMob ) {
                var admob_key_banner = "xxxxxx";
                var admob_key_interstitial = "xxxxxx";
                window.plugins.AdMob.setOptions( {
                    publisherId: admob_key_banner,
                    bannerAtTop: false, // set to true, to put banner at top
                    overlap: false, // set to true, to allow banner overlap webview
                    offsetTopBar: true, // set to true to avoid ios7 status bar overlap                    
                    interstitialAdId: admob_key_interstitial,
                    autoShow: true, // autoshow intertitial Ad
                    isTesting: false // receiving test ad
                });
            } else {
                alert("AdMob plugin not ready");
            }
        }
        
        function showAdMobBanner(){
            window.plugins.AdMob.createBannerView();
        }
        
        function showAdMobInterstitial(){
            window.plugins.AdMob.createInterstitialView();
        }
        
    </script>  
        

0 Kudos
2 Replies
Amrita_C_Intel
Employee
869 Views

Hello,

  var onDeviceReady=function(){
            navigator.splashscreen.hide();
            initAdMob();
            showAdMobInterstitial();
            showAdMobBanner();
        };

You are calling this function inside device ready. what you should actually do is create a button handler, call this function over there.Then you should call the button handler inside device ready.

We have a blank template.Have a look the button responds only when all the ready functions are triggered.

Start a new project -> blank template -> General -> HTML5+Cordova .

0 Kudos
Anusha_M_Intel1
Employee
869 Views

Our admob sample actually activates the ads on button click. 

The sample ships with the XDK. You can create it by Start a new project -> Samples and Demos -> Genenral -> HTML5+Cordova -> Hello Admob. 

It uses the floatighoptspot third party plugin so you will have to build the app, but you can use it for code reference. 

Github link: https://github.com/gomobile/sample-hello-admob

0 Kudos
Reply