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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With