2

我们有一个正在运行的项目,客户要求在其中实施 Google DoubleClick for Advertising。客户给了我们来自 DFA 的示例代码,我们试图在我们的类别页面中实现它,但它根本不起作用。任何人都可以看看下面,让我知道可能是什么广告根本没有显示并且只抛出错误。

标题部分

    <script type='text/javascript'>
vargoogletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
varuseSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') + 
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>


<script type="text/javascript"> 
googletag.cmd.push(function() {
googletag.defineSlot('/2408346/Asociacion_bottom', [728, 90], 'div-gpt-ad-1340819095858-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

文件正文部分

<div id='div-gpt-ad-1340819095858-0' style='width:728px; height:90px;'>
<script type='text/javascript'>
        googletag.cmd.push(function() { googletag.display('div-gpt-ad-1340819095858-0'); });
</script>
</div>

抛出错误并且根本不显示任何广告(即使在所有浏览器中):

错误列表

googletag is not defined
[Break On This Error] vargoogletag = googletag || {};

googletag is not defined
[Break On This Error] googletag.cmd.push(function() {

googletag is not defined
[Break On This Error] googletag.cmd.push(function() { goog...y('div-gpt-ad-1340819095858-0'); }); 
4

2 回答 2

5

看起来您的脚本中有一些语法错误。

这一行:

vargoogletag = 谷歌标签 || {};

应该:

var googletag = googletag || {};

并且 varuseSSL 也应该有一个空格... var useSSL

试试这个:

<html>
<head>
    <title>DFP test</title>

    <script type='text/javascript'>
        var googletag = googletag || {};
        googletag.cmd = googletag.cmd || [];
        (function() {
            var gads = document.createElement('script');
            gads.async = true;
            gads.type = 'text/javascript';
            var useSSL = 'https:' == document.location.protocol;
            gads.src = (useSSL ? 'https:' : 'http:') +
            '//www.googletagservices.com/tag/js/gpt.js';
            var node = document.getElementsByTagName('script')[0];
            node.parentNode.insertBefore(gads, node);
        })();
    </script>


    <script type="text/javascript">
        googletag.cmd.push(function() {
            googletag.defineSlot('/2408346/Asociacion_bottom', [728, 90], 'div-gpt-ad-1340819095858-0').addService(googletag.pubads());
            googletag.pubads().enableSingleRequest();
            googletag.enableServices();
        });
    </script>

</head>
<body>

    <div id='div-gpt-ad-1340819095858-0' style='width:728px; height:90px;'>
        <script type='text/javascript'>
                googletag.cmd.push(function() { googletag.display('div-gpt-ad-1340819095858-0'); });
        </script>
    </div>

</body>
</html>
于 2012-08-26T19:56:23.253 回答
0

besides the typos, you probably have a minify plugin that is conflicting with your ads.

于 2017-01-15T22:29:17.933 回答