我尝试使用来自https://gentlenode.com/journal/meteor-18-add-google-adsense-to-your-application/37的相同代码 ,这适用于 AdSense,但不适用于 Google DFP 代码。Google js 不会触发标签内的任何代码。
Template.sidebar.rendered = function() {
$.getScript("//www.googletagservices.com/tag/js/gpt.js", function() {
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.defineSlot('/58419895/sidebar_large', [300, 600], 'div-gpt-ad-1432029985552-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
var ads = "<div id='div-gpt-ad-1432029985552-0' style='height:600px; width:300px;'>";
$("#square-long").html(ads);
return googletag.cmd.push(function() { googletag.display('div-gpt-ad-1432029985552-0'); });
});
};