exclude my traffic from google analytics using cookie with subdomain
I got the cookie method of excluding my traffic to work when I didn't specify the domain. Now that I have specified the domain, it no longer works. It appears to be setting two cookies, the exclude.html page I created is setting a cookie of "mydomain.com" and the google analytics is setting a cookie of "www.mydomain.com".
Here is the code for my exclude.html page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Exclude Me</title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setVar', 'exclude_me']);
_gaq.push(['_setDomainName', 'www.mydomain.com']);
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<p>
This computer now has a cookie placed on it to exclude it from any Google Analytics reports.</p>
<开发者_运维百科;p>
If you delete your cookies, you will need to revisit/reload this page again.</p>
</body>
</html>
I added the _gaq.push(['_setDomainName', 'www.mydomain.com']);
to try and get it to work which doesn't appear to be doing anything. That is the way I have it setup for all the other pages, using the www.mydomain.com.
As I was typing this it appeared to me that the '_gaq.push(['_setDomainName', 'www.mydomain.com']);' should probably be put in before '_gaq.push(['_setVar', 'exclude_me']);' So I switched them around and it is no longer creating two different cookies, so hopefully that works.
When setting a "setDomainName", you should exculde the www from .mydomain.com. It's also important to notice that (.mydomain.com) and (mydomain.com) are two different domains and hence result two cookies (they are both valid, but you should stick with one of them).
精彩评论