0

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"?

1 Answer 1

1

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.

4
  • 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'
    Commented Apr 19, 2013 at 9:08
  • This answer is incorrect. For example, you could: if($_SERVER['SERVER_NAME'] != 'dev.example.com') {print (Piwik code);}
    – David K.
    Commented Apr 19, 2013 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. Commented Apr 19, 2013 at 12:03
  • Ah, you're right. Sorry about that.
    – Su'
    Commented Apr 19, 2013 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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