Skip to content

Instantly share code, notes, and snippets.

@jeremyworboys
Created October 31, 2012 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyworboys/3984789 to your computer and use it in GitHub Desktop.
Save jeremyworboys/3984789 to your computer and use it in GitHub Desktop.
GA Event Tracking
<div>
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx" onClick="_gaq.push(['_trackEvent', 'Driving School Services', 'Book Now']);" title="Book driving lessons online" target="_blank">
<img style="width: 162px; height: 65px;" alt="Book driving lessons online now" src="/portals/17/Book%20now%20blue.png">
</a>
&nbsp;
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx?su=1" onClick="_gaq.push(['_trackEvent', 'Driving School Services', 'Sign Up Now']);" title="Become a customer and book online" target="_blank">
<img style="width: 160px; height: 65px;" alt="Sign up to use our booking system" src="/portals/17/sign%20up%20180%20x%2065.png" longdesc="Sign up to use our booking system">
</a>
</div>
<div>
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx" title="Book driving lessons online" target="_blank">
<img style="width: 162px; height: 65px;" alt="Book driving lessons online now" src="/portals/17/Book%20now%20blue.png">
</a>
&nbsp;
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx?su=1" title="Become a customer and book online" target="_blank">
<img style="width: 160px; height: 65px;" alt="Sign up to use our booking system" src="/portals/17/sign%20up%20180%20x%2065.png" longdesc="Sign up to use our booking system">
</a>
</div>

Following Google's Event Tracking spec the onClick attribute is added to the anchor tags.

This runs the _gaq.push method when the button is clicked.

_trackEvent is the internal method to run,
Driving School Services is the category (The name you supply for the group of objects you want to track)
Book Now/Sign Up Now is the action (A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment