Given:
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
I tried with opt_label but it seems like it's just a string and doesn't accept a hash of different parameters like Mixpanel do.
I suspect one of the the work around is using custom variables? But the docs seems confusing. Appreciate any advice.
While you can certainly make this work in Google Analytics, other analytics services like Mixpanel, KISSmetrics, Kontagent, etc specialize in event analysis and give you more flexibility. Having said that, you can hack the Google Analytics event model to get what you’re looking for.
If you want to track multiple parameters for each event in Google Analytics I’d suggest cramming the parameters you want to track into the event label. This is workable for two reasons: Event labels can be really long (ridiculously long, actually) and Google Analytics provides flexible filtering and segmentation options.
So, to extend an example discussed in an earlier answer, you could have an event for tracking video play details that looks like this:
All we've done is toss a few arbitrary parameters into the event label string in such a way that we can pull them out later. To analyze the results you could filter your event reports to show, say, the number of times the ‘MoreCatLolz’ video was shown with ads:
Alternately, using advanced segments and regex, you could count the number of visits in which users watched at least 90% of any video:
To track persistent user data, such as name, join date, level, purchase count, etc., I’d suggest using visitor-level custom variables which are automatically included with every tracking call (including events) and allow you to apply many of the same analysis techniques.
I'm not sure what mixpanel is, so I'm unaware of what you're trying to compare analytics to. If you provided a specific example of the data you're trying to collect, I could provide you with a better answer.
Lets say you have a video player and you want to track how long people watch the video and how many times people paused the video, you would do something like this;
Obviously this is generic, but as you can see in the
_gaq.push
arrays,Play
andPause
are the parameters andplayTime
andclickPause
are the variable values of the parameters.The label is optional, so I would expand it to something like:
Category = 'Games'
Event = 'Play'
Label = 'Tetris'
GA is not as good as Mixpanel for tracking event (or hit in general) properties, and maybe you should rethink what you want to/can do in GA. That said, there is a way to achieve what you need with custom dimensions and metrics. Here is some info on what they do, and here are instructions on how to set them up in the admin panel, and here you can find how to use them in your code. Some limitations:
First, you would need to add the custom dimensions/metrics through the admin panel in GA (Admin -> Properties column -> Custom Definitions -> Custom Dimensions/Metrics).
Using
analytics.js
, you can set the event properties using eitherset
before you trigger a hit, orsend
when you trigger a hit. Examples:In case you're not sure what's the difference between dimensions and metrics, check this out.
I hope this helps