One of the useful features of Google Analytics is the ability to track specific events. It gives you insight into how users filled your forms or on which buttons they clicked inside the video player. You are getting into the world of measuring actions inside your pages and not just between them. In the demo below we will see how to track a ‘download’ button click event and how to track the form filling. It’s super useful when you wish to learn if users use the Autofill feature with your forms.
It’s an easy API that you should leverage, so let’s jump into it.
What?
Events (in our world of Google analytics) are user interactions with content that can be tracked independently from a web page or a screen load. Downloads, mobile ad clicks, gadgets, forms, embedded elements and video plays are all examples of actions you might want to track as Events.
Implementation
Event hits can be sent using the send
command and specifying a hitType of an event
.
The send
command has the following signature for the event
hit type:
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
You need to make sure to add the GA script tag to your page.
Something similar to:
< script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XX-1', 'auto'); ga('send', 'pageview'); < /script>
Please make sure to change the line with UA-XX-1 to your Google analytics id.
Event fields
The following table summarizes the event fields:
Field Name | Value Type | Required | Description |
---|---|---|---|
eventCategory |
text | yes | Typically the object that was interacted with. For example:'registertion form' |
eventAction |
text | yes | The type of interaction (e.g. 'contact details' ) |
eventLabel |
text | no | Useful for categorizing events (e.g. 'first name' ) |
eventValue |
integer | no | A numeric value associated with the event (e.g. 2) |
The last two parameters are optional and if you are using the eventValue – make sure to use an integer.
Live Demo
Misc
- How to use Autofill.
- The official docs for event tracking in Google analytics.
- Building High Conversion Web Forms” course on Udacity.