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

When customers come straight to or, I am rerouting them to using this.htaccess revise:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$ 
RewriteRule ^(.*)$ [R=301,L]

The web content offered by has the adhering to tracking code parameters:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-6']);
_gaq.push(['_setDomainName', '']);

All straight brows through that involve as an outcome of the revise from are tracked as reference website traffic, revealing my very own as reference resource in Google Amalytics.

I would love to track these brows through as straight website traffic.

Just how to transform the arrangement to track mod_rewritten website traffic on my subdomain originating from my very own domain name as straight website traffic?

2019-05-13 03:14:04
Source Share
Answers: 2

Instead of bypassing the referrer details, you need to add the subdomain to the Referrer Ignore List that Google Analytics shops.

You can do this making use of the _ addIgnoredRef () method in the GA API.

Google is summary of the the method:

_ addIgnoredRef ()

Excludes a resource as a referring website. Utilize this alternative when you intend to set particular referring web links as straight website traffic, as opposed to as referring websites. As an example, your firm could possess an additional domain name that you intend to track as straight website traffic to make sure that it does disappoint up on the "Referring Sites" records. Demands from left out references are still counted in your total web page sight matter.

Note: the instances offered by Google might not be 100% proper. Look into the adhering to link for a thorough conversation and also instance execution:

2019-05-30 23:54:12

You can bypass the referrer that Google Analytics is making use of, find out more in the documents for _setReferrerOverride.

To in some way give this proper referrer, you require to pass it using the 301 redirect. I can recommend including a question parameter to your rerouted link, and also creating a javascript fragment that will certainly extract this details from the document.location.

An instance of including javascript to your GA code:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
var _from = unescape(window.location.href.replace(/.*[?&]from=(.*)/,'$1'));
if (_from && _from.length > 0) {

And, an instance of making use of mod_rewrite to move the referrer, if a referrer exists:

RewriteCond %{HTTP_HOST} ^\.com$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} (.*)
RewriteRule ^(.*)$$1?from=%1 [R=301,QSA,L]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

You will certainly require to duplicate the above for too.

2019-05-17 13:18:02