1

My website is hosted on a domain such as example.com, and website visitors progress from example.com to sub.example.com where we host surveys. At the moment, visitor data lists example.com as the main traffic source to sub.example.com. I want the source/medium and other data to be preserved when visitors go from example.com to sub.example.com, so I can look at certain pages on sub.example.com and see how they originally got to example.com.

Here is the analytics code for example.com:

<script type="text/javascript">//<![CDATA[
        // Google Analytics for WordPress by Yoast v4.3.5 | http://yoast.com/wordpress/google-analytics/
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-2596968-5']);
                        _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>

And for the sub.example.com:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>     
<script type="text/javascript">
try {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2596968-5']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview', '/surveys/[survey name]/[location]/page[number]-[status].html']);
} catch(err) {}</script>

Note: The fields in square brackets are automatically inserted from the survey software.

-1

You need to set the same domain name on each subdomain. On your code change only second parameter for yours domain name in that part:

_gaq.push(['_setDomainName', 'none']);

More info: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite?hl=pl#domainSubDomains

  • 1
    Link only answers are not high quality answers. Please fully explain the solution here so that nobody has to click. Include the link as a reference to support your answer. (I have downvoted, but would be happy to upvote when you edit it.) – Stephen Ostermiller Oct 27 '14 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.