Usergroup tracking in Google Analytics

Dakis

Well-known member
We've been trying to figure out a solution to track guests VS members in google analytics (and potentially more usergroups afte that). This is what we've tried:

1- Removed the GA property id from the xenforo option

2- Added this code in the header instead (replacing UA-GA-PROPERTY-ID with our website's actual id):

Code:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-GA-PROPERTY-ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
 
gtag('config', 'UA-GA-PROPERTY-ID', {
    'custom_map': {'dimension1': 'user_state'}
});
gtag('event', 'user_state_event', {'user_state': '{{ $xf.visitor.user_id ? 'registered' : 'guest' }}'});

</script>

3- Created a custom dimension in Google Analytics (for example called "Visitor Type") with the scope "session"


4- Created 2 new segments, each with a condition to filter sessions based on "Visitor Type" containing the words "guest" or "registered"


And it works fine, except one thing: the bounce rate drops to 0%, which means that there must be something wrong with this code somewhere, as there is no doubling up of the GA code anywhere else.

A couple of us have been banging our heads against the wall for a few days, anyone can shed any light on how to do this properly using Google Analytics?



1595199141995.webp
 
Top Bottom