# 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 בנובמבר,‏ 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:** 4
**Page:** 1

<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: [1 בנובמבר,‏ 2014,‏ 2:52pm UTC](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741/1 "2014-11-01T14:52:57Z")

</div>

We have multiple sites (for example, [forum.treode.com](http://forum.treode.com), [treode.github.io](http://treode.github.io) and [www.treode.com](http://www.treode.com)), which I’m sure is not uncommon. Currently we track each one as a separate “property” in Google Analytics. However, when a user moves from one site to the next, it shows up as a drop-off in analytics. Google has written [this helpful page](https://support.google.com/analytics/answer/1034342?hl=en&ref_topic=2772342) to explain how one can track multiple domains as a single property and see viewers flow from one domain to the next.

One of the steps to make that work involves tweaking the GA code that’s on the webpage. It appears that I don’t have a way in Discourse to make that happen.

---

<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 בינואר,‏ 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`.

---

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [10 בינואר,‏ 2015,‏ 4:23pm UTC](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741/3 "2015-01-10T16:23:24Z")

</div>

You can easily do this by add your Google Analystic code into `Admin > Customize > Text Content > HTML head`  
I never use Discourse build in to embed GA.

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [4 בדצמבר,‏ 2025,‏ 11:32am UTC](https://meta.discourse.org/t/support-cross-domain-tracking-with-google-analytics/21741/4 "2025-12-04T11:32:48Z")

</div>


