As you know, Google Analytics is the most popular website analytics which let you see and analyze your website traffic include Visitors, Traffic Sources, PageViews, etc. In addition, it also allows you to set up Event Tracking. For example, you want to track how many time your download button/link is clicked or your play button is pressed or even track how many percent a particular video is played by with a call out function from your player script.
Before we continue, please make sure you placed Google Tracking Code on somewhere your website (before the </body> tag). To track a particular event, you can use either of following methods:
To make it simple, I will create a click with an event tracking when click on that link.
1. Event Tracking with _trackEvent
<a href="javascript:void(0);" onClick="_gaq.push(['_trackEvent', 'Downloads', 'Click', 'Test Download Tracking']);">Click here to raise a track</a> |
The html code will render something like this:
Assume that you’re browsing the page on Firefox with Firebug plugin installed. When click on the link above, the onClick event will call the _gaq.push function to track.
How the report looks like, let’s open the Google Analytics, from your Website Dashboard page, click on Content tab on the left then click on Event Tracking tab.
As you see on the image above, all event tracking is counted. That’s awesome.
Read more: go to Event Tracking Guide on Google
2. Page Tracking with _trackPageview
<a href="javascript:void(0);" onClick="_gaq.push(['_trackPageview', 'download_source_code']);">Click here to download the source code</a> |
The html code will render something like this:
Click here to download the source code
When click on the link above, it will track and count for download_source_code as a page content. Let’s check how Firebug displays:
To see how many time the download_source_code was “viewed”, open the Google Analytics then go to Content => Top Content => type the tracking named ‘download_source_code‘ on the Filter Page text box => Go
Feel free to let us know how you go with it.