• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 Universal Analytics User-ID Tracking not working in XenForo?

Mike Fara

Active member
#1
Any idea what I'm doing wrong? I've tried every combination, which way to next Saturday, after adding this on the Google Analytics side. Basically, my google_analytics template is customized this way (yes I'm pushing it out 3 different times to no avail):

Code:
<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');

  <xen:if is="{$visitor.user_id}">ga('create', 'UA-XXXXX', 'userId': '{$visitor.user_id}');<xen:else />ga('create', 'UA-XXXXXX',  'auto');</xen:if>
  <xen:if is="{$visitor.user_id}">ga(‘set’, ‘&uid’, '{$visitor.user_id}');
  ga(‘set’, ‘userId’, '{$visitor.user_id}');</xen:if>
  ga('require', 'displayfeatures');
  ga('send', 'pageview');

</script>
Admittedly, Google's documentation on this is not good. I tried all 3 resulting combinations.

The output looks something like this

Code:
<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', 'XXXXXXXX', 'userId': '1');
ga(‘set’, ‘&uid’, '1');
ga(‘set’, ‘userId’, '1');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
And still no dice. Nothing as far as the user-ID segment in UA showing anything. Of course, multiple users are logged on, so even in real-time tracking, nothing shows. Hmm?
 

Mike Fara

Active member
#2
Solved:

For those who know what I'm talking about, you literally need brackets to appear in the HTML for this to work. Ex:

Code:
<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');

  <xen:if is="{$visitor.user_id}">ga('create', 'UA-XXX', {'userId': '{$visitor.user_id}'});<xen:else />ga('create', 'UA-XXX',  'auto');</xen:if>
  ga('require', 'displayfeatures');
  ga('send', 'pageview');

</script>
 

sip

Active member
#3
GA doesn't work for me too.
I added the Tracking-ID in XF in Google integration section but Google Analytics still shows not installed.