How to migrate to Google Tag Manager without any loss of data

A common scenario is migrating clients from hardcoded Google Analytics tracking to Google Tag Manager. In this post, I will explain how to switch over without any loss of data at all.

The way we’ll to do this is to create a custom javascript variable that checks to see if Google Analytics tracking is hardcoded in the source code.

We’ll then use this as an exception in the basic Universal Analytics tracking tag deployed through GTM i.e. fire the Universal Analytics page view tag unless hardcoded Google Analytics code is on the page.

This way we can deploy our new Universal Analytics page view tag and it will do nothing……until the developer removes the hardcoded Google Analytics Tracking Code and then our GTM tag will kick instantly with no loss of data. It also means the developer can remove the old code when they like and we know our new tracking will take over.

Start by setting up your Google Tag Manager container and add the basic Universal Analytics page view tag. Make sure the Tracking ID is the same as the hardcoded analytics that’s currently on each web page.

Next, create a Custom Javascript Tag and set it up like this:

All that says is return TRUE if Google Analytics tracking exists in the source code (hardcoded), otherwise, return FALSE.

Now create a trigger like this (named: Hardcoded Analytics Script)

Where ‘GA Code Exists’ is the Custom Javascript variable we created earlier.

Next, alter  the trigger of your Universal Analytics page view tag to look like this:

Now our Universal Analytics page view tag is set to run on all pages except when hardcoded Google Analytics is found in the source code.

 

 

 

 

 

 

 

Author: Kevin Thomson

Head of Analytics & Measurement at Attacat

Leave a Reply

Your email address will not be published. Required fields are marked *