我是很早前就開始使用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代碼、尺寸等信息。準備在以後的新增中采用,而老站也會逐步升級中改用新代碼。
评论2
速度會慢嗎?
速度會慢嗎?
現在Google廣告管理系統的速度還好
去年Google廣告管理系統的展示有些拖慢網頁速度,現在還好,不算慢,異步代碼應該更快,其設計目的就是不影響網頁的正常打開