Gowri
Gowri

Reputation: 1856

Multiple GPT ads in same page with same ad size not working

I had a page with two GPT ads.

If the two ads are different size the ads are displayed in 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 ad is

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 the ads are same size not working

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

and second ad is

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

Please help me.

Upvotes: 5

Views: 5764

Answers (2)

Vaidas
Vaidas

Reputation: 141

I had the same issue and I came to the 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>

Upvotes: 6

mattoc
mattoc

Reputation: 712

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

Set these up in Inventory. When targeting the line items select the root_adunit (not mrec1 or mrec2) and available inventory should be loaded in to both mrec ad units accordingly.

Upvotes: -1

Related Questions