3

尝试了几种方法,但仍然无法让 Google Ad 呈现。目的是根据窗口宽度响应式放置广告。但我什至无法放置一个广告。

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

/* 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')});
};

感谢您的考虑。

4

2 回答 2

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({});
  });
};
于 2014-08-16T21:52:52.383 回答
1

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

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

于 2013-06-01T02:50:14.853 回答