How to disable tracking of developer and admin team actions in google analytics

We have created multiple web properties and profiles. set them up using https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gaq

Tried a few things to disable developer team and admin staff actions, like:

https://developers.google.com/analytics/devguides/collection/gajs/#disable

http://www.seerinteractive.com/blog/best-ways-to-exclude-internal-traffic-in-google-analytics#setCustomVar

Is there a way to stop Google Analytics counting development work as hits?

I see this Disable Google Analytics when in development but it's pretty old

We need this in the staging as well as the production application apps too. And we don't want to depend on user being logged in to know if he/she is a dev or admin, we want to have a unique hidden (from listing/menu) page where if a dev or admin goes, a cookie is set which prevents tracking till the user clears cookies.

Answers


The general best practice here is to have gaoptout installed across anyone internally.

Other than that you can setup a regex to exclude internal traffic by IP and/or set a permanent cookie in your employee section and check for it before firing.

/**
 * Required jQuery and jQuery.cookie
 */

// login-landing-page.html
$.cookie('employee', 'true', { expires: 365 * 24 * 60 * 60 * 1000 }); // expires in 1 year

// all other pages
if (!$.cookie('employee')) { // if not employee
    // _ga.push(['_setAccount _trackpageview']) etc...
}

Use cookies, but not how you think...

The "opt-out" add-on either hides your visits from ALL sites or doesn't work at all depending on who you ask.

Instead, keep a "developer cookie" set on your machines at all times for the domains that you manage. Set this cookie to have a unique value that is specific to your organization. Then, simply check for this cookie before sending any data to Analytics.

Examples of how to put the code into your pages...

JavaScript

if (window.location.host==="mydomain.com" || window.location.host==="www.mydomain.com") {
   if (document.cookie.indexOf("COOKIENAME=COOKIEVALUE") === -1) {
      // Insert Analytics Code Here
   }
}

PHP

if ($_SERVER['HTTP_HOST']==="mydomain.com" || $_SERVER['HTTP_HOST']==="www.mydomain.com") {
   if (@$_COOKIE["COOKIENAME"] !== "COOKIEVALUE") {
      // Insert Analytics Code Here
   }
}

Verifying that the HOST name equals the domain of your live app ("mydomain.com") ensures that the analytics data will never be sent by ANY visitor while viewing from a test domain such as "localhost" or "beta.mydomain.com". In the examples above, "www.mydomain.com" and "mydomain.com" are the two valid domains where we DO want visits to be recorded.

The live site sends data to analytics as expected UNLESS a developer cookie is found with matching values. If it finds that unique cookie set on your device, then your visit will not count towards the totals in Google Analytics (or whatever other analytics tool you might one day decide to use).

This method can easily be used by a team of people as long as they all use the same NAME/VALUE pair, so developers, content creators, proofreaders, and anyone else in your organization can all view pages without inflating the statistics.

To set the "developer cookie"...

Yes, you could visit a hidden page to set the cookie and give it a really long expiration date. But, clearing cookies can be a problem here, and they're invisible so you might not even be aware that they stopped working.

Or, you could use this Browser Extension to keep them set automatically... https://chrome.google.com/webstore/detail/lknhpplgahpbindnnocglcjonpahfikn

Full disclosure: I created this extension. I was facing the same problem as you and couldn't find a solution, so I made my own. It uses a visible green icon to illustrate whether the cookie is on or off for the current domain so I think it is easier for less tech-savvy team members and just helps everyone to remember to use it. Just click it once for that domain and you're good to go.


Need Your Help

Laravel 3 and MYSQL memory limit

php mysql laravel-3 memory-limit

I have a problem with a query that I have in Laravel 3.