≡ Menu

Help! I just enabled the User ID feature through Google Tag Manager and my pageviews dropped?

Update 6/9/2014: Jump to the end of this post for a solution that obviates the need for two tags.

A week ago, I migrated a site to use Universal Analytics (UA) from classic GA.  As part of the migration, I wanted to enable the new User ID functionality which lets you pass a User ID for authenticated (signed in) with each GA hit.  This gives Google Analytics a common identifier to the ‘connect the dots’ across visits where cookies aren’t shared.  That way when a user visits from multiple machines and mobile devices, you have visibility into their behavior through the new Cross Device Measurement reports in Google Analytics.

The site being upgraded to UA was using Google Tag Manager which makes migrations of this nature a breeze.  I disabled the classic Google Analytics tag and added the new Universal Analtyics tag.  To enable the User ID feature, you need to add a row in the ‘Fields to Set’ section.

Screen Shot 2014-06-08 at 4.26.16 PM


The value field is populated with my {{uid}} macro which is the customer identifier that is passed to the data layer when a user is authenticated.  What I didn’t realize is that when the user isn’t signed in, the {{uid}} is empty, but the &uid field is still passed to the Google Analytics hit.   This caused a significant drop in pageviews, because for some reason when the UID field is empty, Google Analytics isn’t tracking them.

The workaround is to create two versions of your Universal Analytics tag to handle authenticated and non-authenticated scenarios.  For the authenticated users, you want a firing rule similar to this:

Screen Shot 2014-06-08 at 4.37.07 PM


This rule uses RegEx to test that the {{uid}} is a valid GUID (the customer identifier on this particular site) and fires on all pages.

For the non-authenticated (no User ID to populate), modify your Universal Analytics tag so the ‘Fields to Set’ is not being populated with the ‘&uid’ field.  The firing rule for this tag will simply be the ‘All Pages’ rule.  Now add a blocking rule using the rule created above (All Authenticated Pageviews) that only fires when the {{uid}} macro is a valid GUID.

Now  you have two versions of your Universal Analytics tag.  One will fire when users are authenticated and pass the User ID.  The other tag will fire for anonymous users and not populate the User ID field.  This will resolve the issue of pageviews not being properly recorded due to the empty User ID field.

Don’t forget to do this same workaround for any event or ecommerce tags you have implemented in Google Tag Manager.

As a final note, I have reached out to the Google Analytics team asking if this is the intended behavior as I suspect others will encounter this same issue.  I will update this post based on their response.

Update 6/9/2014: Thanks to Simo Ahava, there is a solution that eliminates the need for two using two tags.  For this version, you’ll only need one Universal GA tag, one rule  (All Pages) and two macros ({{uid}} and {{Get User ID}}.  In the Universal GA Tag fields to set, you’ll use a JavaScript macro {{Get User ID}} that will do a check to see if the User ID value is empty or not.  If it is, it simply returns which sets the {{Get User ID}} macro to undefined.  Google Analytics does not pass undefined values as part of the hit, so you avoid the problem I encountered previously.  Here’s what the JavaScript macro looks like:

Screen Shot 2014-06-09 at 7.40.59 PM

Happy Measuring!

Questions or comments?  Get in touch with me on Google+ or leave a comment below.



Comments on this entry are closed.

  • Eric


    Very helpful, have been curious on a better way to pull User ID’s. Was wondering what the Field Name needs to be for the Get User ID macro. The link to Simo’s blog does not link to any specific post.

  • Paul

    Surely that Javascript macro should not reference the {{uid}} macro and not itself??

    • Paul

      Oops ignore me, I’m suffering from code-blindness!

  • Tom Capper

    Hi Paul,

    I recently set up User ID using GTM, pulling the UID from a cookie that is only created when a user logged in. I’m having no issues tracking pageviews of people who don’t have a cookie. Do you know if Google have updated and fixed this issue, or is it a quirk of using a cookie macro rather than a datalayer macro?


    • Dan

      It appears that Google has since addressed this issue. I ran a quick and test and verified I could see the hits with an empty “uid” parameter in the collection URL.

  • http://trevorfox.com Trevor Fox

    Is the new {{User ID}} variable different from leaving the Default Value empty? Each Variable’s Default Value tooltip says “To set the value to be an empty string, leave the field blank.” Wouldn’t this accomplish the same thing as the custom js variable? see here: http://pho.to/7nMDw

    • Dan

      Thanks for the feedback, Trevor. At the time of this blog post, leaving the {{User ID}} field empty (and not filling in the default value), caused the Universal GA tag to append the “uid” parameter to the query string with no value. This caused these hits to be discarded by GA. The ideal scenario is that when the {{User ID}} field is empty, the “uid” parameter should not be included at all.

  • https://www.analytics-toolkit.com/ Geo

    Hi Dan,

    I don’t see why you would want to go through that JavaScript or have two tags. Leaving the checkbox for “set default value” for your userID macro uncheked accomplishes the same.


    • Dan

      See my comment above. This issue has since been corrected by Google. Previously this was an issue that had to be addressed with JavaScript.