I'm confused by the Google documentation for analytics.js
Need to track cross domains, e.g. main-site.com blog-site.com
I set up a new property in Google Analytics and received the tracking code for main-site.com.
Step 1: Installed tracking code at page bottom in main-site.com
<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', 'UA-000000-X', 'main-site.com');
ga('send', 'pageview');
</script>
Step 2: instructions for analytics.js for cross domain (installed on main-site.com) Add the following before script ending tag.
// Load the plugin.
ga('require', 'linker');
// Define which domains to autoLink.
ga(‘linker:autoLink’, [‘main-site.com’, ‘blog-site.com’]);
Step 3: add tracking code to blog-site.com
// UA-000000-X is the tracking code number for main-site.com
ga(‘create’, 'UA-000000-X', {
‘allowLinker’: true
});
Problem: we need to track traffic that does not original in main-site.com. For example, a link from Facebook to blog-site.com should still count under the main-site property in GA.
