Is there a way (in code or configuration) that I could prevent google analytics from collecting visits on any of my development websites?

  • Are you asking how to automatically turn off Analytics module on your dev environment, server side? If you are looking for a browser solution, it belongs to Super User, not here.
    – Mołot
    Jan 14, 2014 at 8:32
  • Hi, this would be a question for the analytics team over at Google. There may be a bunch of ways to do this but all of them involve changing your analytics code/settings, none would involve Drupal. For example, you can set filters on your analytics data to exclude certain IP addresses.
    – Clive
    Jan 14, 2014 at 9:45
  • 1
    Now, there are a few ways this can be done within Drupal (assuming you're using Drupal 8). 1: Add this to your settings.php or settings.local.php on the environments you want to exclude: $config['google_analytics.settings']['account'] = 'UA-XXXXXXXX-X';. 2: Use the Configuration Split module to create specific per-environment settings.
    – karolus
    Oct 6, 2018 at 13:51

2 Answers 2


just add the following line in in hosts file in computers which you want to exclude analytics tracking: www.google-analytics.com
  • Nice hack. But wouldn't it make this change for all the sites which might include the other(non dev) sites as well. I think it would be better to keep it at web-site level and not server level.
    – Gokul N K
    Jan 14, 2014 at 9:14
  • It shouldn't track our own visits in any of our sites be it dev or production ones.
    – AgA
    Jan 14, 2014 at 9:34

I am assuming that you are referring to Bots or Crawlers. If that is true you can add a robots.txt file. Visit http://www.robotstxt.org/faq/prevent.html to know more about it.

If you are in fact referring to the Google Analytics, you can just disable the module or remove the tracking code if you have added it manually.

  • Analytics is not bot or crawler, it is a script his site deliberately executes.
    – Mołot
    Jan 14, 2014 at 8:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.