Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 149875

Send Google Analytics to two accounts

$
0
0

I know there are many posts about this, but I can't find a solution that works for us.

We have an application that we track in Google analytics using Tag Manager.

But each page should be able to send tracking data to two different Google Analytics accounts. And the we want our costumer to only have to feed their UA-code into the the admin of our page, and then our page will generate everything needed for them to track the page, as well as us. So this need to be an automated process, where we won't have to set anything up in our Analytics account for them to track the page in theirs. I hope that makes sense.

Just to illustrate, this is what we do now:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-XXXX');
</script>

And we would want to be able to do something like this (this is clunky and stupid, but hopefully you understand what we're after):

// OUR ANALYTICS TRACKING
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-XXXX');
</script>

// CUSTOMERS ANALYTICS TRACKING
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-YYYY"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-YYYY');
</script>

Viewing all articles
Browse latest Browse all 149875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>