Google Analytics Event Tracking Ebook 2
Google Analytics Event Tracking Ebook 2
No part of this publication can be reproduced or transmitted in any form or by any means, mechanical or
electronic including photocopying and recording or by any information storage and retrieval system, without
permission in writing from the author (except by a reviewer, who may quote brief passages and/or show brief
video clips in a review).
Disclaimer: Great efforts have been made to ensure the accuracy, timeliness and completeness of the contents
(written text, graphics) provided in this book. However neither the author nor Optimize Smart make any
guarantee /warranty of accuracy, timeliness and completeness of the information provided in this book or any
website this book links out to. No warranty/guarantee may be created or extended by a sales representative or
written sales materials. Similarly neither the author nor Optimize Smart make any guarantee/warranty that the
websites linked to this book are free from viruses, adware or other malicious programs. Websites listed in this
book may have changed or disappeared between when this book was written and when it is read. Neither the
author nor Optimize Smart will be liable for any losses or damages (including but not limited to: commercial,
special, incidental, consequential damages) arising from the use of the contents in this book. This book is for
information purposes only. The advice and strategies contained herein may not be suitable for every situation.
If professional assistance is required, the services of a competent consultant/agency should be sought. The fact
that an organization or website is referred to in this book, as a citation and/or potential source of further
information does not mean that the author or Optimize Smart endorses the information the organization or
website may provide and/or recommendations it may make.
● Runs one of the most popular blogs in the world on digital analytics
Website: www.optimizesmart.com
Linkedin: https://www.linkedin.com/in/analyticsnerd
Facebook: https://www.facebook.com/optimizesmart
WHAT'S INSIDE: Learn to set up your Google Analytics account correctly and
fast using this 62 point checklist. This is no ordinary checklist - it is a result of
more than a decade of experience in the analytics industry.
WHAT'S INSIDE: My Step-by-step blueprint for getting started with data layers.
Get the only ebook on GTM data layers ever published. Learn the JavaScript
behind it.
The user’s interaction/activity with a web page element that you track
in Google Analytics is called an 'event'.
Following are the examples of events that can be tracked in Google Analytics:
1. Downloading a file
2. Loading of Ajax, JavaScript or Flash content
3. Loading of a dynamically generated webpage
4. Loading of pop-ups, lightboxes
5. Loading of a video on a webpage
6. Scrolling down the page
7. Viewing of a video
8. Viewing video footage of certain length
9. Clicking on a video’s play/pause/stop button
10.Interaction with a gadget
11.Clicking on an image or an external link
12.Abandonment of a form field
13.Log-ins
14.Sharing/printing a blog post, article, video or image
15.Clicking on a button
16.Movement of mouse
● video
● gadget
● podcast
● image
● button
● form
● scroll bar
● external link
● lightbox
● Ajax content etc.
#1 Events that generate pageviews when they occur. For example, clicking on
an internal link on a webpage generates a pageview.
#2 Events that do not generate pageviews when they occur. For example,
following users' interactions do not generate a pageview when they occur:
By default Google Analytics (GA) can not track any event that does not
generate pageview when it occurs.
You can track such events only through event tracking or virtual pageviews.
The rule of thumb is, track those types of users' interactions, using
‘event tracking’ which either do not generate a pageview when they
occur or which are not equivalent to a page being viewed.
1. Event Category
2. Event Action
3. Event Label
4. Event Value
#1 Event Category
The 'event category' is the name assigned to the group of similar events you
want to track. You can use any value of type 'text' as an event category.
If you have already set up event tracking then you can see the values of the
'event category' in Google Analytics by navigating to Behavior > Events > Top
Events:
#2 Event Action
If you have already set up event tracking then you can see the values of the
'event action' in Google Analytics by navigating to Behavior > Events > Top
Events and then click on the 'Event Action' primary dimension:
#3 Event Label
The 'event label' is the name assigned to the web page element, whose users'
interaction you want to track. You can use any value of type 'text' as an event
label.
If you have already set up event tracking then you can see the values of the
'event label' in Google Analytics by navigating to Behavior > Events > Top
Events and then click on the 'Event Label' primary dimension:
#4 Event Value
The 'event value' is the numerical value assigned to the event you want to
track. You can use any value of type 'number' as an event value. However, you
can not use any value of type 'text' as an event value.
For example, an event value can be any number that represents a download
time, length of the video footage played, or some monetary value.
Note(1): If you want to assign a monetary value to a tracked event then use the
'event value'.
If you are using analytics.js library to set up event tracking then specifying
‘event category’ and ‘event action’ is mandatory. Whereas, specifying
‘event label’ and ‘event value’ is optional.
Example:
ga('send','event','videos','Play','chappy',100); // correct
Note: If you are using the analytics.js library then default values of
eventCategory, eventAction, eventLabel and eventValue fields is '(not set)'.
If you are using the global site tag (gtag.js) then specifying the 'event
category', 'event label', and 'event value' is optional. However,
specifying 'event action' is mandatory.
Example:
gtag('event','' , {
'event_category' : 'videos',
gtag('event', 'Play', {
'event_category' : 'videos',
'event_label' : 'Chappy'
}); //correct
Note: If you are using the gtag.js library then the default value of the 'event
category' is 'engagement' and the default value of the 'event label' is (not set).
ga('send', {
'hitType': 'event',
'eventCategory': 'videos',
'eventAction': 'Play',
'eventLabel': 'chappy',
'eventValue': 100
You can also write this line of code without using any field names:
ga('send','event','videos','Play','chappy',100);
When you do not specify field names, you then need to supply field values in
the following order:
Event Category > Event Action > Event Label > Event Value
Since field values are executed in the order in which they are supplied, if I
changed the order, my event tracking will work differently or worse won’t work
at all.
For example:
ga('send','event','Play','videos','chappy',100);
Here ‘Play’ will be treated as an event category and ‘videos’ will be treated as
an event action.
Another example:
ga('send','event','Play','videos',100);
To avoid this issue, you can leave the ‘event label’ field empty:
ga('send','event','Play','videos','',100);
#4 Use the correct data type for your field values while
setting up event tracking
Note: There is no hard and fast rule regarding what data you put into 'event
category', 'event action', 'event label' and 'event value' as long as you are
assigning values of type text to 'event category', 'event action' and 'event label'
and values of type integer to 'event value'.
Likewise, use consistent names for event categories, event actions, and event
labels.
So if you are using 'videos' as an event category, then do not use 'video',
'Videos', 'VIDEOS' as an event category. Otherwise, you will end up creating
several different event categories in Google Analytics that all hold the same
type of event data.
One of the best ways to use consistent names is by using only lowercase letters
for event categories, event actions, and event labels.
#1 Hard code the Google Analytics event tracking code on your website that
tracks a specific user’s interaction (aka event) with a web page element.
#2 Use Google Tag Manager to track users' interaction with the web page
elements.
The advantage of using GTM to track events is that it is easier to use and is
scalable.
Example
gtag('event', 'Play', {
'event_category': 'videos',
'value': 100,
'non_interaction': 1
});
gtag('event', 'Play', {
'event_label': 'chappy',
'event_category': 'videos',
'value': 100,
'non_interaction': true
});
If you are using the gtag.js libabry then the above code can be written as:
gtag('event', 'play-spiderman', {
'event_category' : 'videos',
'event_label' : 'Spiderman-2'
});
gtag('event', 'play-dog-out', {
'event_category' : 'videos',
});
'event_category' : 'videos',
});
#1 Determine in advance, all of the web page elements (like videos, gadgets,
image, external link, etc) you want to track and the type of users' interactions
(aka events) you want to track for each web page of your website.
#2 Create a hierarchy of event categories, event actions, and event labels that
is scalable. So that you don't need to frequently change the names of event
categories, event actions, and event labels to hold different types of event
data.
#3 Use an Excel Spreadsheet to decide the names of all your event categories,
event actions, and event labels in advance. Then work with your report users,
to make sure that your hierarchy is understandable:
Step-1: Determine in advance, all of the web page elements (like videos,
gadgets, image, external link, etc) and the type of users' interactions you want
to track for each web page of your website.
Step-2: Create a hierarchy of event categories, event actions, and event labels
that is scalable. So that you don't need to frequently change the names of
event categories, event actions, and event labels to hold different types of
event data.
Step-3: Use an Excel Spreadsheet to decide the names of all your event
categories, event actions, and event labels in advance. Then work with your
report users, to make sure that your hierarchy is understandable:
#1 Hard code the Google Analytics event tracking code on your website
that tracks a specific user’s interaction with a web page element.
#2 Use Google Tag Manager to track users' interaction with the web page
elements.
Step-1: Navigate to the web page (via Google Chrome web browser) which
contains the button you want to track via event tracking.
Step-2: Right-click on the button and then click on 'Inspect' from the
drop-down menu:
Step-5: Create your Google Analytics Tracking Code using the following syntax:
For example,
event value is 10
Step-6: Add your Google Analytics Event tracking code to your button code:
Note: You can also use the event tracking code builder tool to generate event
tracking code.
Step-7: Open your FTP tool and then navigate to the web page/file which
contains the button you want to track via event tracking.
Step-8: Download the file, open it, and then replace the button code with your
new button code (the button code with event tracking code).
Step-9: Upload the file to your web server. This will replace the old file with the
new version.
Step-10: Navigate to the web page (via Google Chrome web browser) which
contains the button you want to track.
Step-12: Navigate to your Google Analytics view and then click on 'Events'
under 'Realtime':
If you don't see your event category and/or event action then it means your
event tracking is not set up correctly.
This is the recommended method to track users' interactions with web page
elements as it is easier to use and is scalable.
So if you want to track clicks on the buttons across your website in one go
without manually adding the event tracking code to each and every button,
you can easily do that via Google Tag Manager.
Step-1: Navigate to the web page (via Google Chrome web browser) which
contains the button you want to track via event tracking.
Step-2: Right-click on the button and then click on 'Inspect' from the
drop-down menu:
Step-3: Find your button code. It is going to look something like the one below:
Step-4: Note down the 'id' attribute of the button. In our case, it is 'checklist3'.
Note: The 'id' value that you use should be unique. If the ‘id’ attribute is
missing, then ask your developer to add it.
Step-7: Click on the 'Triggers' link and then click on the 'New' button to create a
new trigger:
Step-8: Name the new trigger 'Check for clicks on the download button'
Step-16: Name your new tag 'Send click on the button download to GA as
event':
Step-23: Find and click on the trigger 'Check for clicks on the download button':
Step-27: Click on the button. Now if you see your tag listed under the 'Tag
Fired' section then it means you tag is firing:
Step-28: If the tag is firing then click on the 'Leave Preview Mode' link in your
GTM account and then click on the 'ok' button:
Trigger the event you are tracking (via GA event tracking code) and then look at
the real-time events report to check whether the event data (category, action,
label) is being passed to Google Analytics.
The second way to see the real-time firing of events is through ‘Google
developer console’.
Trigger the event you are tracking (via GA event tracking code) and then look at
the Google developer console to check whether the event data (category,
action, label, value) is being passed to Google Analytics:
The real-time events report in GA does not provide any such information. So if
your event is not firing and you just rely on real-time events report, then you
will have a hard time diagnosing event tracking issues.
If you do not supply event category value while setting up event tracking (in
case of analytics.js), then the tracked event will not be counted in the 'Total
events' metric and will not be reported in GA event reports.
The Google developer console will also show you the error message "Missing
required field 'eventCategory' for hit of type 'event':
But unlike event category, if you do not supply the even action value while
setting up event tracking (in case of analytics.js), then the tracked event
(without event action) will still be counted in the 'Total events' metric.
Google developer console will show you the error message "Missing required
field 'eventAction' for hit of type 'event':
1. Overview report
2. Top Events report
3. Pages report
4. Events Flow report
Sessions with an event - These are those Google Analytics sessions in which at
least one tracked event occurred.
Through this report, you can determine the pages of your website on which the
maximum number of events were recorded by GA:
Through this report, you can visualize the order in which visitors triggered
events on your website.
#4 Selecting dimensions
To understand the difference between dimensions and metrics, read the article:
Complete Guide to Dimensions and Metrics in Google Analytics
Step-1: Login to your Google Analytics account and then navigate to the main
reporting view.
Step-4: Scroll down and then select the 'custom' option (under 'Goal Setup):
Step-7: Enter the values for 'event category', 'event action', 'event label'
(optional) and 'event value' (optional):
All of these events can or can not generate pageviews when they occur.
ga('send', {
'hitType': 'event',
'eventCategory': [category],
'eventAction': [Action],
'eventLabel': [Label],
'eventValue': [Value],
'nonInteraction': true
});
ga('send', {
'hitType': 'event',
'eventCategory': 'videos',
'eventAction': 'Play',
'eventLabel': 'chappy',
'eventValue': 100,
'nonInteraction': true
});
You can also write this line of code without using any field names.
For example:
ga('send','event','videos','Play','chappy',100,{'nonInteraction': true});
When you do not specify field names, you then need to supply field values in a
particular order.
In case of event tracking, you need to specify field values in the following
order:
Event Category > Event Action > Event Label > Event Value
Since field values are executed in the order in which they are supplied, if I
changed the order, my event tracking will work differently or worse won’t work
at all.
For example:
ga('send','event','Play','videos','chappy',100);
Here ‘Play’ will be treated as an event category and ‘videos’ will be treated as
an event action.
Another example:
ga('send','event','Play','videos',100);
here 100 will be treated as event label instead of event value. To avoid this
issue, you can leave the ‘event label’ field empty:
ga('send','event','Play','videos','',100);
ga('send','event','Play','videos','',100ex);
here event value is of type text. Since event value accepts a value of type
integer, the code above will create tracking issues.
You can bypass all of these order rules by using field names:
ga('send', {
'hitType': 'event',
'eventCategory': 'videos',
'eventAction': 'Play',
'eventValue': 100
});
I prefer using field names because it makes the code easy to understand.
Remember:
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
Note: If you are using the global site tag (gtag.js) then specifying the 'event
category', 'event label' and 'event value' is optional. However, specifying 'event
action' is mandatory. The default value of the 'event category' is 'engagement'
and the default value of the 'event label' is (not set).
The following example code fires a Google Analytics Event with an action of
'Play", a category of 'videos', and a label of 'Chappy':
gtag('event', 'Play', {
'event_category' : 'videos',
'event_label' : 'Chappy'
});
The following table lists the default Google Analytics Events, their default
categories, and default label types (if available):
For example, the following code fires a Google Analytics Event with an action of
'Play', a default category of 'engagement, and a default label of '(not set)':
gtag('event', 'Play');
For example:
Another example,
<a href="https://www.abc.com/gu/dw/social-media-guide.pdf"
onClick="ga('send', 'event', 'guides', 'download-social',
'social-media-guide.pdf', 10);">Download Social Media Guide</a>
Another example,
Here, we are tracking the number of people who sent emails by tracking clicks
on emails.
The other but less popular mouse event handlers are ondblclick,onmouseover
and onmouseout. All of these mouse event handlers can be used to execute
the event tracking code.
Note: You should avoid tracking highly repetitive events like mouse movements
because Google Analytics can't track more than 500 events per session.
If you want to track clicks on external links, clicks on file downloads and other
buttons in Google Tag Manager, then read the following articles:
I have not found any good use of keyboards event handlers in event tracking.
It executes a method after a page, frame or image has completely loaded. For
example:
The most common form event handler is onSubmit. This event handler
executes a method/function when a form is submitted and is often used to tie
event tracking code to a form embedded on a web page.
For example:
Other commonly used form event handlers are onBlur, onChange, onReset,
and onSelect. All of these event handlers are frequently used for advanced
form tracking.
If you want to track forms via Google Tag Manager then read the following
articles:
I certainly don't want you, to manually add event tracking code on each and
every web page element, throughout your website. That would be insane, esp.
when now you have got the mighty Google Tag Manager at your disposal.
To learn more about event tracking in Google Tag Manager, read the following
article: Event Tracking in Google Tag Manager – Complete Guide
Here is an article which can help you do that: Video Tracking in Google Tag
Manager
Through scroll tracking, you can get an insight into, how people are consuming
your website contents. Again, GTM is the best tool to scale and automate scroll
tracking on a website.
To learn more about implementing scroll tracking via GTM, read the following
article: Scroll tracking in Google Tag Manager
Cross-device tracking
Cross-device tracking is the most advanced application of event tracking, where
you send event hits from devices other than laptops, mobiles, desktops, and
tablets via measurement protocol.
So if you want to send event data from your cash register or washing machine
to the Google Analytics server, you can do that by writing a script that sends
the payload data to the GA server.
I have seen many issues, from incorrect tracking code, selecting the wrong KPIs,
to analyzing data without using custom reports or advanced segments.
And they seem to be making this mistake over and over again.
They give the credit for conversions to the last touchpoint (campaign, ad,
search term...).
They can’t help themselves because they believe that the Google Analytics
reports are ‘what you see is what you get’.
This has resulted in marketers making wrong business decisions and losing
money.
All the data you see in Google Analytics reports today lies to you unless you
know exactly how to interpret it correctly.
During an HTTP to HTTPS redirect (or vice versa), the referrer is not passed
because of security reasons.
So on the surface, it may look like most people are visiting your website
directly, but this is not usually the case.
But this analysis does not end here because you are still not looking at the
complete picture.
People do not always access your website directly and then make a purchase
straight away.
They are generally exposed to multiple marketing channels (display ads, social
media, paid search, organic search, referral websites, email, etc.) before they
access your website directly.
So if you are unaware of the role played by prior marketing channels, you will
credit conversions to the wrong marketing channels.
To get this type of understanding, you need to understand and implement web
analytics.
The direction in which your analysis will move will determine the direction in
which your marketing campaigns will move.
You get that direction from ‘web analytics’ and not from ‘Google Analytics’.
So what I have done is, I have put together a completely free training for you.
This training will teach you what digital analytics really is and how I have been
able to leverage it to generate floods of news sales and customers. And how
you can copy what I have done to get similar results.