Multi tenant Google Analytics -


i have multi tenant site serves 2 domains: "a.com" , "b.net". want setup google analytics have separate information these 2 domains, example, see visitors, etc, each tenant independently of other. need 2 different keys (ua-xxxx-x), 1 each tenant? javascript shall use? using analytics.js.

i'd recommend using 1 account 2 different properties unique ua-id each website.

this way won't clutter properties a.com's data , b.net's data , vice versa.

the other way have 1 property 1 ua id , create include full url filter , segment and/or filter on specific domain.

analytics.js way go days. ga.js deprecated in future.

to add new property, click down property drop down , select "create new property". adding new property

you'd need if statement or check domain. if a.com post ua id a.com , vice versa.

something (in php):

<!-- google analytics --> <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', '<?php function ua() { if ($_server['server_name']=='a.com' ) {echo 'ua-xxxxx-x';} else {echo 'ua-xxxxx-x';} } ua(); ?>', 'auto');  ga('send', 'pageview');  </script> <!-- end google analytics --> 

Comments