: How to use Google Analytics to track a development and production versions of the same site on different servers? I have a website with two versions, one for production and one for development
I have a website with two versions, one for production and one for development (testing new features). All of the code is under version control and the websites are on separate servers.
Currently, I have the same Google Analytics Tracking code used on both sites. Since the code is under version control, it would be ideal to either have an if I am on production, use this code; else if on development server use that code clause. But I suspect that Google makes it easier to do something like this.
I see that there are many ways to configure a GA tracking code, e.g. "a single domain" vs. "multiple top level domains". But it is not clear to me how to set this up.
Also, if tracking code configured for a single domain has been on the development server, have I been picking up traffic to both sites, or does GA just ignore the second domain that I haven't registered?
More posts by @Shanna517
2 Comments
Sorted by latest first Latest Oldest Best
I have been working on something similar and the solution I came up with was to include my analytics snippets via PHP (rather than pasting the snippet itself into the pages/templates). On the development server I have the snippet itself commented out and I have the file(s) which contain the snippet listed in my .gitignore file.
Another simple way to do this would be via a tag manager.
I see that there are many ways to configure a GA tracking code, e.g.
"a single domain" vs. "multiple top level domains". But it is not
clear to me how to set this up.
The single/multiple domain setup has nothing to do with your test environment. It's supposed to be used when in production you have one or multiple domains accordingly.
To remove development and testing data from Google Analytics I recommend using a filter if you have a static IP address or if you don't just create a filter that executes the Google Analytics or not based on a check if the current environment is production or not.
Also, if tracking code configured for a single domain has been on the
development server, have I been picking up traffic to both sites, or
does GA just ignore the second domain that I haven't registered?
You've been picking traffic from both.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.