My task is to track registered and guest users on my site.
I use GA code from this question.
Problem, that in Custom Variables report i see incorrect information. For example, I have 700 unique visitors, but only 60 of them with “user type”.
Here is the screenshoot:

As I understand there should be 688 visits and 688 “User Type” visits. What’s wrong?
Here is my Djano 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>
Thank you in advance.
You need to set your
_setCustomVarbefore your_trackPageview. Otherwise, the custom variable data doesn’t bind (ie, gets sent in the__utm.gifhit and stored in cookies), and custom variable isn’t tracked.The 10% of visits that are showing custom variables are likely from pages on which there were other hits (events, ecommerce, etc.) that did carry the custom variable data. If you move the
_setCustomVarto be before_trackPageview(but after_setDomainName), it should track 100%.