We are planning to use Google Analytics in our organization and I am in charge for setting it up. I was wondering how to deal with multiple environments. We sure do not want to collect data during development and QA (or maybe collect data to a different analytics account), but we want to when the site goes to production (obviously).

How do you deal with multiple environments and Google Analytics ?

Do you setup multiple accounts for Google Analytics and use either one depending on the environement ?

4 Answers
4

The easiest answer is yes, setup multiple accounts for each environment. Then, replace the profile ID (the text that looks like 'UA-XXXXX-X', as seen here) with the correct ID from the desired environment.

Since you are using ASP.NET, you can store the profile ID in the web.config. This will lead to having to embed .NET code within JavaScript (which may or may not be okay).
You could also configure the production configuration to be the only configuration to output the tracking code, but that would lead to code being released that wasn't tested.

Depending on how you host your site (dev.domain.tld, test.domain.tld, www.domain.tld) you can possibly use a single profile and then filter the results based on subdomain/folder/url. Google has a pretty good article on the various tracking scenarios.

Another option would be Google Analytics profiles. Use the same account in all environments, but add a hostname filter in each profile to only include traffic from the respective environment.

For example, if your internal QA environment is qa.example.com, create a "QA" profile in Google Analytics with a custom filter to only include hostnames matching ^qa\.example\.com$. In your "Production" profile, do the opposite and exclude traffic from internal hostnames.

If you want to exclude internal traffic from appearing in your reports, you can filter out a specific IP address or a range of IP addresses. You can also use cookies to filter out visits from particular users. We'll explain how below.