简体   繁体   English

Google DFP广告管理系统响应不起作用

[英]Google DFP Responsive Not Working

Would anyone mind looking over my code I have, trying to make my DFP ads responsive as my websites are all responsive? 有人会介意查看我的代码,以使我的网站都具有响应性,使DFP广告管理系统具有响应性吗? I follow the example on Google DFP, and the ad doesn't seem to shrink when I tried mobile screen (and not showing up on real mobile screen at all) the code below is in my Header file. 我按照Google DFP广告管理系统上的示例进行操作,并且当我尝试使用移动屏幕(并且根本不显示在实际的移动屏幕上)时,以下代码在我的Header文件中似乎没有收缩。

I'm pretty sure I mapped thing correctly. 我敢肯定我正确地映射了东西。 I wonder if I have to make any changes to my body code also, or if I have to upload new creatives which has the adjusted size to fit mobile screen? 我想知道是否也必须对我的身体代码进行任何更改,或者是否必须上传尺寸经过调整以适合手机屏幕的新广告?

<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>

<script>
  googletag.cmd.push(function() {

    var mapping = googletag.sizeMapping().
    addSize([992, 0], [[970, 90], [728, 90], [300, 250], [1, 1]]). //desktop
    addSize([768, 0], [[300, 250], [728, 90], [1, 1]]). //tablet
    addSize([320, 0], [[320, 50], [320, 100], [300, 250], [1, 1]]). //mobile
    addSize([0, 0], [[320, 50], [1, 1]]). //other
    build();

   slot1 = googletag.defineSlot('/316721235/DL-TestAds', [728, 90], 'div-gpt-ad-1496860907063-0').defineSizeMapping(mapping).addService(googletag.pubads());
    googletag.pubads().enableAsyncRendering();
    googletag.enableServices();
  });
</script>

You must detect when the browser window size changes yourself, then trigger the ads to be redisplayed by calling refresh. 您必须检测浏览器窗口大小自己何时更改,然后通过调用refresh触发广告重新显示。

Listen to the resize event to detect when the browser window changes size. 侦听resize事件,以检测浏览器窗口何时更改大小。

window.addEventListener('resize', function (event) { // Check window.documentElement.clientWidth window.addEventListener('resize',function(event){//检查window.documentElement.clientWidth

} }

+1 to BeWarned for his answer : the responsive mapping is set at the page load. +1为警告:要响应的映射是在页面加载时设置的。 If the size of the window is amended, then you should relaunch the ad slots calls so DFP will be able to call the correct ad size. 如果修改了窗口的大小,则应重新启动广告位调用,以便DFP广告管理系统能够调用正确的广告尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM