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.
If you don't add a referral exclusion, your subdomain will show up as a referral to your own domain. If you do not want this, you'll want to exclude this subdomain from your referral traffic in your property level > tracking info > referral exclusion list.
GA4 also automatically handles subdomains. If you are working with a business that operates on multiple subdomains (e.g. blog.business.com, support.business.com, www.business.com, etc.), you will most likely want to track website visitors with Google Analytics across all these websites.
From the Select filter type menu, select Exclude . From the Select source or destination menu, select traffic from the IP addresses. From the Select expression menu, select the appropriate expression. Enter the IP address or a regular expression.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With