A few months ago I wrote about a technique I use so that Adsense ads aren’t shown to me when I’m viewing my sites. Recently I started doing the same with Google Analytics code so that I don’t show up in my stats.
Yes, I know that Google has instructions for doing this but they assume a dedicated IP address which, because of a cable modem, do not have. It would be nice if there was some way to define a filter that worked on the user-agent string, and if anybody reading this knows how please add a comment. But barring that, I’m using my method.
Just swap out ABC below with whatever unique string you put in your query string.
if (strpos($_SERVER['HTTP_USER_AGENT'], 'ABC')!==false) { echo '<!--Hiding Analytics Code-->'; } else { // The full Google code echo '<script> (JS Code that Google gives you)</script>'; }
Be First to Comment