2
votes

At work we have a dynamic IP address so excluding internal traffic by IP doesn't work for us, we have to set a cookie in the users browser which tell Google Analytics to exclude any traffic from users with this cookie installed.

The cookie we use is:

<body onLoad="javascript:_gaq.push(['_setVar','me_exclude']);">

This cookie is on a page /ex that not linked to, so the only people who would visit it would be people who knew to exclude themselves from the Google Analytics.

What I was wandering is do you need to also include the tracking code on this page for the exclude cookie to work, or is the line above all that's needed?

1
Better to deploy the google opt out plugin in your company: tools.google.com/dlpage/gaoptout - Eike Pierstorff
thanks for that, ive been looking for one of those for ages but only able to find chrome plugins, and were all of firefox. cheers - sam

1 Answers

0
votes

I almost gave up searching for answer, but then found this: https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#optout

1) Make yourself a dummy page on your site. For example: www.yourdomain.com/exclude-traffic.html

2) Add in <meta name="robots" content="noindex, nofollow"> in head, so the page wont be indexed.

3) Add script above your tracking code inside the head tag. Make sure you update UA-XXXXXXXX-Y values. You can check your GA code in Admin -> Tracking info -> Tracking code

4) Add link inside body tag.

5) Open the page and click on the link.

Final result:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>Remove My Internal Traffic from Google Analytics</title>
        <meta name="robots" content="noindex, nofollow">
        <script>
            // Set to the same value as the web property used on the site
            var gaProperty = 'UA-XXXXXXXX-Y';

            // Disable tracking if the opt-out cookie exists.
            var disableStr = 'ga-disable-' + gaProperty;
            if (document.cookie.indexOf(disableStr + '=true') > -1) {
                window[disableStr] = true;
            }

            // Opt-out function
            function gaOptout() {
                document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
                window[disableStr] = true;
            }
        </script>
        <script>
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
            })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

            ga('create', 'UA-XXXXXXXX-Y', 'domainname.com'); //now its changed to auto
            ga('send', 'pageview');
        </script>
    </head>
    <body>

    <h1>Remove My Internal Traffic from Google Analytics</h1>
    <p><a href="javascript:gaOptout()">Click here to opt-out of Google Analytics</a></p>

    </body>
    </html>