0
我想通過Google DFP廣告管理系統在通過ajax以無限滾動方式加載的每個頁面中展示廣告。每頁有四個不同的插槽。我遵循Google DFP的常規代碼,這是我的情況:Google DFP廣告管理系統標記在無限滾動頁面上
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/XXXXXXX/ROS_DHTML', [600, 600], 'div-gpt-ad-5').addService(googletag.pubads());
googletag.defineSlot('/XXXXXXX/ROS_Horizontal', [960, 250], 'div-gpt-ad-6').addService(googletag.pubads());
googletag.defineSlot('/XXXXXXX/ROS_Interstitial', [1920, 1080], 'div-gpt-ad-7').addService(googletag.pubads());
googletag.defineSlot('/XXXXXXX/ROS_Txt', [[300, 250], [300, 600]], 'div-gpt-ad-8').addService(googletag.pubads());
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
然後我再次定期致電廣告。
<div id='div-gpt-ad-8'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-8'); });
</script>
</div>
我的無限滾動腳本(Ajax Load More WordPress插件)我提供的是每一個成功的查詢之後調度回調函數。例如,我使用AddThis,Facebook和Twitter按鈕代碼。
$(function() {
$.fn.almComplete = function(alm){
console.log("Ajax Load More Complete!");
};
})(jQuery);
如何讓DFP和此回調函數一起工作?我知道Advanced Google Publisher Tag,但我不是世界上最懂代碼的人,而且我無法適應我的需求(特別是因爲我使用了很多插槽)。所以,我認爲這將是更簡單的方法...
我只是沒有得到第二部分。你能搗鼓嗎? :) – borbs
下面是一個例子的小提琴:[FiddleJS(https://jsfiddle.net/oscardom/cog46j82/4/) 這是一個簡單的例子,當你每點擊它一次按鈕加載一個新的旗幟。讓我知道你是否需要關於代碼的任何解釋。 P.S .:對不起,小提琴上的內聯JS。我試圖把所有的東西放在JS部分,但它沒有工作。希望它對你仍然有用。 – OscarDOM