1

I'm trying to set up User-ID tracking so that my User Explorer can show user ids instead of anonymous ids. I followed the instructions here:

https://support.google.com/analytics/answer/3123666?hl=en

When I go to my User ID View, the real time reports always shows zero, and my Behaviour>User Explorer always says there's no data. Does anyone know what I did wrong?

Here's a simple web page I made on https://startmission.com/test.html

<!DOCTYPE html>
<html dir="ltr">
<head>

  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-5315469-12"></script>
  <script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-5315469-12');
  gtag('set', {'user_id': 'sessuid-2'});
/*
  setTimeout(function(){
  gtag('set', {'user_id': 'sessuid-2'});
  gtag('set', {'userId': 'sessuid-2'});
  ga('set', 'user_id', 'sessuid-2');
  ga('set', 'userId', 'sessuid-2');
  },1000);
*/
  </script>
  <meta charset="utf-8"/>
  <title>Test Page</title>
</head>
<body>
</body>
</html>

In Google Analytics, these are my settings: enter image description here enter image description here enter image description here

Even when I try to uncomment the setTimeout in my code, my User ID View still doesn't report any results. It's been almost 24 hours, and still no results.


Other Notes If I go back to the "default" view, then I will get results: enter image description here


Update

I got things working on another website, but I used this GA code:

<!-- BEGIN ExactMetrics v5.3.5 Universal Analytics - https://exactmetrics.com/ -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-102411872-1', 'auto');
  ga('set', 'userId', 'sessu-2');
  ga('send', 'pageview');
</script>

Why does it work with the old GA code and not the new style gtag.js GA code?

3

Seems like at the moment you are hardcoding just one user ('sessuid-2'). To see data in the reports of a user id only view, I'd recommend trying to dynamically set the user ids and ask other people to visit the page. At the moment one user may not be enough for data to show up, theres also data processing delays so the report will not populate automatically.

In terms fo dynamically generating the user ids, this is usually set up for gated content where a user needs to log into his/her account. When a user logs in, you can grab the id that is set in the site or from your CRM tool, etc, and either save it in a cookie to later be read with Google Tag Manager, or you can also push an event to the layer that you can also later use GTM to grab the value and sent it to Google Analytics.

Hope this helps

  • Thanks is the data processing delay greater than 48 hours? The user id is dynamically set for the pages that require you to login. I still funny see any results in the User ID View – John Apr 27 '20 at 10:29
  • 1
    Hi John, sorry for the delay. Up to 24hr, no more than that. – Rafael Lopez May 7 '20 at 2:15
  • Thanks Rafael, I just updated teh question showing that I got things working using the old style ga code. So the question is why doesn't it work for the new style gtag.js code? – John May 7 '20 at 14:25
1

The following code worked:

<!DOCTYPE html>
<html dir="ltr">
<head>

  <!-- Global site tag (gtag.js) - Google Analytics -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-5315469-12"></script>
  <script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('set', {'user_id': 'sessuid-2'});
  gtag('config', 'UA-5315469-12');

  </script>
  <meta charset="utf-8"/>
  <title>Test Page</title>
</head>
<body>
</body>
</html>

The solution was to fire the gtag('set',{'user_id':'sessuid-2'}); before the gtag('config', 'UA-5315469-12');. The gtag('config',...) does the actual HTTP request to google servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.