Calling Google Analytics User Types

My task is to track registered and guest users on my site.

I am using GA code from this question .

The problem is that in the Custom Variables report I see incorrect information. For example, I have 700 unique visitors, but only 60 of them have a "user type".

Here is a screenshot: enter image description here

As I understand it, there should be 688 visits and 688 "User Type". What's wrong?

Here is my Jjano code:

<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS_KEY }}']); _gaq.push(['_setDomainName', '.site.com']); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); _gaq.push(['_setCustomVar', 1, 'User Type', {% if user.is_authenticated %}'Registered User'{% else %}'Guest'{% endif %}, 2 ]); (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> 

Thanks in advance.

+4
source share
2 answers

You need to set _setCustomVar before _trackPageview . Otherwise, the data of the user variable is not associated (i.e., it is sent in the __utm.gif tag and stored in cookies), and the custom variable is not monitored.

10% of visits that show user variables are most likely from pages that had other images (events, e-commerce, etc.) that carried user variable data. If you move _setCustomVar to _trackPageview (but after _setDomainName ), it should track 100%.

  var _gaq = _gaq || []; _gaq.push(['_setAccount', '{{ GOOGLE_ANALYTICS_KEY }}']); _gaq.push(['_setDomainName', '.site.com']); _gaq.push(['_setCustomVar', 1, 'User Type', {% if user.is_authenticated %}'Registered User'{% else %}'Guest'{% endif %}, 2 ]); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); 
+2
source

Are you sure that custom var is set on all pages that use this _setAccount value?

Maybe he was skipped in some section that will disable it?

Are you violating any of these restrictions for custom session level variables?

For any web resource, you can create as many different session levels as user variables that can be defined using a 64-byte key-value pair limit.

For any given user session, you can set up to 5 session levels variables.

0
source

Source: https://habr.com/ru/post/1384309/


All Articles