我们的广告合作伙伴只有一个 gpt 广告代码。 在同一个页面上,我们希望使用同一个广告单元投放多个广告。 我们使用我们的广告标签来实现这个官方谷歌文档:https://developers.google.com/publisher-tag/samples/infinite-content。 不过,只有第一个广告得到投放。 随着我们生成更多广告,每个新标签上都会形成一个 google-query-id,但实际上并没有显示任何广告。 我们是否犯了任何错误,广告合作伙伴 Google Ad Manager 方面必须设置什么?
代码:
<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>
我上面的代码是正确的。但要投放相同标签的多个广告,您需要在谷歌广告管理器中设置比例数量的广告素材。即,如果您希望使用相同的代码 5 次,则需要在 Google 广告管理器中设置 5 个广告素材。就我而言,前提是 gpt 标签在 GAM 上只有一个创意设置。这就是为什么只有一个标签充满了广告。
你可以调用同一个adunit,你唯一要做的就是改变div id,添加某种变量,所以每个div都是独一无二的。希望你仍然觉得这有帮助,它对我们帮助很大。