Sometimes a conversion tag only needs to be fired if a visitor was referred by a certain affiliate website or other source. For example: we run an affiliate program at Tradedoubler and we need to be sure that only the conversions made by visitors referred by Tradedoubler are attributed as a conversion in Google AdWords.
This data used to be available in Google Analytics’ UTMZ cookie. Since Google Universal Analytics was introduced, the UTMZ cookie is no longer available. We can solve this by creating a custom tag that saves the utm source in the browser’s local storage and a custom variable that makes the saved utm source accessible in our triggers.
- In Google Tag Manager, go to Tags and click New
- Choose the Custom HTML Tag type
- Give the tag a name like UTM Source Helper
- In the Configure Tag field, paste the following script
/// get the url and the key to find
var url = window.location.href;
var keyToFind = 'utm_source';
/// is there a utm source ?
if(url.indexOf(keyToFind + '=') > -1)
var valueFound = url.substr(url.indexOf(keyToFind + '=') + keyToFind.length + 1).split('&');
- Click Continue
- Choose All Pages as trigger
- Click Create Tag
Next we need to create the variable that will contain the value of UTM Source
- Go to Variables and click New
- Name the variable UTM Source
- Paste the following script
- Click Create Variable
The variable UTM Source is now available and will contain the last UTM Source value. Now we will be able to create a conversion tag that only fires on the thank you page and only when the visitor came through Tradedoubler.
- Go to Tags and click New
- Click Google AdWords
- Choose AdWords Conversion Tracking
- Set up the conversion tag as you normally would
- In Fire On, choose More
- Click New to create a new trigger
- For Event choose Page View
- Choose Page View as a trigger type and click Continue
- Select Some Page Views
- Select the rules that define your thank you page
- Add a rule for the UTM Source variable to equal tradedoubler
- Click Create Trigger
- Click Create Tag
The conversion tag is created
You’re all done. Don’t forget to publish the changes. The conversion tag should only fire when the last UTM Source was Tradedoubler.
Author: David Peeters