The simple implementation for tracking visitor actions, or clicks, involves adding the
to an HTML tag. For example, to track a visitor click on an image, just add
_trackPageview() to the
onclick event of that element:
<img src="/image.jpg" onclick="_gaq.push(['_trackPageview', '/image.jpg']);" />
<a href="/schedule.pdf" onclick="_gaq.push(['_trackPageview', '/vpv/downloads/pdf/schedule.pdf']);" />PDF</a>
When creating pageviews for non-HTML files, try to use a consistent
naming convention. This will make it easier to identify them in the
reporting interface. For example, you may want to create a virtual directory
In the previous code example, I added
/vpv/downloads/pdf/ to the value passed to
_trackPageview() (vpv stands for “virtual
pageview”). This makes it easy to identify the non-HTML files in the
Outbound links are tracked in the same manner:
<a href="http://www.cutroni.com" onclick="_gaq.push(['_trackPageview', '/vpv/outbound/'+this.href]);" />www.cutroni.com</a>
This outbound link will appear as
/vpv/outbound/http://www.cutroni.com in the reports.
Again, be logical in your naming convention. By placing all outbound links
in the /vpv/outbound/ directory, you
can easily filter the data in the Top Content report or the Content
Clicks on outbound links are not “real” pageviews. If you need an accurate count of the number of pageviews your website generates, make sure you filter out any clicks on outbound links. An exclude filter, using the request URI and a filter pattern that matches your outbound link structure, will do the job.
An alternate method for tracking clicks is to use event tracking rather than virtual pageviews. See Chapter 9 for more information about event tracking.
The problem with DOM scripts is the browser compatibility. If a browser changes the way it interprets the DOM, the script can break. This actually happens more often than you might think. Another challenge with DOM scripts is keeping them up to date. At the time of this publication, there are no DOM scripts that support the new async version of the tracking code.
In October 2007, Google announced that automatic file download tracking and automatic outbound link tracking would be included in Google Analytics. It has been almost three years and this feature has still not appeared. Google assures us that it is coming, but we still have not seen it.
If you are tracking file downloads or outbound links, it is critical to your business that you do not wait for Google to launch this functionality.
One modification that I do recommend adding is a timer, especially when tracking outbound links or file downloads. In some instances, the browser can redirect the visitor to the file or requested website before the Google Analytics code can generate the virtual pageview or event. By adding a short timer, you can increase the chances that Google Analytics will record your data.
Adding a timer means you must create a small function that intercepts the visitor’s click, creates the pageview, and lets the browser execute the visitor’s actions. You modify an outbound link like this:
<a onclick='trackClick(this);return false;' href="http://www.redsox.com/" > Red Sox </a>
Google Analytics uses up to five first-party cookies to track and
store information about a visitor. These cookies, set by the
track attributes of the visitor, such as how many times she has been to
the site and where she came from. The cookies do not store any personally
identifiable information about the visitor. Here is a list of all the
tracking cookies, their format, and other information:
The __utma cookie is the visitor identifier. The
unique-idvalue is a number that identifies this specific visitor.
ltime(last time), and
stime(start time) are all used to compute visit length (along with the
__utmccookies). The final value in the cookie is the session or visit counter. It tracks how many times the visitor has visited the site and is incremented every time a new visit begins.
The __utmz cookie is the referrer-tracking cookie. It tracks all referrer information regardless of the referrer medium or source. This means all organic, cost-per-click (also known as CPC), campaign, or plain referral information is stored in the __utmz cookie. Data about the referrer is stored in a number of name-value pairs, one for each attribute of the referral:
Identifies a search engine, newsletter name, or other source specified in the
Expiration: 6 months
This is a custom variable cookie. This cookie is not present unless you have implemented a visitor-level custom variable. The cookie is created using the
_setCustomVar()method, which we will discuss in Chapter 10.
Google Analytics uses first-party cookies. A first-party cookie belongs to your website. Some web analytics tools use a third-party cookie. A third-party cookie is not owned by your website, but rather a different website. By default, many browsers block third-party cookies, which can cause issues for any tool that tracks visitors with a third-party cookie. It is always preferable to use an analytics tool that tracks visitors with first-party cookies.
There are numerous studies, white papers, and blog posts estimating the rate at which user cookies are blocked by browsers and deleted by users. Eric Petersen first wrote about the pitfalls of cookies in a 2005 study for Jupiter Research. The latest formal cookie study was done by comScore, an online measurement company: http://troni.me/ca7sDU.
In my opinion, the best course of action to mitigate cookie deletion and its effects on your data is to look for trends and patterns in your data and to avoid absolute numbers.