Multiple GPT ads in same page display only once
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
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?
Ads not display, in console i see error: Exception in queued GPT command TypeError: Cannot read property 'addService' of null .
Do you see it if you place it only once, but as I explained?
Yes, if i remove every other ads from body, then i see it
Take a look here: stackoverflow.com/questions/23236177/…
Then, I'm afraid, it's impossible task to do. You'll have to define different slots for GPTs, even though they can display the same ad.