Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 944
Gowri Avatar asked Apr 23 '14 06:04

Gowri


1 Answers

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>

like image 58
Vaidas Avatar answered Sep 27 '22 21:09

Vaidas