Skip to content

Instantly share code, notes, and snippets.

@rbdcti
Created January 27, 2012 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbdcti/1688847 to your computer and use it in GitHub Desktop.
Save rbdcti/1688847 to your computer and use it in GitHub Desktop.
Exclude multiple sites from Google Analytics
<!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">
<!-- See http://www.alwaysgoingnorth.com/exclude-your-visits-from-google-analytics-even-if-you-have-a-dynamic-ip/ for how to use this -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Exclude Me</title>
</head>
<body>
<p>This computer now has a cookie placed on it to exclude it from
Google Analytics reports for the following domains: </p>
<script type="text/javascript">
var _gaq = _gaq || [];
var gaqInstructions = [];
var profiles = [
['UA-23217991-1', "http://www.mysite1.com"],
['UA-23217991-7', "http://www.mysite2.com"],
['UA-23217991-5', "http://bla.mysite3.com"]
];
//Exclude from all of our domains/profiles
var prefix = null;
for(var i = 0;i < profiles.length;i++) {
prefix = String.fromCharCode(97 + i) + '.'; //start with 'a'
gaqInstructions.push(
[prefix + '_setAccount', profiles[i][0]],
[prefix + '_setVar', 'exclude_this'],
[prefix + '_trackPageview']
);
//if(console && console.log) console.log("Excluding: " + profiles[i]);
document.writeln(profiles[i][1] + " (UA: " + profiles[i][0] + ")<br/>");
}
(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>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment