当前位置


将“Google 广告管理系统代码”替换为“Google 发布商代码(异步)”

James Qi 在 2012年2月17日 - 13:41 提交

  我是很早前就开始使用Google广告管理系统的,这个系统对于中小发布商来说还有一些复杂,我开始也是摸索了一段时间、听了几次讲座才基本了解的。后来我们在各个网站上基本都采用了这套系统,普通的AdSense代码都很少用,而是通过DFP的补余来发布AdSense广告,代码也一直沿用以前的。

  去年收到过邮件,说了有了新的异步代码,但没有空试用,直到这次Drupal升级,也顺便把DFP的代码进行更换。

  目前有三种代码可用,DFP中设置的各种展示位置、广告位置等等在功效上这三种代码是一样的,下面是三种代码的简介:

  • Google 广告管理系统代码:使用 HTML 和 JavaScript 集成网页上的一个或多个广告单元。了解详情
  • Google 发布商代码(异步):通过抓取广告并以异步方式将广告呈现到 iframe 来提高网页加载速度。了解详情
  • Google 发布商代码(同步):如果使用异步代码不能正确呈现您的广告,则使用同步代码。了解详情

  以前的DFP代码:

文档标头
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Widgets Magazine</title>
<style type="text/css" media="screen">
</style>
<script type='text/javascript' src='http://partner.googleadservices.com/gampad/google_service.js'>
</script>
<script type='text/javascript'>
GS_googleAddAdSenseService("ca-pub-9094871827609791");
GS_googleEnableAllServices();
</script>
<script type='text/javascript'>
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiBottom728x15");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiBottom728x90");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiLeft160x600");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiLeft160x90");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiMiddle336x280");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiOther");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiRight160x600");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiRight160x90");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiSearch");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiSecond336x280");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiTop728x15");
GA_googleAddSlot("ca-pub-9094871827609791", "JamesqiTop728x90");
</script>
<script type='text/javascript'>
GA_googleFetchAds();
</script>
</head>
文档正文
广告单元 >
<!-- JamesqiBottom728x15 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiBottom728x15");
</script>

<!-- JamesqiBottom728x90 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiBottom728x90");
</script>

<!-- JamesqiLeft160x600 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiLeft160x600");
</script>

<!-- JamesqiLeft160x90 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiLeft160x90");
</script>

<!-- JamesqiMiddle336x280 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiMiddle336x280");
</script>

<!-- JamesqiOther -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiOther");
</script>

<!-- JamesqiRight160x600 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiRight160x600");
</script>

<!-- JamesqiRight160x90 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiRight160x90");
</script>

<!-- JamesqiSearch -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiSearch");
</script>

<!-- JamesqiSecond336x280 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiSecond336x280");
</script>

<!-- JamesqiTop728x15 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiTop728x15");
</script>

<!-- JamesqiTop728x90 -->
<script type='text/javascript'>
GA_googleFillSlot("JamesqiTop728x90");
</script>

  我在本站中采用了异步代码,如下:

文档标头 ?
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Widgets Magazine</title>
<style type="text/css" media="screen">
</style>
<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('/1027280/JamesqiBottom728x15', [728, 15], 'div-gpt-ad-1329457030007-0').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiBottom728x90', [728, 90], 'div-gpt-ad-1329457030007-1').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiLeft160x600', [160, 600], 'div-gpt-ad-1329457030007-2').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiLeft160x90', [160, 90], 'div-gpt-ad-1329457030007-3').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiMiddle336x280', [336, 280], 'div-gpt-ad-1329457030007-4').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiOther', [125, 125], 'div-gpt-ad-1329457030007-5').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiRight160x600', [160, 600], 'div-gpt-ad-1329457030007-6').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiRight160x90', [160, 90], 'div-gpt-ad-1329457030007-7').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiSearch', [728, 90], 'div-gpt-ad-1329457030007-8').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiSecond336x280', [336, 280], 'div-gpt-ad-1329457030007-9').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiTop728x15', [728, 15], 'div-gpt-ad-1329457030007-10').addService(googletag.pubads());
googletag.defineSlot('/1027280/JamesqiTop728x90', [728, 90], 'div-gpt-ad-1329457030007-11').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
文档正文
广告单元 >

<!-- JamesqiBottom728x15 -->
<div id='div-gpt-ad-1329457030007-0' style='width:728px; height:15px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-0'); });
</script>
</div>

 

<!-- JamesqiBottom728x90 -->
<div id='div-gpt-ad-1329457030007-1' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-1'); });
</script>
</div>

<!-- JamesqiLeft160x600 -->
<div id='div-gpt-ad-1329457030007-2' style='width:160px; height:600px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-2'); });
</script>
</div>

 

<!-- JamesqiLeft160x90 -->
<div id='div-gpt-ad-1329457030007-3' style='width:160px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-3'); });
</script>
</div>

<!-- JamesqiMiddle336x280 -->
<div id='div-gpt-ad-1329457030007-4' style='width:336px; height:280px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-4'); });
</script>
</div>

 

<!-- JamesqiOther -->
<div id='div-gpt-ad-1329457030007-5' style='width:125px; height:125px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-5'); });
</script>
</div>

<!-- JamesqiRight160x600 -->
<div id='div-gpt-ad-1329457030007-6' style='width:160px; height:600px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-6'); });
</script>
</div>

 

<!-- JamesqiRight160x90 -->
<div id='div-gpt-ad-1329457030007-7' style='width:160px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-7'); });
</script>
</div>

<!-- JamesqiSearch -->
<div id='div-gpt-ad-1329457030007-8' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-8'); });
</script>
</div>

 

<!-- JamesqiSecond336x280 -->
<div id='div-gpt-ad-1329457030007-9' style='width:336px; height:280px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-9'); });
</script>
</div>

<!-- JamesqiTop728x15 -->
<div id='div-gpt-ad-1329457030007-10' style='width:728px; height:15px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-10'); });
</script>
</div>

 

<!-- JamesqiTop728x90 -->
<div id='div-gpt-ad-1329457030007-11' style='width:728px; height:90px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1329457030007-11'); });
</script>
</div>

  可以看到,代码比以前稍微复杂一些,编号没有用以前的adsense ca-pub号,而是另外产生的,并且加入了一些序号、div代码、尺寸等信息。准备在以后的新增中采用,而老站也会逐步升级中改用新代码。

评论

添加新评论

Plain text

  • 不允许使用HTML标签。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
验证码
本问题用于测试您是否为人类访问者,避免自动垃圾发贴。
图形验证
键入显示在图片中的字符