8

I have universal analytics installed on my website, and want to parse the __utmz cookie to get referral info. However, I never see this cookie set.

Has something changed? Any reason this isn't set?

I do see the _ga cookie when I browse my site, and I see the __utmz cookie in my browser cache if I go to other sites.

I checked out the docs, and don't see any reference to this changing recently, so a bit stumped.

steve cook
  • 3,116
  • 3
  • 30
  • 51

4 Answers4

11

Universal Analytics doesn't create any __utm* cookies.

However, you can use Universal Analytics code (analytics.js) AND the traditional code (ga.js) simultaneously on your site. This will allow you to populate your UA profile and scrape the values from __utmz.

Andrew C
  • 562
  • 3
  • 10
  • ah! sneaky.. yes that sounds like it could work. Not sure how long google are suppoering ga.js tho. – steve cook Sep 05 '13 at 01:50
  • If you're concerned about Google dropping ga.js, just make a copy of it and reference it locally. – Andrew C Feb 06 '19 at 17:50
  • updating your implementation would be a better idea. once google drops ga.js, you never know if ga.js will be referencing outdated api endpoints – johnmarinelli Mar 18 '19 at 12:06
4

It seems like with Universal Analytics, this cookie has disappeared, and you only get a single _ga cookie.

Source: https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage

Also mentioned here: How to get the referrer, paid/natural and keywords for the current visitor in PHP with new Google Analytics?

Also given that analytics is primarily a tool to collect aggregated information, I couldn't find (and I doubt) that there is any way to query GA to get this info back, given the _ga cookie.

Community
  • 1
  • 1
steve cook
  • 3,116
  • 3
  • 30
  • 51
3

You can create your own cookie and store the query string parameters that google analytics use (utm_campaign and etc). See this project as example: https://github.com/dm-guy/utm-alternative

dm-guy
  • 566
  • 3
  • 10
0

Use below code to get utmz cookie along with your universal analytics js code

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
Gsk
  • 2,929
  • 5
  • 22
  • 29
vkk
  • 1