Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics : _setvar to new tracking code

I have been using the older version of analytics code and used the following to track different types of users

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx");
pageTracker._setVar('memberlevel-2');    pageTracker._trackPageview();
} catch(err) {}</script>

How do I use this with the new asynchronous code? Google Analytics forums is dead and i got no response :(

like image 691
David Avatar asked Apr 08 '11 10:04

David


1 Answers

Try reading this for setting custom variable:

http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html

Sample code for to track page view:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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>
like image 195
ysrb Avatar answered Sep 29 '22 06:09

ysrb