Adding Google Adsense to Meteor App

Tried several methods but couldn't get Google Ad rendering. The goal is to quickly place ads based on window width. But I cannot place even one ad.

Here's the most reliable method I can think of:

/* templates.html */
<head>
    <script type="text/javascript">
        var googletag = googletag || {};
        googletag.cmd = googletag.cmd || [];
    </script>
    <script type="text/javascript" src="http://www.googletagservices.com/tag/js/gpt.js">       </script>
</head>

<body>
    <div class="container">
        {{> page}}
    </div>
</body>

<template name="page">
    <div class="page_ad"></div>
</template>

/* client.js */
Template.page.rendered = function(){
    googletag.cmd.push(function() {
        googletag.defineSlot('LEADERBOARD', [728, 90], 'AD-CODE-ID').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
    });

    $('.page_ad').html("<div id='AD-CODE-ID' style='width:728px; height:90px;'>");

    googletag.cmd.push(function() { googletag.display('AD-CODE-ID')});
};

      

Thank you for your attention.

+3


source to share


2 answers


This is how I do it. Read more about this in this blog post .



Template.MyAds.rendered = function() {  
  $.getScript("//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", function() {
    var ads, adsbygoogle;
    ads = '<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-72414***074839" data-ad-slot="4009***57" data-ad-format="auto"></ins>';
    $('.leaderboard').html(ads);
    return (adsbygoogle = window.adsbygoogle || []).push({});
  });
};

      

+7


source


Check out the iframe solution here; Meteor JS: use an external script



Check information about this method against TOS; http://productforums.google.com/forum/#!category-topic/adsense/adsense-basics-and-policies/JP6vrWxFMVg

+1


source







All Articles