Admob Integration

6 posts, 0 answers
  1. sampath
    sampath avatar
    2 posts
    Member since:
    Nov 2014

    Posted 03 Nov 2014 Link to this post

    HI i have added admob in my app and its not showing any ads this is ads.js code

    var app = {
        // Application Constructor
        initialize: function() {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        // deviceready Event Handler
        //
        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicity call 'app.receivedEvent(...);'
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
        },
        // Update DOM on a Received Event
        receivedEvent: function(id) {
            var parentElement = document.getElementById(id);
            var listeningElement = parentElement.querySelector('.listening');
            var receivedElement = parentElement.querySelector('.received');

            listeningElement.setAttribute('style', 'display:none;');
            receivedElement.setAttribute('style', 'display:block;');

            console.log('Received Event: ' + id);
            
            if( window.AdMob ) {
                var adIdiOS = 'ca-app-pub-1241252919825525/1505824893';
                var adIdAndroid = 'ca-app-pub-1241252919825525/1505824893';
                var adId = (navigator.userAgent.indexOf('Android') >=0) ? adIdAndroid : adIdiOS;
                
            var am = window.AdMob;
            am.createBannerView( 
            {
            'publisherId' : adId,
    'adSize' : am.AD_SIZE.BANNER,
    'bannerAtTop' : true
            }, 
            function() {
            am.requestAd({
    'isTesting' : true,
    'extras' : {
    'color_bg' : 'AAAAFF',
    'color_bg_top' : 'FFFFFF',
    'color_border' : 'FFFFFF',
    'color_link' : '000080',
    'color_text' : '808080',
    'color_url' : '008000'
    }}, 
    function() {}, 
    function() {
    alert('Error requesting Ad');
    });
    }, 
    function() {
    alert('Error create Ad Banner');
    }
    );
            } else {
            alert( 'AdMob plugin not loaded.' );
            }
        }
    };
    and initialization
    <script type="text/javascript">
                app.initialize();
            </script> but still it does not show any ads in simulator or in my mobile. Can anyone help me.




  2. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 06 Nov 2014 Link to this post

    Hello Sampath,

    I think I found the culprits for your issue.
    First, I want to remark that custom plugins are not supported in the Simulator so it is expected to miss the adds there.

    Basically, I have made two changes in order to make your code working:
    1. Changed the way you initialize the plugin and check for its existence.
    2. Replaced your Android and iOS keys. Maybe you need to do some more adjustments in your AdMob account which are out of the scope of our service.

    if (window.plugins && window.plugins.AdMob) {
                var adIdiOS = 'ca-app-pub-1882245665150742/5173927112';
                var adIdAndroid = 'ca-app-pub-1882245665150742/7348664319';
                var adId = (navigator.userAgent.indexOf('Android') >= 0) ? adIdAndroid : adIdiOS;
                 
                var am = window.plugins.AdMob;

    If using the changes I provided does not help we might need your complete project attached in a private ticked open by you. Before that I suggest debugging your app on device in order to investigate any possible issues.

    Regards,
    Zdravko
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. sampath
    sampath avatar
    2 posts
    Member since:
    Nov 2014

    Posted 07 Nov 2014 Link to this post

    Thank you got is worked here is code and how do i enable interstatial ads

    <script>
        
        document.addEventListener("deviceready", onDeviceReady, false);
       
        function onDeviceReady() {
        var admob_ios_key = 'ca-app-pub-1241252919825525/1737667290';
        var admob_android_key = 'ca-app-pub-1241252919825525/1737667290';
        var adId = (navigator.userAgent.indexOf('Android') >=0) ? admob_android_key : admob_ios_key;
       
        if ( window.plugins && window.plugins.AdMob ) {
           
           var am = window.plugins.AdMob;
           am.createBannerView( 
            {
                   'publisherId': adId,
                   'adSize': am.AD_SIZE.BANNER,
                   'bannerAtTop': true                        
                   }, function() {
                    am.requestAd( { 'isTesting':true }, function() {
                    am.showAd( true );
                    }, function() {
                    alert('failed to request ad');
                    })
                   }, function(){
                    alert( "failed to create ad view" );
                   });
        } else {
        alert('AdMob plugin not available/ready.');
        }
        }
        function showAd( bshow ) {
        if ( window.plugins && window.plugins.AdMob ) {
           var am = window.plugins.AdMob;
           am.showAd( bshow );
        } else {
        alert('AdMob plugin not available/ready.');
        } 
        }
        </script>
  4. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 11 Nov 2014 Link to this post

    Hello Sampath,

    Thanks for sharing your findings with us.
    I am glad you have made it work on your side.

    Regards,
    Zdravko
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  5. Ariel
    Ariel avatar
    8 posts
    Member since:
    Sep 2014

    Posted 11 Nov 2014 in reply to Zdravko Link to this post

    Hello Zdravko,

    I have a this code and it shows add only in android, and not worked in case of iOS. Can you please suggest how to run it on iOS platform.

    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
    console.log("Device Ready");
        $.getScript('js/webcontent.js', function() {}); //WEBCONTENT(WORDPRESS REST API) FUNCTIONS
        $.getScript('js/tags.js', function() {}); //TAG FUNCTIONS
    $.getScript('js/upload.js', function() {}); //CAMERA AND UPLOAD FUNCTIONS
    getCategories();  //GET CATEGORIES FOR NAV
    showAdMob(); //SHOW ADMOB ADS
    }

    var ctl_api = "http://thecollegetown.life";


    function socialShare(){
    if (typeof window.plugins.socialsharing !== 'undefined'){
    var title = localStorage.getItem("title");
    var url = localStorage.getItem("url");
    var the_message
    console.log(title);
    console.log(url);
            window.plugins.socialsharing.share(null, null, null, url);
        }else{
        console.log("error in social sharing. PLugin is not initialized");
        }
    }

    function showAdMob(){

    if( window.plugins || window.plugins.AdMob ) {
    //var admob_ios_key = 'ca-app-pub-4626918179104727/2683983691';  //INTERSTITIAL
    var admob_ios_key = 'ca-app-pub-4626918179104727/4957099290';
    //var admob_android_key = 'ca-app-pub-4626918179104727/5358248496'; //INTERSTITIAL
    var admob_android_key = 'ca-app-pub-4626918179104727/5875429291';
    var adId = (navigator.userAgent.indexOf('Android') >=0) ? admob_android_key : admob_ios_key;

    //var am = window.plugins.AdMob || window.plugins;
            var am = window.plugins.AdMob;
        
    am.createBannerView( 
    {
    'publisherId': adId,
    'adSize': am.AD_SIZE.BANNER,
    'bannerAtTop': false
    }, 
              
    function() {
                   
    am.requestAd(
    { 'isTesting':false },
    function(){
    am.showAd( true );
    }, 
    function(){ console.log('failed to request ad'); }
    );
    },
               
    function(){ console.log('failed to create banner view'); }
    );
            

        else 
        {
    var networkstate = checkConnection();
    console.log(networkstate);
    }
    }

    /*
    function : getCategories
    params : nones
    returns : categories taxonomy 
    dataType : json
    */
    function getCategories(){
    $.ajax({
    type: 'GET',
    url: ctl_api + '/wp-json/taxonomies/category/terms/',
    dataType: 'json',
    success: function(data){
    console.log(data);
    //EXCLUDE (TWEETS OF THE WEEK)
    menuObj = [];
    $.each(data, function(index, element){
    if(element.slug != "tweets-of-the-week"){
    //CONVERT ANY SYMBOLS FROM HTML TO PLAIN TEXT
    var category_raw = element.name;
    var category_cleaned = $('<span>').html(category_raw).text();
    menuObj.push({'category_name' : category_cleaned , 'category_id' : element.slug});
    }
    });
    //SAVE MENU TO LOCALSTORAGE
    localStorage.setItem("menu", JSON.stringify(menuObj));
    },
    error: function(data){
    console.log(data);
    }
    });
    }
    /*
    function : checkConnection
    params : none
    returns : network state 
    dataType : json
    */
    function checkConnection() {
        var networkState = navigator.connection.type;
    return networkState;
    }

    Thanks & Regards
    Nitish




  6. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 14 Nov 2014 Link to this post

    Hello Ariel,

    In order to benefit from Telerik support services I will kindly ask you to consider renewing your license.

    Note that you can still use our forums to interact with our community and share knowledge with each other.
    Thank you.

    Regards,
    Zdravko
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top