Google Tag Manager in a multi-tenant environment

by Dan on May 14, 2014

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:

 var dataLayer = [{
  'gaProfileId': '[Dynamic Code to Insert client's GA Profile ID]'

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.

Leave a Comment

{ 1 trackback }

Previous post:

Next post: