I have two property tracking IDs in my Google Analytics account for the same website. I basically want to have the same set of data inserted into both properties/views. Currently, this is how I have it set up on the site:
JavaScript
x
11
11
1
<!-- Global site tag (gtag.js) - Google Analytics -->
2
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
3
<script>
4
window.dataLayer = window.dataLayer || [];
5
function gtag(){dataLayer.push(arguments);}
6
gtag('js', new Date());
7
8
gtag('config', 'UA-XXXXXXXX-1');
9
gtag('config', 'UA-XXXXXXXX-3');
10
</script>
11
However, I have come to realize this is not actually working correctly. I believe the proper solution to this is this (two sets of script tags, one for each property), but I am not 100% sure:
JavaScript
1
20
20
1
<!-- Global site tag (gtag.js) 1 - Google Analytics -->
2
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
3
<script>
4
window.dataLayer = window.dataLayer || [];
5
function gtag(){dataLayer.push(arguments);}
6
gtag('js', new Date());
7
8
gtag('config', 'UA-XXXXXXXX-1');
9
</script>
10
11
<!-- Global site tag (gtag.js) 2 - Google Analytics -->
12
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-3"></script>
13
<script>
14
window.dataLayer = window.dataLayer || [];
15
function gtag(){dataLayer.push(arguments);}
16
gtag('js', new Date());
17
18
gtag('config', 'UA-XXXXXXXX-3');
19
</script>
20
Advertisement
Answer
After testing the solution in my question, I can confirm that is the proper way to solve this:
JavaScript
1
20
20
1
<!-- Global site tag (gtag.js) 1 - Google Analytics -->
2
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
3
<script>
4
window.dataLayer = window.dataLayer || [];
5
function gtag(){dataLayer.push(arguments);}
6
gtag('js', new Date());
7
8
gtag('config', 'UA-XXXXXXXX-1');
9
</script>
10
11
<!-- Global site tag (gtag.js) 2 - Google Analytics -->
12
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-3"></script>
13
<script>
14
window.dataLayer = window.dataLayer || [];
15
function gtag(){dataLayer.push(arguments);}
16
gtag('js', new Date());
17
18
gtag('config', 'UA-XXXXXXXX-3');
19
</script>
20