Multiple GPT ads in same page display only once

Viewed 478

i need display multiple ads on one page with this code:

<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<div id="gpt-passback650x250">
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot('/162717810/xxxxx/650x250', [650, 250], 'gpt- 
passback650x250').addService(googletag.pubads());
googletag.enableServices();
googletag.display('gpt-passback650x250');
});
</script>
</div>

If i use this code twice or more on page, i get error: Exception in queued GPT command TypeError: Cannot read property 'addService' of null

Code must be same, customer want paste it to page via shortcode in cms. How to solve this? Thanks

1 Answers

What happens if you put this:

<script>
    window.googletag = window.googletag || {cmd: []};
    googletag.cmd.push(function() {
    googletag.defineSlot('/162717810/xxxxx/650x250', [650, 250], 'gpt-passback650x250').addService(googletag.pubads());
    googletag.enableServices();
    googletag.display('gpt-passback650x250');
    });
</script>

...before </body>, and this:

<div id="gpt-passback650x250"></div>

...in every place you'd like to have ads?

Related