: How do you exclude yourself from Google Analytics on your website using cookies? I'm trying to set up an exclusion filter with a browser cookie, so that my own visits to my don't show up
I'm trying to set up an exclusion filter with a browser cookie, so that my own visits to my don't show up in my Google Analytics. I tried 3 different methods and none of them have worked so far. I would like help understanding what I am doing wrong and how I can fix this.
Method 1
First, I tried following Google's instructions, www.google.com/support/analytics/bin/answer.py?hl=en&answer=55481, for excluding traffic by Cookie Content:
Create a new page on your domain,
containing the following code:
<body onLoad="javascript:pageTracker._setVar('test_value');">
Method 2
Next, when that didn't work, I googled around and found this Google thread, www.google.com/support/forum/p/Google%20Analytics/thread?tid=4741f1499823fcd5&hl=en, where the most popular answer says to use a slightly different code:
SHS Analytics wrote:
<body onLoad="javascript:_gaq.push(['_setVar','test_value']);">
Thank you! This has now set a __utmv cookie containing "test_value",
whereas the original:
pageTracker._setVar('test_value')
(which Google is still recommending)
did not manage to do that for me (in
Mac Safari 5 and Firefox 3.6.8).
So I tried this code, but it didn't work for me.
Method 3
Finally, I searched StackOverflow and came across this thread, stackoverflow.com/questions/3495270/exclude-my-traffic-from-google-analytics-using-cookie-with-subdomain, which suggests that the following code might work:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setVar', 'exclude_me']);
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
// etc...
</script>
This script appeared in the head element in the example, instead of in the onload event of the body like in the previous 2 examples. So I tried this too, but still had no luck with trying to exclude myself from Google Analytics.
Re-iterate question
So, I tried all 3 methods above with no success. Am I doing something wrong? How can I exclude myself from my Google Analytics using an exclusion cookie for my browser?
Update
I've been testing this for several days now, and I've confirmed that the 2nd method of excluding yourself from tracking does indeed work. The problem was that the filter settings weren't properly applied to my profile, which has been corrected. See the accepted answer below.
More posts by @LarsenBagley505
7 Comments
Sorted by latest first Latest Oldest Best
Such task have to be solved by Google Analytics filters feature.
I recommend to take a look on this article - there are a few other Google Analytics filters which can be useful:
www.lunametrics.com/blog/2015/12/10/basic-google-analytics-filters/
For example, I recommend also to add filter which is excluding staging traffic (people often forget about this). You can do this in the following way:
Filter Name: Exclude Dev Site Traffic
Filter Type: Custom > Exclude
Filter Field: Hostname
Filter Pattern: Enter a regex pattern of all development hostnames for your website. For example, if the development hostnames are dev.example.com, backend.example.com, and stage.example.com you would enter ^dev.example.com$|^backend.example.com$|^stage.example.com$ in this field (or some similar Regex).
Another recommended filter - Lowercase domain (hostname):
Filter Name: Lowercase Hostname
Filter Type: Custom > Lowercase
Filter Field: Hostname
And the last one - lowercase request uri:
Filter Name: Lowercase Request URI
Filter Type: Custom > Lowercase
Filter Field: Request URI
This is Google's official plugin for all the most common browsers, which will exclude you from Google Analytics:
tools.google.com/dlpage/gaoptout
Have all your team members install it.
PS: The issue with the IP-based filtering method is dynamic IP address allocation.
If you are using Chrome only, use this:
chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh?hl=en-US
A quick and dirty way to stop all tracking on all sites is to edit your hosts file C:WindowsSystem32driversetchosts and add these entries.
You'll probably need to restart your browser after changing them.
0.0.0.0 google-analytics.com 0.0.0.0 ssl.google-analytics.com
You don't need to go editing filters on google's site. Of course this method is mostly useless if you have many users you need to exclude and it means you can't use the Google Analytics Debugger Chrome Plugin which I highly recommend for testing (it's publiched by Google).
A way to do it without cookies is by using an extension: www.igorware.com/extensions/block-yourself-from-analytics I like this because
I have the extension installed in Chrome so it is available across my devices
it is easy to setup
I don't need to create a hidden page that sets the cookie or change a real page temporarily.
If I erase my cookies I don't need to remember to re-enable them.
A quick and easy fix if you're using Firefox and don't want to mess your source code:
Get the noscript add-on mark "google-analytics.com" as untrusted. This will prevent Firefox from executing the tracker, and your visits won't show up in your stats, or any other website's stats for that matter.
There's nothing in your question about the second step of the process. The code you're using should just set a custom variable that will be sent to GA with the rest of the tracking data. You need to then set up a filter to exclude data where the variable is set to "test_value".
To create the filter , go to the "Analytics Settings > Profile Settings" screen and click on "Add Filter". In the screen that comes up use the following settings:
Add new Filter for Profile
Filter Name: Exclude own Traffic
Filter Type: Custom filter
Click the "exclude" radio button
Filter Field: User Defines
Filter Pattern: test_value
Case Sensitive: No
On a side note, remember that to set the custom variable you need to add the code to your page, run it then remove it. If you don't remove it then a cookie will be set for all visitors and they will all be excluded. It's best to set up an additional profile to test that the filter is working properly before applying it to your main profile as historical data can't be retrieved if you set it up wrong.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.