We just have one gpt ad tag from our advertising partner. On the same page, we want to deliver multiple ads using the same ad unit. We used our ad tag to implement this official Google document: https://developers.google.com/publisher-tag/samples/infinite-content. Only the first ad gets served, though. A google-query-id is formed on each new tag as we generate more advertising, however no ads are really displayed. Are we making any mistakes, and what has to be set up on the side of the ad partner Google Ad Manager?
Code:
<html>
<head>
<title>Infinite content example</title>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
window.googletag = window.googletag || {
cmd: []
};
googletag.cmd.push(function() {
googletag
.defineSlot(
"/XXXXXX/XXXXXX", [
[300, 100],
[200, 200],
[300, 300],
[200, 250],
[250, 250],
[300, 250],
[750, 200],
[970, 250],
],
"div-gpt-ad-some-id"
)
.setTargeting("test", "infinitescroll")
.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
// Function to add content to page
function moreContent() {
// Define the slot itself, register it and fetch an ad.
googletag.cmd.push(function() {
var slot = googletag
.defineSlot("/XXXXXX/XXXXXX", [
[300, 100],
[200, 200],
[300, 300],
[200, 250],
[250, 250],
[300, 250],
[750, 200],
[970, 250],
])
.setTargeting("test", "infinitescroll")
.addService(googletag.pubads());
var div = document.createElement("div");
div.id = slot.getSlotElementId(); // auto-generated by GPT
document.body.appendChild(div);
// Call display() to register the slot as ready and fetch an ad.
googletag.display(slot);
});
}
</script>
<style>
body>div {
margin-bottom: 5em;
border: solid 1px black;
width: 728px;
}
body>button {
position: fixed;
bottom: 40%;
}
</style>
</head>
<body>
<h1>GPT Test Page - Infinite Content</h1>
<!-- First ad -->
<div id="div-gpt-ad-some-id">
<script>
// Call display() to register the slot as ready and fetch an ad.
googletag.cmd.push(function() {
googletag.display("div-gpt-ad-some-id");
});
</script>
</div>
<!-- Button to load more content dynamically. -->
<button onclick="moreContent()">More Content</button>
</body>
</html>
My Above code is correct. But to serve same tag multiple ads you need to have set up proportional number of creative in google ad manager. i.e. If you wish to use same tag 5 times, you need to have 5 creatives set up in google ad manager. In my case, provided gpt tag has only one creative setup on GAM. That is why only one tag was filled with ad.