Google Analytics ga.js Tracking Best Practices

Posted 2010-09-08 in JavaScript by Johann.

  1. _gat._anonymizeIp()
  2. Google Analytics Search Engine Extension.
  3. _trackPageview(location.pathname) if you don’t use query parameters. _trackPageview(location.pathname.replace(/;jsessionid=[^?]+/,'') if you use session IDs. Over time, a lot of junk ends up in the query string and that might skew content reports.
  4. Track positive and negative goals (anything that means the goal can’t be reached) in one goal set and track the positive goals one more time in another goal set. For media.io, a negative goal would be that the file couldn’t be converted.
  5. _setDetectFlash(false) because Flash is dead.
  6. Google’s async ga.js syntax is stupid (but inevitably so). Use the _gaq.push(function() { … }); syntax.
  7. Any interaction in a form should probably be tracked using virtual page views instead of event tracking.
  8. Always use _createTracker('UA-1234-12', 't') once in the page and _getTrackerByName('t') in event handlers. _createTracker should be used only once.
  9. Set up a second profile for each domain that filters only search traffic (or whatever traffic you prefer). You can’t use segments when comparing date ranges with a filter and that is a workaround.
  10. Create a “branded traffic” segment for search terms that contain your brand name. Keep in mind people are creative when typing names so you will need to dig into your keywords first. For media.io, the segment filters media\W*[1i]o.
  11. Create an “non-branded traffic” segment for search terms that don’t contain your brand name (see 10).
  12. _setAllowAnchor(true) so that you can link by using anchors instead of query strings. Can avoid duplicate content issues.
  13. _setVisitorCookieTimeout(5270400000). This sets the persistent GA cookie expiration to 61 days instead of the default two years. I’ve never seen any substantial activity past two months.

Subscribe

RSS 2.0, Atom or subscribe by Email.

Top Posts

  1. DynaCloud - a dynamic JavaScript tag/keyword cloud with jQuery
  2. 6 fast jQuery Tips: More basic Snippets
  3. xslt.js version 3.2 released
  4. xslt.js version 3.0 released XML XSLT now with jQuery plugin
  5. Forum Scanners - prevent forum abuse
  6. Automate JavaScript compression with YUI Compressor and /packer/

Navigation