Configuring Analytics
Set up Google Analytics and Tag Manager to Measure Your Website's Performance
February 20, 2016
In order to judge a site, you need to measure it. For years I used Google Analytics (GA) to measure conversions and user behavior. A few months ago, I added Google Tag Manager (GTM) to the tracking system. GTM is a great tool for adjusting the out-of-the box tracking of GA. Here are some basic configurations that I have found helpful.
Set Up Instructions
Below are details on my basic set up. You will need to create accounts with both GA and GTM. After you create your accounts, GTM will provide a script to add to the website you want to track.
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-[ID####]"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-[ID####]');</script>
<!-- End Google Tag Manager -->
Once you add this script to all pages or templates, all updates that you publish within GTM will be live on your website. You can customize the GTM functions by creating a series of cascading operations using Tags, Triggers, and Variables.
Add GA to GTM
Use GTM to install GA.
Create a Variable in GTM
Variable Name: UA
Type: Constant
Value: ua-[Google Analytics Account Number]*
Create Tag in GTM
Tag Name: Google Analytics Tag
Product: Google Analytics
Tag Type: Universal Analytics
Tracking Id: {UA}
Fire On: All Pages
Track Not Found Errors
When users visit a url that is not defined on your site, they get a 404 error. Configure a GA report to track which URLs are triggering the error.
- Create a new report.
- Type: Explorer
- Metric Groups: Site Usage/Unique Page Views
- Dimension Drill Down: Page/Full Referrer
- Filters: Include Page Title = [Page Title of 404 page]
Regularly check in and set up a GA alert to get an email or notification whenever the number spikes. Then correct the errors by adding redirects.
Form Measurement
Track form conversions as an Event in GA.
Set the Variable in GTM
Variable Name: Event
Type: Custom Event
Set the Trigger in GTM
Trigger Name: Form Trigger
Event: Custom Event
Fire on: Event Name - Form Submit
Set the Tag in GTM
Tag Name: Form Trigger Submit
Product: Google Analytics
Tag Type: Universal Analytics
Configure Tag:
Track Type = Event,
(Set corresponding category & action)
label = {event}
Fire On: Form Trigger [or corresponding Trigger]
Set {event} with JavaScript on Form Submit
The {event} variable is defined in the JavaScript on form submit. And will appear as the event label in GA.
dataLayer.push({
'event': gtmLabel
});
Track Links
GA automatically tracks URLs. But what if you want to know which links people are using? Is it from the Primary Nav, Secondary Nav, or copy? Set up GTM to track individual links.
In GTM, set the Variables
Enable the built in variables:
- Click Text
- Click URL
- Click ID
- Click Element
- Click Target
Set the Variable in GTM
Variable Name: Element URL
Type: Auto-Event Variable
Variable Type: Element URL
Component Type: Full URL
Set the Trigger in GTM
Set a Trigger for when a user clicks a link.
Trigger Name: Clicks Anchor
Event: Click
Trigger: Targets All Elements
Fire on: Click URL matches RegEx: .+
Set the Tag in GTM
Set a Trigger for when a user clicks on a non link button.
Tag Name: Link Click
Product: GA
Tag Type: Universal Analytics
ID: {UA}
Track Type: Event
Category: Clicks
Action: {Click Text}
Label: {Click Element}
Custom Dimension 1: {Click ID}
Fire On: Clicks Anchor
In GA, Enable Custom Dimension
Google provides a custom dimension overview. Set the Custom Dimension to “Element ID.”
In the document HTML, add ID to non-link elements
On my portfolio, images Trigger the display of related content. And I’m tracking the clicks to see which images users are selecting.
<img src="/images/portfolio/200/giving.png" alt="Giving Website" id="Web_Gallery_Giving">
Use a consistent naming convention to keep track of the ids. View the stats by going to GA and then selecting Behavior/Events/Top Events and Select Custom Dimension as the Secondary Dimension. In the example above, each click on the image will register with a Custom Demension of “Web_Gallery_Giving.”
Track YouTube play
Analyze how users play and stop your YouTube video embeds with these Cardinal Path instructions.
Next Steps
The optimum set up largely depends on the site goals and strategy to attain those goals. The measurements listed above should help get a better picture of what is happening and what is working. Use that knowledge to inform your future iterations.
Learn more about using data to assess and inform tactics view my Analytics Remarks.