Using Hosts Files With Google Analytics
When you decide to use a hosts file to test your site, make sure that you're aware of the Google Analytics tracking implications of using the files.Â
With hosts files, you're able to choose the hostname for a site. If you've got Google Analytics set up to include or exclude certain hostnames, make sure that what you're setting your hosts file to in compatible.Â
If you're including your staging traffic in a separate view in Analytics through a hostname filter, and your staging URL is what you're overwriting with your hosts file, your traffic is not going to appear in the staging profile.
If you're overwriting the staging hostname to your production hostname, remember that your staging tests are going to show up in your production analytics view; unless, of course, you make sure that you're separately filtering out your own IP address from the production view.Â
If you want to block tracking in Google Analytics all together through your hosts file, append these lines to the bottom of your file:
127.0.0.1 www.google-analytics.com 127.0.0.1 google-analytics.com 127.0.0.1 ssl.google-analytics.com
Good luck with testing! Hopefully these tips will help you successfully filter out your analytics and keep your data clean.Â













