To take advantage of the new cross device measurement reports in Google Analytics, you need to enable the User ID functionality.  For these reports to be of any value, you need to be tracking user interaction across all of your web and mobile touch points against the same GA Property ID.  The property ID is that funky UA-XXXXXX-XX value that Google assigns you when you create a new Google Analytics property.

A typical hierarchy with views might look like this:

  • Client/Property Name (The UA-XXXXXXX-XX is assigned here)
    • Web Rollup View (Tracks all web hits – no filters)
    • Web Site Subdomain (For tracking a particular portion of your site  - filters to a specific subdomain)
    • Web Site Subdirectory (For tracking a particular portion of your site – filters to a specific subdirectory)
    • Mobile App Rollup (Tracks both iOS and Android hits for segmentation and aggregate reporting)
    • Mobile App iOS (Only tracks iOS SDK hits – Filtered to iOS operating system)
    • Mobile App Android (Only tracks Android SDK hits – Filtered to Android operating system)
    • User ID (Tracks authenticated users across all platforms)

In the above hierarchy, the top 3 views are ‘Web Site’ type and the bottom 3 are ‘Mobile’ type.  The last profile is the User ID profile that only records traffic when a User ID is passed along with the Google Analytics pageviews and events.  This enables those snazzy cross device measurement reports.

What you may not realize is that as of version 3.0.0 of the iOS and Android SDKs released on August 6th, 2013, the mobile SDKs were modified to record hits in the same manner as the web version.  While web and mobile profiles differ in tracking pageviews (screens in mobile), the sessions are similar.  As a result, your mobile sessions may be reflected in your web profiles and vice versa.  Oh the humanity!

Hindenburg

How do I know if I’m affected?

The quickest way to see if you’re affected by this, is to look at the Audience > Technology > Browser & OS report.  If you see a browser ‘GoogleAnalytics’, then you’re affected.  This is the browser the Android and iOS SDKs pretend to be when they record hits.

GoogleanalyticsBrowser

 

See how the report is showing the ‘GoogleAnalytics’ browser sessions, but no pageviews?  You can imagine the havoc this wreaks on your computed metrics such as bounce rate, pages/session and so on.

 

How do I fix it?

To prevent mobile SDK hits from sneaking into your web views add the following rule to all of your web views:

Screen Shot 2014-06-08 at 6.07.19 PM

 

** Hint: Once you save this rule, you can use it in other views.

To prevent web hits from showing in your mobile profiles, add this rule:

Screen Shot 2014-06-08 at 6.09.45 PM

Once you add these rules, you’ll be accurately reporting web hits and sessions in your web views and mobile hits and sessions in your mobile views.   Keep in mind that you should not add either of the above rules to your User ID views.   Doing so will remove the data needed to generate the cross device measurement reports.

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

 

{ 1 comment }

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.

 

 

{ 4 comments }

In many software-as-a-service (SaaS) companies, applications are multi-tenant.  This means you’ll have multiple clients sharing the same code base.  However, clients will often want their own Google Analytics profiles or even their own accounts.  To meet this need while also keeping things manageable in Google Tag Manager (GTM), you’ll want to store your clients’ Google Analytics (GA) Profile IDs in your database alongside their configurations.  Then, once an instance of a client’s site is loaded, you can pass the client’s GA Profile ID into the GTM data layer.

First, create a macro to hold the client’s GA Profile ID in GTM:

Screen Shot 2014-05-14 at 6.50.14 PM

 

 

Now create a tag instance that uses this macro for the GA Profile ID:

Screen Shot 2014-05-14 at 6.58.22 PM

The last thing we’ll do in GTM is create a rule that fires our new tag after we check that the GA Profile ID is populated:

Screen Shot 2014-05-14 at 7.02.13 PM

 

Now in our data layer on the multi-tenant application, we’ll pass the client’s GA Profile ID:

<script>
 var dataLayer = [{
  'gaProfileId': '[Dynamic Code to Insert client's GA Profile ID]'
 }];
</script>

Now you can scale your Google Analytics using Google Tag Manager!  When the gaProfileID in our data layer is populated with a value starting with ‘UA-’, then our rule will be true and our Universal GA tag will fire.  This same logic applies to adding additional dynamic values that may be client-specific but useful in the client’s GA profile.  If you have an aggregate profile that collects data across all clients, you can pass a unique client ID value as a custom dimension which will enable you to filter by client in your aggregate profile.

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

{ 3 comments }

How to set a UserID as a custom variable using the Google Analytics cookie

March 15, 2014

I’m an active member of the LinkedIn Google Analytics group and a fellow group member, Ruth, recently asked how to set the unique Google Analytics user ID from the GA cookie as a custom variable.  I responded with the JavaScript code that would do this in classic Google Analytics.  Before long Ruth asked how to do [...]

Read the full article →

Using Google Tag Manager to log JavaScript errors in Google Analytics

March 13, 2014

As a developer, client-side errors can be a real pain.  Developers usually do a good job logging server-side application errors, but often times ignore client-side errors.  As the web evolves, we’re seeing more and more single page applications that are heavily reliant on client-side service calls using technologies like AJAX.  This makes sites heavily dependent on JavaScript. [...]

Read the full article →

What’s next for Google Analytics and Google Tag Manager? Q&A with Justin Cutroni from Google

February 19, 2014

Last night, I had the pleasure of attending our local Web Analytics Wednesday meeting (yes, I know, on a Tuesday) at ThoughtFaucet in Burlington, VT. As Vermonters working in the web analytics space, we’re fortunate to have Justin Cutroni, Analytics Evangelist for Google, right here in our backyard. The format for the meeting was open Q&A. [...]

Read the full article →

How to implement Google Tag Manager in the WordPress Thesis Theme

November 24, 2013

For those of you using the WordPress Thesis theme (as this site is), you may be wondering how to properly implement Google Tag Manager.  The built in Thesis option for scripts places scripts such as Google Analytics at the end of the page just before the closing </body> tag.  This is not an ideal location [...]

Read the full article →

About to make the jump to the DoubleClick version of the Google Analytics script? Read this first.

November 23, 2013

Update 2/18/2014: As it turns out the logic I used in my test below has an issue due to using setTimeout to test whether the user’s browser had loaded the GA script successfully.  Phil Pearce commented and suggested following Andre Scholten’s method which avoids the use of setTimeout.  I’m happy to report that follow up [...]

Read the full article →

Google Tag Manager for Single Page Applications

July 17, 2013

Single Page Applications are becoming more and more common as web developers adopt asynchronous technologies such as AJAX, Node.JS and Knockout. One of the challenges of adding a web analytics solution such as Google Analytics to a Single Page Application, is the browser location (site address) does not change as a user performs actions on [...]

Read the full article →

Sampling a percentage of your users with Google Tag Manager

March 31, 2013

One of the neat features of Google Tag Manager is the ability to fire a tag or some custom JavaScript to only a certain percentage of your users.  Why would you want to do this?   Let’s say you want to use a test app like Optimizely but don’t want to pay for one of the [...]

Read the full article →