Google Analytics - 如何使用新的异步代码跟踪页面名称?
我正在使用 Google 提供的以下代码进行 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"));
ry {
var pageTracker = _gat._getTracker("UA-XXXXX-X");
pageTracker._trackPageview("PAGENAME");
} catch (err) { }
</script>
但 Google 已经发布了异步 Javascript 代码(如下)。
<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>
我的问题是:在旧代码中,我曾经使用 PAGENAME (pageTracker._trackPageview("PAGENAME");) 跟踪页面。如何使用新的异步代码来做到这一点?
I was using the below code provided by Google for 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"));
ry {
var pageTracker = _gat._getTracker("UA-XXXXX-X");
pageTracker._trackPageview("PAGENAME");
} catch (err) { }
</script>
But Google has released Asynchronous Javascript Code (below).
<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>
My QUESTION is: in the old code I used to track a page with PAGENAME (pageTracker._trackPageview("PAGENAME");). How can I do it using the new asynchronous code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重写异步跟踪代码中的第三行代码并将其更改为以下内容:
这已记录在案 此处
You can rewrite that third code line in the async tracking code and change it to the following:
This is documented here
RTFM:http://code.google.com /apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
您的示例如下所示:
这只是指定第二个参数的情况。
RTFM: http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
Your example would look like this:
It's merely a case of specifying a second parameter.