Reusing Google Analytics Campaign Information with Google Tag Manager


GA Campaign UTMZ

There are many situations where it would be helpful to have the source, medium, and other campaign information for a user’s session. For example, we may want to capture the source / medium of a session when a user submits a Contact Us form to store inside of Salesforce.

This used to be very easy to do; in Classic Analytics, campaign information would be stored in the __utmz cookie, right on the user’s browser.

Universal Analytics moved campaign processing from the user’s browser to Google’s servers, eliminating the __utmz cookie (and easy access to that data). So how can we retrieve that information with Universal Analytics?

The proper way to do it is to store the users Client ID in a 3rd-party system and a Custom Dimension, then run a periodic script to retrieve the data via the Reporting API and sync it between systems. However, for many clients that kind of implementation is out of reach.

The next best solution is to re-create the __utmz cookie. One traditional solution has been to include Classic Analytics and send its hits to a dummy UA number. This does the job, but adds a lot of JavaScript that we don’t need.

A few years ago we wrote a UTMZ Cookie emulator recipe that we’re releasing to the public today. The script it contains will do its best to faithfully recreate the __utmz cookie of old, and will inherit values from any existing __utmz cookie and apply the same rules that ga.js would to values therein.

Import The Recipe

For instructions on how to import the recipe file, check out my colleague Jim Gianoglio’s evergreen post on using the Import feature of Google Tag Manager. Once you’ve got it imported, proceed.

Use the Variables

The recipe will import the following Variables into your container:

  • JS – GA Source
  • JS – GA Medium
  • JS – GA Campaign
  • JS – GA Content
  • JS – GA Keyword

These correspond to dimensions in Google Analytics. We can use these Variables to use for a condition in a Trigger or to pass values to a Tag.

In a Trigger

Let’s set up a Trigger that fires when a user visits from a search engine. We’ll create a Trigger that fires on Pageview when the value of the JS – GA Medium Variable is “organic”. Here’s how to set that up:

We can use this concept with any of our campaign variables, too; want to fire a modal for users visiting from a specific campaign? Use the JS – GA Campaign Variable.

In a Tag

We also might want to provide these values to Tags that fire in our container. If the Tag is a “pre-built” templated Tag, we typically just need to add the Variable to a field in the template. To pass along our data to a Custom HTML Tag, we need to review the vendor’s documentation and determine where the value belongs.


Hopefully you’re excited about some of the things you might try with this recipe, but before you get too jazzed, there are some caveats. Because the processing happens server-side, there are some situations our recipe can’t account for:

  • If you’re using cross-domain tracking, our recipe will probably say the session was a self-referral from that sister domain.
  • If you’re using the referral exclusion list extensively, our recipe will attribute sessions to domains that the exclusion list would have set to (direct) / (none) instead.
  • If you have any kind of filter black magic fiddling with the source / medium values, our script will miss those, too.
  • If you’re using Google AdWords or Google DoubleClick and autotagging is turned on, you will see the source/medium, but you won’t receive campaign information as that’s joined inside the interface.
  • If the user is coming directly and has an existing campaign from before the recipe was added, the recipe will show them as (direct) / (none) whereas the reports will show the previous campaign.

Questions? Issues? Let us know in the comments.

Dan Wilkerson is a former LunaMetrician and contributor to our blog.

  • Ivanna

    Hi! Great article.
    But I couldn´t find the link in “my colleague Jim Gianoglio’s evergreen post on using the Import feature of Google Tag Manager.” 🤔

    • Dan Wilkerson

      That’s because I’m a poor author and Jon is a terrible editor. Added and thank you for pointing that out!

  • Idan Daniels

    Is it ok to send the client id during the GDPR regulations?

  • Cristiano Pires combr Adwords


  • Jessica Chapin

    According to GTA recording and dataslayer, my site is getting this error, “This hit was preceded by an identical pageview hit. It’s likely that this hit is a duplicate. If you have consecutive duplicate pageview hits, your bounce rate and pageview numbers could be inaccurate.”

    When I check GTM in preview mode, the pageview tag only fires once. How can I fix this?

    • Dan Wilkerson

      Hi Jessica,

      It sounds like you’ve got a hard-coded page view in addition to GTM. Right-click, select ‘View source’ and look for the Google Analytics snippet. If you spot it and you’ve got page view tracking set up in GTM, you can most likely safely remove it, but double-check internally to make sure that you can. This blog might be useful:


      • Jessica Chapin

        The vendor for our site has it hardcoded on our site to send a pageview to their GA property, but we do not have anything in the source coded to send pageviews to our properly.

  • Benjamin Schwabe

    That’s great, it helps me in completing an A/B testing scenario where Optimize creates the variants and GTM reads both Optimize cookie and your traffic values to inject source-dependent scripts and changes. You made my day with this, thanks.

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187