Track user through Google Universal Analytics

Posted by raygo on Pro Webmasters See other posts from Pro Webmasters or by raygo
Published on 2014-06-10T20:58:49Z Indexed on 2014/06/12 21:40 UTC
Read the original article Hit count: 287

I want to track a user from my site, give an id to Google Analytics and later be able to see which pages that id visited and for how long did that id view the pages.

I've tried custom variables with the classic analytics.

I tried enabling the User-ID feature in the Universal Analytics.

Neither of these have given me what I want yet. Is there any way to accomplish this with Universal Analytics?

UPDATE

This is a sample code with a user whose id is 2. I try to set the userid in different ways to see if at least in one way it shows.

    <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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXX-1', 'domain.com', { 'userId': '2' });

  ga('set', '&uid', '2'); // Set the user ID using signed-in user_id.

  var dimensionValue = '2';
  ga('set', 'dimension1', dimensionValue);

  ga('send', 'pageview');

</script>

© Pro Webmasters or respective owner

Related posts about google

Related posts about google-analytics