How to track subdomains with Google Analytics while having mod_rewrite redirect to a subdomain?

Posted by Marek on Pro Webmasters See other posts from Pro Webmasters or by Marek
Published on 2010-10-30T18:22:02Z Indexed on 2010/12/30 1:01 UTC
Read the original article Hit count: 734

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?

© Pro Webmasters or respective owner

Related posts about google-analytics

Related posts about url-rewriting