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:
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:
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?