Analytics Log - Adil Khan

View Original

How to add UTM parameters via Google Tag Manager

This post is based on a recent "situation" I had where the utm values we attached to a referrer link were not getting passed when the site loaded.

Background: Site 1 has a referrer link to Site 2. The link to site 2 is an anchor tagged link [that should automatically scroll/anchor down to the section that we want to link to].

The original UTM tagged link was: www.site2.com/folder1/page1#anchortag?utm_source=site-1&utm_medium=referrer&utm_campaign=campaign-name

The UTM values from this link were not showing up in Google Analytics Real-Time. My first reaction was to remove the UTM and work with this limitation [at least while a solution is figured out]. Headed down to GTM forum, posted about it and sure enough, Simo Ahava helped [again] here. The correct syntax for the UTM should have the anchor tag after the UTMs. So: www.siteB.com/folder1/page1?utm_source=site-1&utm_medium=referrer&utm_campaign=campaign-name#anchortag

So, what if we didn't have access to Site1's HTML code but wanted to add UTM values via Google Tag Manager. 

How to add UTM parameters via Google Tag Manager

Trigger: First, we need a trigger that listens for a referrer where it contains the link from Site 1. The Referrer variable does exactly that and here, we can have a referrer equals, a regex or one of the one ones. In this example [from my own blog], have used the referrer trigger where the referrer link was [http://analyticslog.com/blog/should-you-promote-a-facebook-video-post-for-views-or-engagement-cpv-vs-cpe-bidding]

Tag: We have two options here as we can use the campaign fields OR use the location field.

Method#1 / Campaign field: In this method, we can create a GA settings variable with the fields, campaignName / campaignSource / campaignMedium fields being hard coded values for this example. 

Once the tag is created, it just needs to be associated with the trigger. Here's the traffic in GA Real-Time.

 

Method#2: Location field.

I had to ask Simo for more details on this one. The location field is the Page URL, we only add the UTM values to the Page URL value. This is how the GA variable looks. Location field is the UTM tagged link.

and here's the traffic in GA Real-Time with source 'test-location-field'

Both methods do the exact same task but method #1 [campaign fields] is easier to spot when going through Google Analytics variables in GTM.

 

Here's a link to the Google Tag Manager product forum thread for the same topic: https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tag-manager/v7U7L0MEqQ0/JcG6YEO9AAAJ

Happy tagging!