问题描述
Google分析现在有两种选择:经典和具有更多功能的全新通用。 (实际上,'通用'分析已经可以为客户付费一段时间,但现在它可以免费使用!)使用经典分析,看起来像这:
< script type =text / javascript>
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-XXXXX-Y']);
_gaq.push(['_ trackPageview']);
(function(){更多代码
})();
< / script>
我从很多谷歌搜索中发现,跟踪基于Ajax的网站(例如,通过AJAX加载页面的位置但导航菜单保持静态并且不会刷新),您可以将上面的代码添加到包含导航菜单的主index.html中,然后将javascript事件添加到菜单中的页面链接,以便...
< ul>
< li>< a href =contact.html>联络人< / a>< / li>
变为
< UL>
< li>< a onclick =_ gaq.push(['_ trackPageview','/ contactpage']); HREF = contact.html >联系与LT; / A>< /锂>
(其中'/ contactpage'是Google Analytics中要调用的页面 - 我们可以选择任何标题)。
现在分析也会开始跟踪这些页面。
但是我找不到一个明确的指南来说明如何为'通用分析,如下所示:
< script>
(函数(i,s,o,g,r,a,m){i ['GoogleAnalyt ...更多代码...
'//www.google-analytics.com/的analytics.js', 'GA');
ga('create','UA-XXXXX-Y','mydomain.com');
ga('send','pageview');
< / script>
我是否让我的链接看起来像这样?:
< ul>
< li>< a onclick =ga('send','pageview','/ contact'); HREF = contact.html >联系与LT; / A>< /锂>
或者这会更好吗?
< UL>
< li>< a onclick =ga('send','pageview',{'page':'/ contact','title':'/ contactpage'}); HREF = # >家庭和LT; / A>< /锂>
有人可以提醒一下吗?我是新来的谷歌分析,因此仍然在学习绳索!
非常感谢您提前。
您的最后一个代码块看起来很好,除了标题更适合页面友好标签。在这种情况下,我建议像
ga('send','pageview',{'page':'/联系','标题':'联系页'});
或者如果您想要区分联系人页面点击次数与简单的旧标准页面加载次数$ b'b
ga('send','pageview',{'page':'/ contact','title':'联系页面 - Ajax Load });
Google analytics now comes in two options: 'Classic' and the new 'Universal' which has more features. (Actually the 'Universal' analytics has been available to paying customers for a while, but now its available for free!)
With the 'Classic' analytics, which looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_gaq.push(['_trackPageview']);
(function() { SOME MORE CODE
})();
</script>
I have found from much googling that to track Ajax based websites (i.e. where the pages are loaded by AJAX but the navigation menu remains static and never refreshes), you can add the above code to the main index.html which contains the navigation menu and then add javascript events to the page links in the menu, so that...
<ul>
<li><a href="contact.html">Contact</a></li>
becomes
<ul>
<li><a onclick="_gaq.push(['_trackPageview', '/contactpage']);" href="contact.html">Contact</a></li>
(where '/contactpage' is what the page will be called in Analytics - we can choose any title).Now the analytics will start tracking these pages too.
But I can't find a clear guide on how to do the same kind of thing for the 'Universal' analytics which looks like this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyt...SOME MORE CODE...
'//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'mydomain.com');
ga('send', 'pageview');
</script>
Do I make my links look something like this?:
<ul>
<li><a onclick="ga('send', 'pageview', '/contact');" href="contact.html">Contact</a></li>
Or would this be better?
<ul>
<li><a onclick="ga('send', 'pageview', {'page': '/contact','title': '/contactpage'});" href="#">Home</a></li>
Can someone please advise? I'm new to Google analytics and therefore still learning the ropes!
Many thanks in advance.
Your last code block looks fine, except the "title" is more for the page friendly tag. In which case I'd advise something like
ga('send', 'pageview', {'page': '/contact','title': 'Contact Page'});
or if you wanted to differentiate contact page clicks from just plain old standard page loads
ga('send', 'pageview', {'page': '/contact','title': 'Contact Page -- Ajax Load'});
这篇关于基于AJAX的网站上的全新'Universal'Google分析脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!