You may want to hide your Google analytics tracking code from your IP address. Why? So you can get more accurate data from the analytics program. If you track your own visits that is not giving you the full picture of your visits. Here is how you do it.

Step #1 Hide Your Analytics Tracking Code From Your IP Address

Go to Google search and type in "What is my IP". You will see that Google shows you your IP address. what-is-my-ip

Step #2 For Hiding Analytics Code From Yourself

Now you know your IP address. Open up a text editor and paste the following code into it. You have to do 2 things to this code.
  1. Replace your.ip.address with your actual IP address. Make sure that you leave the single ' on both sides of the ip address.
  2. Paste your analytics code over top where it says PASTE YOUR ANALYTICS CODE HERE. Again make sure you leave the single quote ' on both sides of the code.
<?php
add_action('wp_head', 'dont_track_my_ip');
function dont_track_my_ip() {
$myip=$_SERVER['REMOTE_ADDR'];
if($myip!='your.ip.address'){
echo 'Paste your Google Analytics code here';
}else{
echo '';
}
}
?>

Step #3 To Hide Your Google Analytics Code

Navigate to your themes functions file. Hopefully this is a child theme. Paste the code at the bottom of your functions file before the php closing tag if you have one, "?>". Save the file.

Step #4 Check your Browser

Load up your google analytics in one tab and in another tab load your website. In Google analytics go to real time and see if you can see your location. You should not see yourself.

Alternative Method For Hiding From Google Analytics

If you do not have a wordpress website and you want to hide your visits from  your website then use this code.
<?php
$myip=$_SERVER['REMOTE_ADDR'];
if($myip!='your.ip.address'){
echo 'Paste your Google Analytics code here';
}else{
echo '';
}
?>
You could paste the above code into your header.php in your theme.

 


Sign Up To Comment