I have a SaaS solution with multiple tenants, like a website builder. I want to be able track stuff like page views, visitors, and number of online users ... for ALL of these tenants in one place. I think Google Analytics covers a scenario like this, but I am not sure how to implement it.
Some tenants has domains, other has sub-domains:
- tenant1.app.com
- tenant2.app.com
- tenant3.com
- tenant4.com
I am trying to use one Google Analytics property to cover all of these domain, what is the correct tracking code that can accomplish that? Here is what I got so far, but I am sure it doesn't work correctly, and I probably mixing gtag.js with analytics.js (I think)
<script async src="https://www.googletagmanager.com/gtag/js?id=[account id]"></script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[account id]']);
_gaq.push(['_setDomainName', '<?= getTenant()->getDomain() ?>']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '[account id]');
</script>
PS: No traffic is shared between these tenants, visitors do not go from domain X to domain Y. So I am not sure cross-domain tracking is the solution here, since it deals with visitors crossing between different domain. I just want the total numbers for all these tenants.