在舊版的設定方式中,Google 建議將追蹤程式碼放在位於網頁最尾端 <BODY></BODY> 標記區段內的底端 (詳情可參閱 Google Analytics 官網說明 http://www.google.com/support/analytics/bin/answer.py?hl=b5&answer=66983 ),而新版的追蹤程式碼 (非同步追蹤程式碼),Google 則建議放入位於網頁最頂端的 <HEAD></HEAD> 標記區段內的底端 (詳情可參閱 Google Analytics 官網說明 http://www.google.com/support/analytics/bin/answer.py?answer=174090 ) 。
舊版追蹤程式碼範例:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>
新版追蹤程式碼範例:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
沒有留言:
張貼留言