Exclude Admin Traffic from Google Analytics

(Ultra Noob) #1


Are you running a client-side application, where you are unable to exclude yourself Analytics script?

Or, may be you are directly pasting Google Analytics code in the WordPress theme panel?

Both are the worst situtation which can result to big unrealistic data in Analytics Dashboard.

In WordPress, if you are using a plugin properly which provide exclude feature; then no worries.

Method to exclude own visits from Google Analytics

Step 1. Don’t change anything in Analytics Script.

Step 2. Add below gaOptout script before original Analytics script.

    function gaOptout() {
        document.cookie = disableStr + "=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/", window[disableStr] = !0
    //  Please replace with your own tracking ID
    var gaProperty = "UA-54832768-5",
        disableStr = "ga-disable-" + gaProperty;
    document.cookie.indexOf(disableStr + "=true") > -1 && (window[disableStr] = !0);

Step 3. Above script will filter loading of Analytics script based in the presence of gaOptout.

Step 4. Create an Opt-Out link for excluding yourself.
<a href="javascript:gaOptout()">Click here to opt-out of Google Analytics</a>

That’s it.

In WordPress, this process can be done using snippet

// Set Google Analytics Disbale cookie for logged in
function gk_exclude_admin_cookie() {
    $expire_time = time() + 60 * 60 * 24 * 180;
    setcookie( 'ga-disable-UA-54832768-5', 'true', $expire_time, '/' );
if( is_admin() ) {
    add_action('init', 'gk_exclude_admin_cookie');
// Filter GA tracking
function gk_ga_optout() {
    echo '<script>
    function gaOptout() {
        document.cookie = disableStr + "=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/", window[disableStr] = !0
    var gaProperty = "UA-54832768-5",
        disableStr = "ga-disable-" + gaProperty;
    document.cookie.indexOf(disableStr + "=true") > -1 && (window[disableStr] = !0);
add_action('wp_head', 'gk_ga_optout', 10);

I hope this helps.

Thanks & Regards,

Webmaster and google analytics showing different results
(Ultra Noob) #2

Real life application: I am using this at my blog, here at forum, also popular plugin MonsterInsight provides this feature.

Above script is taken from Internet source, Google Developers page.

(Aatish Kamble) #3

For this purpose, I’m using this chrome extension: Google Analytics Opt-out Add-on

(Dhananjay Bhardwaj) #4

Can Google’s own Publisher Toolbar help in this?

(Ultra Noob) #5

Chrome Extension is great when we are from Desktop, it doesn’t work on smartphone.

(Ultra Noob) #6

The Google Publisher tool is not for Google Analytics. It’s for AdSense.


Every blogger should install Google publisher toolbar and configure website in it… It will keep safe your account from fake impressions… And also it displays ad sizes, network etc…

(Ultra Noob) #8

Anyone who is concerned about user privacy, they can use above tutorial to provide user an option to out out from the Google Analytics. All you need to include the Opt out link at the Privacy Policy page as written on the Step 4.

(Serdar) #9

And there is a alternative way. You can exclude your ip adresses and also ip adresses of other admins in Google Analytics Settings…

(Ultra Noob) #10

IP is not a reliable way. It changes every hour when we are using a Mobile network.

(imamit) #11

To exclude my own traffic I just add the filter to exclude traffic from my city. I know it will not track other traffic from same city but its OK, I am not getting much traffic from my city.

(Saksham Kumar) #12

Where to add this in WordPress???

And according to you, using a plugin is better for this or by this method??

(Ultra Noob) #13

Google Analytics Dashboard for WP is a good plugin. It has feature to exclude admin. You can give a try.

Or … You should try my method if nothing worked or if you pasted Analytics code directly somewhere in Head or footer section.

You need to place snippet in the functions.php file or via Code Snippet plugin It will set opt out cookie and filter tracking for logged in users.

(Ultra Noob) #14

Were you able to setup? Or need help?

(Saksham Kumar) #15

I have installed that Google Analytics plugin and exclude the visits for Admin but still have one problem.

I check the sites by visiting them from either private window or by logging out to check the design and other things so in that case, they will include my visits also as the traffic right? Any way to fix this also?

(Ultra Noob) #16

Above method works based on Opt out cookie.

Therefore, when you open Incognito mode which is equal to logged out mode initially, hence GA can track.

If you want to completely opt out yourself from the Ga… you may try using extention or editing host file and pointing Google Analytic script domain to localhost (

(Saksham Kumar) #17

I will use Chrome for these things then… Thanks, BTW! :relaxed: