有誰知道Google Analytics需要兩個單獨的腳本標記的原因嗎?Google Analytics的兩個單獨的腳本標記?
具體來說,他們的說明書告知用戶嵌入下面的代碼片段到網頁進行跟蹤:
<!-- Google Analytics -->
<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-8720817-1");
pageTracker._trackPageview();
} catch(err) {}</script>
爲什麼不能用戶只使用一個腳本塊這樣的:
<!-- Google Analytics -->
<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"));
try {
var pageTracker = _gat._getTracker("UA-8720817-1");
pageTracker._trackPageview();
} catch(err) {}</script>
我懷疑這是晦澀難懂的;我相信當前腳本塊完成後,瀏覽器將只解析腳本標記...可預測的單線程JavaScript執行... – Stobor 2009-07-31 00:11:03
@Stobor:你應該把它寫成答案。我會爲此投票。 :) – chaos 2009-07-31 00:15:11