0
對於單頁的應用程序,我想知道是否有可能要求新的廣告,以取代現有的廣告在一個div容器GPT重新加載廣告
var slotName = '/blogs/peter/recentPosts' // this changes according to route
var adContainer = 'div-common-container' // this never changes
window.googletag.defineSlot(slotName), ['fluid'], adContainer).addService(this.googletag.pubads())
我發現的例子到目前爲止,確認這是可能刷新現有slots
,但我的使用情況是不同的(https://support.google.com/dfp_premium/answer/2694377?hl=en&ref_topic=4390040)
我的目標是有共同的模板頁面的常見的廣告容器元素,併爲每個pageTransition,其中分類爲不同 請求一個新的廣告。
我到目前爲止所做的當前測試,試着改變slotName然後調用refresh(),但它似乎不起作用!例如(比下面的例子更復雜,但只是爲了暴露點):
<!DOCTYPE html>
<html>
<head>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var myAddSlot
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
myAddSlot = googletag.defineSlot('/6355419/Travel/Europe/France/Paris', ['fluid'], 'div-common-ad-container')
.addService(googletag.pubads());
googletag.enableServices();
});
</script>
</head>
<body>
<div id='div-common-ad-container' />
<button id="refresh">refresh</button>
<script>
googletag.cmd.push(function() { googletag.display('div-common-ad-container'); });
document.querySelector('#refresh').addEventListener('click', function() {
googletag.destroySlots()
googletag.cmd.push(function() {
myAddSlot = googletag.defineSlot('/6355419/Travel', ['fluid'], 'div-common-ad-container')
.addService(googletag.pubads());
googletag.enableServices();
});
})
</script>
</body>
</html>
任何提示是讚賞!