Google Analytics for developers
blog.arkency.com
blog.arkency.com
<!-- Async Tracking Code - http://code.google.com/intl/en-US/apis/analytics/docs/tracking/asyncTracking.html -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR ANALYTICS ID GOES HERE']);
_gaq.push(['_trackPageview']);
//*******************
// Trick #1: Track page load time in Google Analytics
// (note: only works for HTML5 browsers)
//*******************
_gaq.push(['_trackPageLoadTime']);
(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);
})();
//*******************
// Trick #2: Add a Javascript error handler so that it creates an event in Google Analytics
// whenever there's a CLIENT-SIDE javascript error
//*******************
window.onerror = function(message, file, line) {
var sFormattedMessage = '[' + file + ' (' + line + ')] ' + message;
_gaq.push(['_trackEvent', 'Errors', 'Browser', sFormattedMessage, null, true]);
}
</script>
Update: Included complete GA code to address any confusion on order and values available in stack.Update: your 2nd trick is still relevant though
[0] https://developers.google.com/analytics/devguides/collection...
However, Google Analytics only automatically samples the page load time for 1% of visitors.
To change this call
_gaq.push([‘_setSiteSpeedSampleRate’, 100]);
before tracking the pageview. This will sample 100% of users for the site load time.
https://developers.google.com/analytics/devguides/collection...
- Google will take a lot longer to report your data if you do this. - Google also has data limits. If you're experiencing 10k+ pageviews a day, you will probably run into the limit and it will stop reporting stuff.
Place this stuff in the head tag rather than the bottom. It's async code and placing it closer to the top you can make sure you're setting up tracking the page as soon as possible.
After adding that, where does that appear in the Google Analytics dashboard? Can you explain further how that works? Thanks!
The GA code will track client side page load time (DOM fully loaded) across your site. You'll get site-wide averages and you'll also get to drill in on slow pages. This doesn't work for every single browser (last I checked it only worked for browsers that support HTML5), but it still provides a good sample size.
It's also important to do this as Google Webmaster tools dropped support of the Site Speed lab which shows you how fast Google thinks your site is ( <1.5 seconds user DOM load is considered faster, >= 1.5 seconds is "slow"). If you're trying to improve your Google ranking you need to be tracking how fast Google thinks your site is. (Also, fast websites are great for lots of reasons, not just Google ranking.)
See also: http://analytics.blogspot.com/2011/05/measure-page-load-time...
Googlebot seems to give up crawling your site after about 14 seconds :) You might see that reported in GWT.
I know you weren't actually asking, but I figured it's worth stating this for someone else who might experience the same thing. Load times do vary greatly. Digging down into the Analytics can show you where/why they vary. And as you said and as always with Analytics, look for trends more than exact figures.
Compress data with gzip is probably the big one for modem users, but also batching scripts and CSS together, reducing image sizes, re-arranging code to reduce blocking during rendering.
These are all things under your control, and with current mobile browsers, these are things you really must care about
You can do something to make like better for those on mobile and dialup with server settings, image compression, and the like. You can't change their connection speed, but you can focus on their experience.
[1] https://github.com/cardinalpath/gas
Best part is, with Google Analytics you can see what people did before and after they ran into trouble and correct for the user experience.
[1] https://www.google.com/search?q=site:https://developers.goog...
[2] http://stackoverflow.com/questions/6618719/how-does-google-a...
[3] http://stackoverflow.com/questions/4484748/what-happens-with...
[4] http://productforums.google.com/forum/#!msg/analytics/132Eet...
[1]https://developers.google.com/analytics/devguides/collection...
Do your mobile apps require an Internet connection? From what I'm seeing I imagine that's a prerequisite to use GA. It's a deal breaker for me though, I can't intentionally throw away a slice of offline usage data (iPods, iPads, etc).
That hits the nail on the head. Great article, although I wish you went into it a bit more in depth on how to do those actions, how to do other actions, and then maybe talk more about the benefits.
I love browsing Google Analytics but I will be the first to tell you that I don't really understand much from it, other than than the obvious things. I really wish I could figure out how to integrate it better with my web sites, like you quickly demoed. Again, I really suggest doing this same article with a bit more information. It would really help out those who are your target audience for this article. Thanks! :)
Here's what Google itself has to say on the matter: http://support.Google.com/analytics/bin/answer.py?hl=en&...
Here's how to correct one code example from the blog post:
//this function is OK, but probably an unnecessary abstraction of a one-liner
function trackEvent(category, action, label) {
window._gaq.push(['_trackEvent', category, action, label])
}
//this event handler will not track some non-negligible percentage of events
$("article a").click(function(e) {
var element = $(this)
var label = element.attr("href")
trackEvent("Outbound link", "Click", label)
});
//corrected outbound link event handler which gives GA 100 ms to register
//the event. higher than 100 risks UX degradation, lower increases the %
//of untracked events. 100 ms is happy medium
$("article a").click(function(e) {
e.preventDefault(); //stay on the page for now
var element = $(this)
var label = element.attr("href")
trackEvent("Outbound link", "Click", label)
//leave the page after a short delay
window.setTimeout("window.location.href='" + label + "'", 100);
});By looking at time to scroll, time to the end of the blog post, and comparing that to the number of unique page views per visit, you can tell if your content is engaging.
Tracking user actions can be very useful: I use it on movieterminals.com to see everything that gets typed into each console. The theory being that (one day?) I'll use that to enhance the scripts to work how people expect.
Tracking an event per page 404 or 500 can also be very helpful. If you aren't already using something more robust to track errors you could even setup alerts to watch for those events and contact you.
Goals are good, although funnels are even better.
Finally: if you can afford it I've found that Clicky offers many great advantages over google analytics. More helpful default reports, a better realtime view, etc.
There are two things here. Sampling rate for calculating page timing and using sampled data when generating reports. Confusingly, they are two different things with the same word "sample."
Sampling rate only affects calculating page timing because it's client side and slows down the client. (http://support.google.com/analytics/bin/answer.py?hl=en&...)
Google Analytics will collect all the unfiltered data for the web property. (http://support.google.com/analytics/bin/answer.py?hl=en&...)
However, to speed up ad-hoc querying, like when you create a custom report, it will limit the amount of data it will fetch to generate that report in order to make the user interface faster.
You can increase/decrease that using the slider. YOu will only see the slider after something like 250k unique pageviews.
Google Analytics Premium increases the number. If you really want to get a better sense of page timing, you should look both at the client side timing and the server side timing together. All you can really control is stuff going out. You can't help it if the user is running a netbook with 512 megs of RAM :)
https://github.com/CardinalPath/gas
It adds these events and even more to your site.
(I'm the main developer by the way.)
Landing pages: Go to Content > Site Content > Landing Pages
What you probably want is to create an advanced segment: Landing page = something. You can use regex or an exact match term.
Then go to audience > visitor flow, select the advanced segment you used and you can visually see how users navigated your site.
Remember: Keep in mind that a user can technically visit your site using browser tabs. That would give you a report where people went from page A to page B even if there isn't a link on page A going to page B.
Hence: Use GA to gain insight into trends.
Thanks
I have some of it tracked with internal code, but for a lot of things that don't need rigorous analysis/tracking, firing an outbound click event to GA is sufficient.