# Support cross domain tracking with Google analytics

**URL:** <https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741>\
**Category:** Feature\
**Created:** [1 Novembre 2014, 2:52pm UTC](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741 "2014-11-01T14:52:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![TopherTheGeek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/topherthegeek/32/114909_2.png) [@TopherTheGeek](https://meta.discourse.org/u/TopherTheGeek)\
**Post date:** [10 Gennaio 2015, 3:35pm UTC](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741/2 "2015-01-10T15:35:33Z")

</div>

### Implementation Detail

I was thinking about how to implement this. Currently, under `Admin` → `Basic Setup` there are options `ga universal domain name` and `ga tracking code`. These options trigger the addition of this script for Google Analytics:

```plaintext
<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-12345678-1', 'auto');
ga('send', 'pageview');
</script>

```

To support this feature, we could add the option `ga linked domains`. If that was blank, we would continue to emit the tag above. However, if it contained a comma separated list of domains, we’d adjust the tag to look like this:

```plaintext
<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-12345678-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['a.example.com', 'b.example.com', 'etc.example.com']);
ga('send', 'pageview');
</script>

```

The difference between these two is in the line that begins `ga('create'` , and the two additional lines after it.

### Workaround

In the meantime, I found that there’s a simple workaround. You can get this by using `Admin` → `Customize` → `Text Context` → `Bottom of the pages`. I cleared my Google Analytics settings under `Basic Setup`, and pasted the Google Analytics tag (with linked domains) into `Bottom of the pages`.

---

_[View the full topic](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741)._
