How to track subdomains with Google Analytics while having mod_rewrite redirect to a subdomain?
- by Marek
When users come directly to domain.com or www.domain.com, I am redirecting them to shop.domain.com via this .htaccess rewrite:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://shop.domain.com/ [R=301,L]
The content served by shop.domain.com has the following tracking code parameters:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-6']);
_gaq.push(['_setDomainName', '.domain.com']);
_gaq.push(['_trackPageview']);
All direct visits that come to shop.domain.com as a result of the rewrite from domain.com are tracked as referral traffic, showing my own domain.com as referral source in Google Amalytics.
I would like to track these visits as direct traffic.
How to change the configuration to track mod_rewritten traffic on my subdomain coming from my own domain as direct traffic?