简体   繁体   中英

Google Analytics with wildcard domains + subdomains

I want to have a single script in my shell/layout page that provides insight on whatever url is currently being used. I have a multitenant app that has URLs like:

  • app1.myapp.com
  • custom.com
  • myapp.com

These all are different domains, but will be hitting the same application with the same page. How can I use google analytics to report from "whatever the active URL is", instead of specifying URLs in the <script> ? I'm trying to avoid specifying domains because users of the app can map their own domains, so manual mapping will be unwieldy.

I have the following:

<script>
        (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', 'SSSSSSSSS', 'mysite.com'); // something here?  I've tried document.URL
        ga('send', 'pageview');

</script>

But this only tracks requests made to the base domain (myapp.com, sub.myapp.com), not other domains (differentapp.com). What changes do I need to make to get this working?

Document.url would not work because the expected format for this parameter (cookie domain) is a domain name, not a full url. But you can set the parameter to "auto" (or not set it all).

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