Setting up subdomain tracking in Google Analytics for Joomla
Some websites use more than one domain or several subdomains to serve content to visitors. You could for instance have most of your website’s pages located on www.domain.com, you’re your support forum is located on a sub-domain, support.domain.com. Google Analytics considers both of these domains as different entities and will not track them automatically. This means that whenever you visit both domains, Google Analytics will consider you to have made two visits, instead of just one. The same problem occurs with two entirely different domain names (www.domain.com and www.domain123.com).
Google Analytics plugin for Joomla
Analytics for Joomla has built two different plugins to makes sure all of your visitors will be tracked across several domains. Follow the next steps to make sure you can track all your visitors correctly in Joomla websites with multiple domain names:
- Download one of our Google Analytics plugins (check out the list of features to learn more)
- Install the plugin on your websites on the different domains
- Go to the plugin section to setup the plugin correctly (installation documentation)
- Select sub-domain tracking or multiple domain tracking in the configuration of the plugin
- You’re done!
So what did the Joomla plugin add?
The normal tracking code of Google Analytics will look like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_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>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', '.domain.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
_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>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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>
Is everything setup now?
- Choose Add New Filter and provide the filter a name.
- Choose Custom Filter and select Advanced on the Filter type settings.
- Under Advanced settings:
- Field A should be set to Hostname
- Field B should be set to Request URI
- Set the values for both Field A and Field B to (.*), which is an expression that captures all characters.
- Set the Output To --> Constructor option to Request URI and provide $A1$B1 as the value for that choice.
Getting advanced
If you link one website to the other, you still have to add a bit of additional code to the link in your page. You won’t have to do this if you link to the main domain from a subdomain. Here’s an example:
Old link:
New link:
onclick="_gaq.push(['_link', ' http://support.domain.com/intro.html ']); return false;"> check this link out </a>
For additional documentation on subdomain and multiple domain tracking, please check out the Google Analytics help section.
Tweet