Today's entry starts a series of Google Anlytics (GA) posts on features I use which extends its functionality. My first topic is virtual pageviews. When you install GA on your web site, you are given javascript which is hosted on every "html" page. However non html pages will not be tracked (like pdf's or MS Office files).
Perhaps you've created a manual (pdf) and you would like to know how many people have downloaded the file. As Adobe pdf's do not have a html header to host the Google Analytics javascript, it would seem impossible to track stats. Enter virtual pageviews which can track either files or links to other web sites. One must code each link you wish to track with individual snippets of code which tells Google what action to perform. For example, I track how many people click upon my LinkedIn profile link given towards the upper right of this web page. I also track virtual pageviews of an iPad for Business Manual I created.
Let's review the process for actually tracking virtual pageviews. My examples assume you are using the GA asynchronous code.
- This Example utilizes the standard Google Analytics asynchronous tracking method / script. If you are using the traditional method, I suggest upgrading. The code I give below will NOT work.
- Asynchronous Code Identification: Take a look at your Google Analytics code.
- Look for the following piece of code in your <head> section:
- var _gaq = _gaq || [];
- If you see that piece of code, or any reference to ‘_gaq‘, then you’re using the newer asynchronous code.
- Look for the following piece of code in your <head> section:
- Here is the example GA code. You need to replace the code for any given link with this script.
- <a onclick="javascript: _gaq.push(['_trackPageview', 'GA Virtual Location']);" href="file web address">file public web label</a>
You will need to replace everything in bolded red with your information
- GA Virtual Location: This drives how you find analytics in your Google reports. I personally like to save all virtual pageviews in a "virtual directory". Thus, my own links start /GA-Virtual/ followed by the file name. Thus when I drill down my Content in GA all my virtual pageviews are grouped together. You can provide whatever name you desire. Avoid GA reserved characters.
- File Web Address: This should be obvious. This is the address of your content or link. Thus, for my own site I might have an address http://www.northstarnerd.org/example.pdf
- File Public Web Label: This is the label for your link which the vistor sees while viewing your web page. It can be anything.
Finally, here is a working example of tracking a web link that leads off my web site.
Here is the code: (follows process outlined above)
- <a onclick="javascript: _gaq.push(['_trackPageview', '/GA-Virtual/LinkedIn-Profile']);" href="http://www.linkedin.com/in/richhoeg">LinkedIn Profile: Rich Hoeg</a>
Here is the link:
I've included two images below to help you get the idea (click to maximize).
No offense, but if there's a facebook like button, it'll be much easier for me to share.
Comment from Rich: I've added a "Share" service to my posts!
Posted by: elliptical reviews | November 29, 2011 at 04:00 AM