将Google Adsense添加到Meteor应用程序

Par*_*ndl 3 meteor

尝试过多种方法,但仍然无法使用Google广告进行渲染.目的是响应性地根据窗口宽度放置广告.但我甚至无法放置一个广告.

这是我能想到的最可靠的方法:

/* 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')});
};
Run Code Online (Sandbox Code Playgroud)

谢谢你的考虑.

Jul*_*nec 7

我就是这样做的.您可以在此博客文章中阅读更多相关信息.

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({});
  });
};
Run Code Online (Sandbox Code Playgroud)

  • gentlenode下来了吗?真可惜.该期刊是一个很好的资源. (2认同)