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

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

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$ 
RewriteRule ^(.*)$ http://shop.domain.com/ [R=301,L]

The web content offered by shop.domain.com has the adhering to tracking code parameters:

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

All straight brows through that involve shop.domain.com as an outcome of the revise from domain.com are tracked as reference website traffic, revealing my very own domain.com 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?

0
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.

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiSearchEngines.html#_gat.GA_Tracker_._addIgnoredRef

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:

http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php

0
2019-05-30 23:54:12
Source

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) {
  _gaq.push(['_setReferrerOverride',_from]);
}
_gaq.push(['_trackPageview']);

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

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

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

You will certainly require to duplicate the above for www.domain.com too.

0
2019-05-17 13:18:02
Source