2015-06-19 160 views
1

我正在使用異步GPT來投放我的展開式廣告,但廣告素材正在被切斷,因爲看起來異步代碼不是友好的iframe。DFP廣告管理系統(DFP):使用異步GPT投放展開式廣告

我使用DOM函數來轉義iframe父級,但我認爲我不能,因爲該廣告素材在呈現頁面之前呈現。

這是我的標籤樣本

<script type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js'> 
    googletag.pubads().definePassback('6917646/H24info/H24INFO_ATF_HOME_728x90', [[728,90]]).setClickUrl('[INSERT_CLICK_COUNTER_HERE]').display(); 

    googletag.pubads().enableSingleRequest(); 
    googletag.pubads().addEventListener('slotRenderEnded', function(event) { 

     var sas = document.getElementById("sas_format_33008"); 

     var gpt = document.getElementById("gpt_unit_6917646/H24info/H24INFO_ATF_HOME_728x90_1_ad_container"); 

     gpt.style.position = "absolute"; 
     gpt.style.zIndex = "100"; 

     sas.style.height = "90px"; 
    }); 
    googletag.enableServices(); 
</script> 

有沒有人誰可以幫我嗎?

回答

1

另一個選擇是使用發佈消息。但是你需要在你的主站點中放置一個事件監聽器。 事情是這樣的:

<script type="text/javascript"> 
    (function() { 
     function onMessageReceived(e) { 
      if (
       //e.origin !== 'http://tpc.googlesyndication.com' || 
       typeof e.data !== 'object' || 
       typeof e.data.id !== 'string' || 
       e.data.cmd !== 'setStyle' || 
       typeof e.data.params !== 'object' 
      ) { 
       return; 
      } 

      var frame = document.getElementById(e.data.id); 

      if (frame === null) { 
       return; 
      } 

      Object.keys(e.data.params).forEach(function(param) { 
       frame.style[param] = e.data.params[param]; 
      }); 
     } 

     if (window.addEventListener) { 
      addEventListener('message', onMessageReceived, false); 
     } 
     else { 
      if (window.attachEvent) { 
       attachEvent('onmessage', onMessageReceived); 
      } 
      else { 
       window.onmessage = onMessageReceived; 
      } 
     } 
    })(); 
</script> 

然後在廣告素材代碼,你將不得不調用事件偵聽器來調整,你需要擴展的元素。例如:

<script> 
(function(){ 
    if (window.top.postMessage) { 
     window.top.postMessage({ 
      cmd: 'setStyle', 
      id: 'div-of-the-banner', 
      params: { 
       display: 'block', 
       height: '600px', 
       width: '300px' 
      } 
     }, '*'); 
    } 
})(); 
</script> 

您可能需要調用這個調整大小腳本幾次,如果超過一個元素實際上是修理你的廣告的尺寸。

1

您將需要使用iframe解碼器

您可以嘗試下面的代碼。請記住,您需要在廣告素材設置中取消選中「投放到SafeFrame」配置。廣告素材的類型必須是自定義,第三方或模板)

if (top === self) { 
     // 
} else { 
    var parentIframes = top.document.querySelectorAll('iframe'); 
    for (var i=0; i < parentIframes.length; i++) { 
     var el = parentIframes[i]; 
     if (el.contentWindow === self) { 
      // here you can create an expandable ad 
      var expandableAd; 

      var googleDiv = el.parentNode; 

      googleDiv.insertBefore(expandableAd, el); 

     } 
    } 
} 

的更多信息:

更多的幫助:

+0

不幸的是,GPT標籤沒有iFrame Buster(僅適用於DART標籤)。 –

相關問題