Increase revenue from Joomla Websites

Analytics for Joomla provides resources to optimize and get insights for Joomla websites without knowledge of HTML

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:

  1. Download one of our Google Analytics plugins (check out the list of features to learn more)
  2. Install the plugin on your websites on the different domains
  3. Go to the plugin section to setup the plugin correctly (installation documentation)
  4. Select sub-domain tracking or multiple domain tracking in the configuration of the plugin
  5. You’re done!

So what did the Joomla plugin add?

The normal tracking code of Google Analytics will look like this:

<script type="text/javascript">
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>
If you select subdomain tracking in the plugin interface, this will add three lines of additional code. It automatically pulls your domain name from your website to add to the code :
<script type="text/javascript">
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>
If you select multiple domain tracking, the new tracking code will look something like this:
<script type="text/javascript">
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?

You are almost there. Just one last problem to tackle. Let’s say you use two sub-domains (www.domain.com and support.domain.com). If they both have the same url’s in their structure (i.e. www.domain.com/login and support.domain.com/login), you still run into a little trouble. Your Google Analytics interface won’t recognize them as two different url’s. You can solve this by using the following filter to append the domain name to the url in your Google Analytics interface.
  1. Choose Add New Filter and provide the filter a name.
  2. Choose Custom Filter and select Advanced on the Filter type settings.
  3. Under Advanced settings:
  4. Field A should be set to Hostname
  5. Field B should be set to Request URI
  6. Set the values for both Field A and Field B to (.*), which is an expression that captures all characters.
  7. 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:

<a href="http://support.domain.com/intro.html">check this link out</a>

New link:

<a href="http://support.domain.com/intro.html">
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.

Share your comments