Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible / how to deactivate the Piwik tracking for the local / dev project copy?

It would work with something like <?php if (current environment is / is not ...) : ?> print (Piwik code); <?php endif; ?>. But maybe there is a Piwik side "switcher"?

share|improve this question
up vote 0 down vote accepted

To my best knowledge there's no such switch. In my opinion, it's also impossible to implement one. The standard Piwik tracking code works with JavaScript that is executed in the visitors browser. Therefore, Piwik does "know" about the visitors computer, but not about the computer/server that served the JavaScript-Code. It can't possibly tell which copy from which computer served the tracking code.

The IMO best solution would be to set some parts of the tracking code variable. You could do something along the lines of, "if development system, track to Piwik website ID 1; if production system, track to ID 2". Another setting you could set variable would be the url of the Piwik installation, to do something along the lines of, "if development system, track to local dev installation of Piwik; if production system, track to prod installation".

That way you can kill two birds with one stone: You can keep the development installation from "polluting" your production data, while you can still see if the tracking data from the development system is generated correctly. With more site ID tracked in Piwik and/or more Piwik installations, as it would fit your needs, you can also handle more environments than "only" development and production, like test, staging etc.

share|improve this answer
PHP knows plenty about the server providing the page with the Javascript in it. That was the point of the pseudo-code in the question. – Su' Apr 19 '13 at 9:08
This answer is incorrect. For example, you could: if($_SERVER['SERVER_NAME'] != 'dev.example.com') {print (Piwik code);} – uberconversion Apr 19 '13 at 9:10
Of course the pseudo-code in the question would work. But the question was, can Piwik itself tell from which server the tracking code has been delivered. And that's not possible. Of course you can decide on the PHP level whether to print the tracking code at all or adjust the tracking code, as in my solution. – Henning Kockerbeck Apr 19 '13 at 12:03
Ah, you're right. Sorry about that. – Su' Apr 19 '13 at 15:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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