I have a website say, www.example.com with subdirectories www.example.com/sub1 and www.example.com/sub2. I have created 3 profiles in Google Analytics account. ‘General’, ‘Sub1’ & ‘Sub2’. ‘Sub1’ & ‘Sub2’ have filters to only include subdirectories for each. My intention is to get information about hits to my website in ‘General’ profile AND information about hits to specific subdirectory ‘Sub1’ or ‘Sub2’ in the respective profile. I have added this in my JS
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GOOGLE_ANALYTICS_ID']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Do I need to add anything else in my JS ?
Is there any advantage of including
_gaq.push(['_setDomainName', '.example.com']);
_gaq.push(['_setCookiePath', '/Sub1']);
in my JS ? I went through Google Analytics documents but could not find advantage of using this, if I have already defined filters in my account. Please shed some light on it.
Neither
_setDomainNameor_setCookiePathare needed in your case._setDomainNameis only needed if you’re dealing with multiple domains and/or subdomains, likewww.example.com,sub1.example.com,www.example2.com, etc._setCookiePathallows tracking of multiple distinct sites on a domain, but makes the general rollup tracking more difficult.Google Analytics uses cookies to track things like session status, referral data, etc.
Normally, root (/) is used as the default cookie path for an entire site. If you try using
setCookiePathto set different paths for different parts of your site, the tracking data is going to be inconsistant across the whole site.Since you have one site, but want different views of the data, only one cookie path is needed, and the default path will work.
FYI: Filters in Google Analytics are not retroactive — they only apply to new tracking data coming in, not data that’s already been recorded.