简体   繁体   中英

Google analytics: tracking not working in subdomain

I have a website which has multiple subdomains. GA code is implemented in both root & subdomain1. While the root GA tracking is working perfectly, no counts are registered in the subdomain1.root.com. Both use the same tracking id.

Below is the code for root.

<script type="text/javascript">
    (function (i, s, o, g, r, a, m) {
    i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
    (i[r].q = i[r].q || []).push(arguments)
    }, i[r].l = 1 * new Date(); a = s.createElement(o),
    m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-TRACKINGCODE-1', 'root.com');
    ga('send', 'pageview');
</script>

Tracking code for the subdomain1

<script type="text/javascript">
    (function (i, s, o, g, r, a, m) {
    i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
    (i[r].q = i[r].q || []).push(arguments)
    }, i[r].l = 1 * new Date(); a = s.createElement(o),
    m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-TRACKINGCODE-1', 'root.com');
    ga('send', 'pageview');
    </script>

I see the website address in the subdomain code is pointing to the root address. Is this a cause of concern? Or what am I missing?

I found this link for tracking subdomains with a Root domain, but I don't know where to implement the code: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#domainSubDomains

Code they say to use: var pageTracker = _gat._getTracker('UA-12345-1'); pageTracker._setDomainName('example-petstore.com'); pageTracker._trackPageview();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM