Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics _setCustomVar - strange data in my dashboard

I have set up the _setCustomVar for my website, like this:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX']);
  _gaq.push(['_setDomainName', '.blog4ever.com']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_setCustomVar', 1, 'B4E_Type_Pub', 'Silver_ou_Gold', 3]);
  _gaq.push(['_setCustomVar', 2, 'B4E_Etat_Blog', 'normal', 3]);

  (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>

In my dashboard, when I go in: Visitors -> Custom variables, I see my 2 variables but the numbers are really strange (like 40 pages views although I have many thousands pages views).

I have it installed for 2 days now.

Did somebody face the same problem?

like image 276
Pascal Messana Avatar asked Dec 03 '22 09:12

Pascal Messana


1 Answers

You're lucky even 40 pageviews recorded these variables.

You need to call _setCustomVar before _trackPageview. Otherwise, the _trackPageview call sends the data to Google Analytics, and only after that are the custom variables set. If you set the _setCustomVar after the _trackPageview, the custom variable data doesn't attach, and if no other __utm.gif hits are set during that pageview, the data is basically gone forever.

(Those 40 pageviews that recorded probably were tracked via some other on-page GA calls that are sending data after the pageview loads).

like image 128
Yahel Avatar answered Jan 12 '23 00:01

Yahel