An event is the measurement of a specific interaction of a user on a website or in an application. For example, a candidate moves the mouse over the "Careers" category or clicks on a job ad. Google Analytics records these interactions and shows you a corresponding evaluation in the event report. Read this article to learn how to create events in Google Analytics.
1. Structure of Google Analytics events
A Google Analytics event is structured using category, actions and labels. While you have to use most of these elements, the values are freely selectable. There are no fixed rules, but generally they are used as described below:
Event category
The top category you want to assign to a single category or a group of similar categories. For example:
- Videos
- Outgoing links
- On-Page-Buttons
- PDFs
Event action
The type of interaction you follow. For example:
- Download
- Play video
- Name of the button clicked
Event label
Further information on the event. For example:
- Name of the downloaded data
- Name of the video
Event value (optional)
The value you assign to an event. This can be anything from monetary value to weight or time.
2. Setting up Google Analytics events on your site
There are two main ways to set up events in Google Analytics:
- Adding the Google Analytics event code to the website
- Setting up Google Analytics events in the Google Tag Manager
How to set up Google Analytics events manually
Manually setting up Google Analytics events is the original method, which is by far the most difficult. It involves adding a code to the website every time you want to create an event. This is probably one of the reasons why it used to be a rarely used method of tracking in Google Analytics. This changed with Google Tag Manager, which is the easiest way to set up events. However, if it is not possible to add Google Tag Manager or another tag manager solution to your website, this is the way you need to set up events.
The code added to the website is an additional Google Analytics code and must be placed wherever you want to track activity on the page, for example on the button you want to track. The event code is always placed in the following order:
- Category
- Action
- Description (optional)
- Value (optional)
- Field objects (non-interaction, etc. > optional)
The syntax for a Google Analytics event is as follows, and must be added to what you want to track.
<em>ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);</em>
The event code must be followed in this order: category, action, label, value, field object. So the tracing could look like this:
<em>ga('send','event','On Page Navigation','Buttons','GTM Training',0,{'nonInteration':false});</em>
Since the field name has not been specified, Google Analytics assumes that it is the order given above, which is fine if you include everything. However, if you do not, you must leave a blank field. For example, if the event above does not include a label, it would be written as follows:
<em>ga('send','event','On Page Navigation','Buttons','', 150, {'nonInteration':false});</em>
If you don't, Google Analytics assumes the event value is the event label and pushes it further.
Note: In the example we have used "ga" as the Analytics code, but if you are using the gtag snippet, replace this with "gtag" and remove "send". You can find more instructions for gtag on the Google Analytics page.
Doing this on every page is a lot of work and you can see why it is so rarely used. In the next section, we describe how you can do this easily using Google Tag Manager.
How to set up Google Analytics events in the Google Tag Manager
Before creating an event in the Google Tag Manager, make sure you have set up a Google Page View tag. Your tasks:
- Click on "New" in the tag screen.
- Select a Google Analytics tag and choose "Event" from the "Track Type" drop-down list.
- Select your category, action, label or value.
- Indicate whether the non-interaction is false or true.
- Select your Google Analytics settings variable or enter your Google Analytics UA number.
- Add your trigger.
- Name your tag.
- Preview and test.
- Publish your tag.
Let's now create a Google Analytics event for a button.
- Click on "New" in the tag screen.
- Select a Google Analytics tag and in the drop-down list "Track type" select the option "Event".
- Select your category, action, label or value.
- Indicate whether the non-interaction is false or true.
- Select your Google Analytics settings variable or enter your Google Analytics UA number..
- Add your trigger.
- Name your tag.
- Preview and test.
- Publish your tag.
Once you have published and visitors start interacting with the event you set up, you will see them in Google Analytics: in the real-time event report and the normal event report. If you are using a browser plugin, such as Tag Assistant or Dataslayer, you should be able to see the live event on the button above.
3. Hints and tips
- Try to keep the number of event tags to a minimum by grouping them and using your click text/class/ID variables.
- Name your events so that anyone looking at your Google Analytics account can understand them.
- Always test your tag before publishing.
- The social tag in Google Tag Manager, which sends information to the social report in Google Analytics, is very similar in style and use to the event tag. Once you have mastered this tag, you should be able to set up your report for social plugins.