Multiple GPT ads on the same page with the same ad size do not work

I had a page with two GPT ads.

If these ads are of different sizes, the ads appear on the page.

The following code is working fine

googletag.defineSlot("/123/test", [728, 90], "div-gpt-ad-123456789-0")
.addService(googletag.pubads())
.setTargeting("interests", ["sports", "music", "movies"]);

and second announcement

googletag.defineSlot("/123/test", [[468, 60], [728, 90], [300, 250]], "div-gpt-ad-123456789-1")
    .addService(googletag.pubads())
    .setTargeting("gender", "male")
.setTargeting("age", "20-30");

But if an ad of the same size doesn’t work

 googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0")
    .addService(googletag.pubads())
    .setTargeting("interests", ["sports", "music", "movies"]);

and second announcement

googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1")
    .addService(googletag.pubads())
    .setTargeting("gender", "male")
.setTargeting("age", "20-30");

Please help me.

+4
source share
2 answers

I had the same problem and came to a solution:

<html>
<head>
  <script src="http://www.googletagservices.com/tag/js/gpt.js"></script>
  <script type="text/javascript">
    var gptAdSlots = [];
    googletag.cmd.push(function() {

      gptAdSlots[0] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-0")
                             .addService(googletag.pubads());

      gptAdSlots[1] = googletag.defineSlot("/123/test", [300, 250], "div-gpt-ad-123456789-1").
                             .addService(googletag.pubads());

      googletag.pubads().enableSingleRequest();

      // Disable initial load.
      googletag.pubads().disableInitialLoad();

      // Start ad fetching
      googletag.enableServices();
    });
  </script>
</head>
<body>
<div id='div-gpt-ad-123456789-0'>
  <script type='text/javascript'>
    googletag.cmd.push(function() { 
      googletag.display('div-gpt-ad-123456789-0');
      // Refresh ad.
      googletag.pubads().refresh([gptAdSlots[0]]);
    });
  </script>
</div>
<div id='div-gpt-ad-123456789-1'>
  <script type='text/javascript'>
    googletag.cmd.push(function() { 
      googletag.display('div-gpt-ad-123456789-1');
      // Refresh ad.
      googletag.pubads().refresh([gptAdSlots[1]]);
    });
  </script>
</div>
</body>

+1
source

Try using different child ad units:

googletag.defineSlot("/root_adunit/banner1", [728, 90], "div-gpt-ad-123456789-0")
googletag.defineSlot("/root_adunit/mrec1", [300, 250], "div-gpt-ad-123456789-1")
googletag.defineSlot("/root_adunit/mrec2", [300, 250], "div-gpt-ad-123456789-2")

. root_adunit ( mrec1 mrec2), mrec .

-1

Source: https://habr.com/ru/post/1537628/


All Articles