A common scenario is for a new website to be built on a test staging server that requires tracking to be implemented. Ideally, you’d want to set all the tracking up on the test site but you don’t want this data going into the main Google Analytics Property since it’s not real data but you do want to be sure all of the tracking is in place and works correctly.
The best way I’ve found to do this is to:
- Create a new Google Analytics property just for the test site.
- Deploy the Universal Analytics page view tag through Google Tag Manager which is also implemented on the test site.
At this stage, we have enough in place to set up and test the tracking.
- Next, deploy another Universal Analytics page view tag that uses the (live site) Google Analytics ID BUT add an exception to the trigger:
The exception is a page view trigger that looks like this:
Where staging.somewebsite.co.uk is the hostname of the staging site.
So what we’re saying is – run this page view tag but not if it’s the staging site. This way when the developer moves the site from staging to live our tracking kicks in without our having to do anything and there’s no danger of our live tracking running on the staging site.
The second benefit is that as soon as the site is live our tracking is running!