2

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.

Community
  • 1
  • 1
JV.
  • 2,658
  • 4
  • 24
  • 36
  • Any chance your production and dev enviroment is on diffrent servers, diffrent netowrks? – Linda Lawton - DaImTo Feb 07 '14 at 07:53
  • Your linked articles already cover all options - for your scenario you'd use the approach from the second link in your post and add a function in the main site that checks for the opt-out cookie (which would be set on the hidden page. Or you set the cookie automatically when the users logs in, presumably your app knows who is admin or dev). IMO the browser plugin is a better approach since it still works when somebody accidentally deletes their cookies. Can you tell why the linkes approaches did not work for you ? – Eike Pierstorff Feb 07 '14 at 08:39
  • 1
    why don't you filter the view by your IP address? or simply use the opt-out from Google (https://tools.google.com/dlpage/gaoptout) – Petr Havlik Feb 08 '14 at 17:39
  • @DalmTo yes they are on different networks and servers. Different Heroku Apps – JV. Feb 19 '14 at 08:26
  • @PetrHavlík the devs are on DHCP a lot many times, i.e. dynamic IP addresses, so can't restrict IP/range – JV. Feb 19 '14 at 08:26
  • @EikePierstorff if I knew why they did not work, I would have solved this :) Even the hidden page approach did not work. Lately we have realized that we are not instantiating GA script directly, rather we are using a third party common analytics service segment.io to push logs/events to different third party analytics apps (like GA, mixpanel, etc) at the same time. And we are thinking that this might be interfering with GA, somehow. Still investigating this. Will update soon. – JV. Feb 19 '14 at 08:31
  • Then I suggest telling your dev-team to use the OPT-OUT feature :) – Petr Havlik Feb 19 '14 at 08:31
  • to all who have responded: sorry folks, I got busy with some other tasks lately and could not respond back earlier. Got back to this today itself. @PetrHavlík that will be our last resort if nothing works soon. – JV. Feb 19 '14 at 08:35

2 Answers2

0

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...
}
TomFuertes
  • 7,150
  • 5
  • 35
  • 49
  • we have already tried this. not with jquery and jquery cookie but by telling GA to set such a cookie on a hidden page and the admin page. but doesn't seem to be working for us. IP restriction does not work for us because devs are on DHCP. gaoptout is the final resort, if nothing works soon. – JV. Feb 19 '14 at 08:33
0

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.

seebigs
  • 869
  • 8
  • 9