Search code examples
adsgoogle-dfp

Google's DoubleClick for Publishers Ad serving system is not working


We have a running project in which client has asked to implement Google DoubleClick for Advertising. Client has given us sample code from DFA which we have tried to implement in our category pages but it is not working at all. Can anyone please take a look below and let me know what it could be that ADs are not being displayed at all and throwing just errors.

HEADER PART:

    <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>

Document Body PART:

<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>

Throwing errors and not displaying any AD at all (even in all browsers):

ERRORS LIST:

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

Solution

  • It looks like you have some syntax errors in your script.

    This line:

    vargoogletag = googletag || {};

    Should be:

    var googletag = googletag || {};

    And varuseSSL should also have a space... var useSSL

    Try this:

    <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>