google analytics for subdomains - good practice
Say, I've a webs开发者_JS百科ite www.website.com, and we are maintaining a subdomain sub.website.com for blogging. Now my question, what is a good practice of having google analytics for both domains, same tracking for both or individually? and why?
Regards
Generally speaking, the best practice is to keep subdomains of the same domain on the same account. (The exception is if the subdomains are completely unrelated sites.)
It's important, though, to adjust your Google Analytics snippet to set its cookies on the root domain, so that users who traffic between subdomains are tracked as a single visit, instead of multiple visits.
You can accomplish that by putting the following call before your _trackPageview
call:
_gaq.push(['_setDomainName', 'example.com']);
Then, on the account management side, you can setup filters for individual subdomains (using Hostname filtering) so that you can get a snapshot of both the combined traffic and the individual subdomains.
EDIT: Removed the leading period on the URL. This will make it compatible with past traffic that doesn't have a setDomainName call.
[Expanded from comment above, as ran out of chars]
The setDomainName command as noted above will work, but if you're using an existing GA setup, using setDomainName = "example.com" (no leading dot) will retain existing GA user IDs, so the new-user metrics will still be valid (GA hashes the domainname into the user ID, but strips "www.example.com" down to "example.com" before hashing. However ".example.com" will hash to a different value, and the user IDs for returning users will not match their original IDs.
If you're starting a fresh site, use ".example.com" (and it's sometimes required for sites with deep FQDN), and don't forget to check what's being sent back to the GA with Firebug.
I think you can get away with just one domain. I never tried to use subdomains, but even with one domain, Google analytics gives you a good breakdown and visibility of the stats. Plus the urls of the pages are different and you can differentiate on that even if you track a single domain. Plus you will avoid domain-clutter.
精彩评论