This Google Tag Manager Recipe was originally posted by the team of Lunametrics.
This recipe will automatically attempt to determine a visitor’s referring traffic information, creating information about their source, medium, campaign, content, and term + store this information in the cookie.
Use cases: this information can be used with other Tags and Triggers – passed to hidden form fields, used to fire specific tags, say, just for the organic traffic, shared with other tools, etc.
What is UTMZ cookie, you ask? It’s a legacy solution previously used by Google Analytics. Once a visitor landed on a page, GA set the __utmz cookie with a source, medium, and other traffic-origin-related information and webmasters were able to use it for additional targeting solutions (like show a popup for social traffic, etc.). Now, Google Analytics is handling this information on their servers, therefore __utmz was deprecated.
With this GTM recipe, you’ll be able to imitate the __utmz cookie and upgrade your triggers, prefill forms, etc.
- Download Container File
Download the container JSON file (right-click on the link and click “Save Link As” or “Save Target As” to save the JSON file to your computer).
- Import JSON File into GTM
Log into your own Google Tag Manager container and head to the Admin section of the site. Under Container options, select Import Container. Read this blog post by Lunametrics for more details about importing a container file.
- Preview & Publish
Use the Preview options to test this container on your own site. An idea for a test case: Enable GTM Preview mode, land on your website from various sources (Google, some referring site, etc.) and see what data is stored in the cookie variables (if you’re new to working with cookies in GTM, here’s a handy guide).
- Optional: By itself, this recipe does not make any visible changes. The recipe works to make a visitor’s traffic information available for you to use in GTM. So what? You can use this information in a trigger and fire an X tag only to those who have landed from search engines, or prefill a form field, etc. The sky’s the limit here!