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

Tag:google-ads-api, javascript, google-ad-manager, ads, wordpress

6 comments.

  1. Maksim I. Kuzmin

    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?

    1. klvb

      Ads not display, in console i see error: Exception in queued GPT command TypeError: Cannot read property 'addService' of null .

    2. Maksim I. Kuzmin

      Do you see it if you place it only once, but as I explained?

    3. klvb

      Yes, if i remove every other ads from body, then i see it

    4. Maksim I. Kuzmin

      Take a look here: stackoverflow.com/questions/23236177/…

    5. Maksim I. Kuzmin

      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.

Add a new comment.