How To exclude Google Analytics for Logged in users
Description:
Using this snippet, you will be able to exclude google analytics tracking code for logged in users.
You just need to past the following code to your function.php or use as standalone plugin with the proper customization
The Code:
// function for inserting Google Analytics into the wp_head
add_action('wp_footer', 'wpc_ga');
function wpc_ga() {
if ( !is_user_logged_in() ) { // not for logged in users
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX']); // insert your Google Analytics id here
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
}


