Tracking Custom Events
Right so I’ve been doing tons of work with Google Analytics lately, implementing custom event trackers to get the most out of user behaviour tracking.
I couldn’t find an easy guide to start implementing the custom trackers anywhere so I thought I’d write a few snippets here to get you going.
I’ll to assume at this point that you’ve installed and have been using the Google Analytics tracking code in your site. If not, go and do it right now! Here’s how.
The gist of it
To implement the custom trackers I wrapped
ga( ) in another method with a quick check to ensure the Google Analytics code has been initialised, and only return if it has. This is so that on the local and demo environments it doesn’t throw an error and prevent execution of what else you actually want the event listener to do.
So now all you need to do is call
analytics_custom_event_tracker( ) passing in the name to track, the event (click, change etc) and a label - you’ll see where that comes in shortly.
To see how these events are doing head to Google Analytics and go to Behaviour - Events - Overview.
Head to the overview and you’re all set up to track in depth custom events, using the name and label you set earlier on.