Track Usergroups in Google Analytics

jonah

Регистрация
16.04.16
Сообщения
5
Симпатии
0
#1
Track your usergroups via the Google Analytics Custom Variables and Advanced Segments.

Replace the code in your google_analytics template with the following.

Код:
<xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}']);
  _gaq.push(['_setCustomVar',
      1,
      'Usergroup',
<xen:if is="{xen:helper ismemberof, $visitor, 1}">
      'Unregistered-1',
<xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
      'Registered-2',
<xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
      'Administrator-3',
<xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
      'Moderator-4',
</xen:if>
      1
]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</xen:if>
If you're not using the default primary usergroups, modify this section to fit your needs.
Код:
<xen:if is="{xen:helper ismemberof, $visitor, 1}">
      'Unregistered-1',
<xen:elseif is="{xen:helper ismemberof, $visitor, 2}" />
      'Registered-2',
<xen:elseif is="{xen:helper ismemberof, $visitor, 3}" />
      'Administrator-3',
<xen:elseif is="{xen:helper ismemberof, $visitor, 4}" />
      'Moderator-4',
</xen:if>
This will add a new Custom Variable called Usergroup, inside it it'll list the individual usergroups.
google.png
Use the Custom Variable (Value 01) dimension in the Advanced Segments section to target your usergroups. For example here I have two called "Logged In" and "Unregistered".
google_2.png
google3.png