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:

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:

So, what if we didn't have access to Site1's HTML code but wanted to add UTM values 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 []

GTM REferrer Variable.JPG

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. 

GA pageview variable UTM value.JPG

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

utm values.JPG


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.

GA pageview variable UTM value Location Method.JPG

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

GA pageview variable UTM value Location Method.JPG

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:!msg/tag-manager/v7U7L0MEqQ0/JcG6YEO9AAAJ

Happy tagging!