DFP ヘルプ フォーラムに投稿したとおり: https://productforums.google.com/forum/#!topic/dfp/9BsgVtKTU9A
jQueryを使用する実用的なソリューションがあります。
if(typeof googletag !== 'undefined' && typeof googletag.pubads !== 'undefined') {
if(adsCloned === false) {
var $dfpIframe = $('#div-gpt-ad-1477269112222-0').find('iframe'); // this is ad id that you use in googletag.defineSlot()
$dfpIframe.each(function (i, v) {
var $clone = $(v).clone();
$(v).replaceWith($clone);
});
adsCloned = true;
}
googletag.pubads().refresh();
}
それがvar adsCloned = false;
機能する理由は、ページの読み込み後に挿入された iframe (この場合は複製された iframe) を更新すると、履歴エントリが IE に追加されないためです。
編集: うまくいかない場合は、if statememt: を削除してみてください:
if(typeof googletag !== 'undefined' && typeof googletag.pubads !== 'undefined') {
var $dfpIframe = $('#div-gpt-ad-1477269112222-0').find('iframe'); // this is ad id that you use in googletag.defineSlot()
$dfpIframe.each(function (i, v) {
var $clone = $(v).clone();
$(v).replaceWith($clone);
});
googletag.pubads().refresh();
}
上記のコードは機能しません - 私の間違いです。しかし、私にとって有効な解決策は、googletag 変数全体を破棄し、コード全体を再度呼び出すことです。
dfp スクリプトの最初の呼び出しは次のようになります (googletag.pubads().disableInitialLoad(); と gads.id = 'dfpHeadScript'; に注意してください):
// Doubleclick
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.id = 'dfpHeadScript';
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);
})();
googletag.cmd.push(function() {
enovatis.dfpSlots.push( googletag.defineSlot('...', [240, 400], 'div-gpt-ad-1').addService(googletag.pubads()) );
enovatis.dfpSlots.push( googletag.defineSlot('...', [[960, 100], [750, 100]], 'div-gpt-ad-2').addService(googletag.pubads()) );
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
});
googletag.cmd.push(function(){
googletag.pubads().refresh();
});
広告を更新する方法は次のとおりです。
var dfpInterval = null;
var $dfpTop = $('#div-gpt-ad-1');
var $dfpLeft = $('#div-gpt-ad-2');
function refreshDfp() {
$dfpTop.empty();
$dfpLeft.empty();
googletag = {};
googletag.cmd = [];
$('#dfpHeadScript').remove();
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.id = 'dfpHeadScript';
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);
})();
googletag.cmd.push(function() {
enovatis.dfpSlots.push( googletag.defineSlot('...', [240, 400], 'div-gpt-ad-1').addService(googletag.pubads()) );
enovatis.dfpSlots.push( googletag.defineSlot('...', [[960, 100], [750, 100]], 'div-gpt-ad-2').addService(googletag.pubads()) );
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
window.clearInterval(dfpInterval);
dfpInterval = window.setInterval(function(){
if(typeof googletag.pubads !== 'undefined'){
window.setTimeout(function(){
googletag.pubads().refresh();
}, 75);
window.clearInterval(dfpInterval);
}
}, 75);
});
}
私はそれを次のように呼び出します:refreshDfp.apply(window);
そしてすべてがうまくいきます。このアプローチの唯一の欠点は、毎回より多くのリクエストを Google に送信することです。