≡ Menu

Google Tag Manager in a multi-tenant environment

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.

Comments on this entry are closed.

  • Pingback: Digital Analytics Week In Review - 16 May 2014 - Data Runs Deep()

  • Alex

    Hi Dan, I’m Alex from palbin.com (I’m following you on twitter from today). There are not many problems for the multitenant GA implementation, but we had a “double” google analytics account code to allow us get stats from own clients domains too (not subdomains of palbin.com). Do you know the best way to do it throught Google Tag Manager? Many thanks!

    Current code y classic GA:

    //************** GOOGLE ANALYTICS CLIENT **************//
    var _gaq = _gaq || [];
    _gaq.push([‘_setAccount’,’UA-ECOMMERCE’]);
    _gaq.push([‘_setAllowLinker’,true]);
    _gaq.push([‘_trackPageview’]);
    //************** /GOOGLE ANALYTICS CLIENT **************//

    //************** GOOGLE ANALYTICS MONIT **************//
    var _gaq = _gaq || [];
    _gaq.push([‘monit._setAccount’,’UA-SAAS’]);
    _gaq.push([‘monit._setDomainName’,’SAAS.com’]);
    _gaq.push([‘monit._setAllowLinker’,true]);
    _gaq.push([‘monit._trackPageview’]);
    //************** /GOOGLE ANALYTICS MONIT **************//

    • Alex

      I meant in their own online stores (not in our product web or admin pages)