用Google Analytics跟踪用户行为来优化网站
Google Analytics(谷歌分析)为我们提供了强大的网站统计功能,其中Custom Reports(自定义报告)功能更是为我们扩展统计功能提供了方便。在这里我们探讨一下通过自定义报告功能跟踪用户行为的方法。
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-xxxxxx-x”); pageTracker._trackPageview(); } catch(err) {}</script> |
| var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']);(function() { var ga = document.createElement(’script’); ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; ga.setAttribute(‘async’, ‘true’); document.documentElement.firstChild.appendChild(ga); })(); |
