While filtering my own traffic in google analytics by cookie as described in https://www.google.com/support/googleanalytics/bin/answer.py?answer=5557... I found that every time there is an access coming from admin or another internal (authenticated) user the value of the cookie changes to "authenticated user" and so my own traffic is in the statistics again.

This happens because in function googleanalytics_footer 'pageTracker._setVar()' is used and so the value of the cookie gets changed from "test_value" to "authenticated user".

For a quick fix I changed the line

      if (count($fields) > 0) {

to

      $internal_traffic = FALSE;
      if (isset($_COOKIE[__utmv])) {
        if (strpos($_COOKIE[__utmv], 'test_value')) {
          $internal_traffic = TRUE;
        }
      }
      if (count($fields) > 0 && $internal_traffic == FALSE) {

This causes that the value of the cookie is only changed if the cookie does not contain 'test_value' and such it is an external access.

This works fine for me. But I'm not sure if this is the right place for the intervention or if there would be a better way to handle this.

If you think this is the right way, the next step could be to incorporate an input field into the settings dialog to define the name of the cookie.

What do you think about this?

Comments

hass’s picture

Category: bug » support
Status: Active » Fixed

You are linking to a IP address filter documentation. What have this to do with cookies!?!?!? Additional - by default - we do not track any hit on admin pages (also internal traffic). IP filters run after hits are tracked and if the analysis runs - hours or days after the data have been collected by google servers or may be in real time... but doesn't matter. This have nothing to do with a google cookie you cannot read (only google servers can read them)

smitty’s picture

Status: Fixed » Active

Sorry, it was the wrong Link (copy and paste isn't as easy as it seems ;-):

This is the right one (I hope): https://www.google.com/support/googleanalytics/bin/answer.py?answer=5548... and it says:

To exclude traffic by Cookie Content

Note: This is an advanced alternative to the previous method.

To exclude traffic from dynamic IP addresses, you can use a JavaScript function to set a cookie on your internal computers. You'll then be able to filter all visitors with this cookies from appearing on your Analytics reports.
How to exclude traffic by cookie:

1. Create a new page on your domain, containing the following code:

  <body onLoad="javascript:pageTracker._setVar('test_value');">

(Please note that this code is in addition to the Google Analytics tracking code that you have on every page of your website.)

2. In order to set the cookie, visit your newly created page from all computers that you would like to exclude from your reports.

3. Create an Exclude filter to remove data from visitors with this cookie. Follow these instructions http://www.google.com/support/googleanalytics/bin/answer.py?answer=55494
to create a filter with the following settings:

Filter Type: Custom filter > Exclude
Filter Field: User Defined
Filter Pattern: test_value
Case Sensitive: No

hass’s picture

Status: Active » Fixed

1. Add the users you don't like to track to a "Do not track user" role and uncheck this role from tracking...

2. If you need vice versa, see http://drupal.org/node/261997

3. Exclude logged in users ($user->id >0) from tracking. You need to adapt the logic in http://drupal.org/node/261997.

4. You can override the 'googleanalytics_segmentation_fields' list via settings.php (*Complex*)

$conf['googleanalytics_segmentation_fields'] = array(
  'roles' => 'User roles',
  'test_value' => 'Exclude user',
);

Than you create a profile field (for e.g. a checkbox) that enables or disables the tracking from logged in users...

5. Use parts from #4 and add some code to your theme...

6. Disable profile field tracking and use your own module only to set the var in GA footer code.

I don't have the time to support this, sorry - this is very advanced and special and I expect this will not work together with profile segmentation. It seems to be out of scope of this module.

smitty’s picture

Category: support » feature
Status: Fixed » Active

Wow! Your outline is really the platinum solution! Only flaw: As far as I can see it does only filter the access from registered users but not the internal access from anonymous users.

If I would 'only' want to filter the access of defined registered users I could do this very much simpler by putting in some code into the Page specific tracking settings (Add if the following PHP code returns TRUE):

global $user;
if ($user->uid == 1 || $user->uid == 22) {
  $return = FALSE;

But the problem is: I want to filter internal traffic from anonymous users too. And this can be done very easily by using the method proposed by Google. This method works quite well - if the small change mentioned in my original post is done. And the advantage of this solution is, that it filters all the traffic from the browser where the cookie is set, no matter if it's an anonymous or a registered user.

So: why not implement this? And perhaps enhance it with the mentioned settings field?

hass’s picture

You could also add a cookie detection to the visibility settings... and exclude tracking for your cookie. This way you don't need to use the Google variant and implement yours. This is tooo special... I don't like to hardcode this... a handbook page with a workaround should be at least enough. Keep always in mind cookies may be deleted by users or blocked at all... this is no real solution and not stable at all. Use fixed IP's... IPv6 is coming... :-)))

hass’s picture

Status: Active » Closed (won't fix)

Sorry, but this an unstable/unsafe workaround for an minor edge case. This is out of scope.

smitty’s picture