Need help to convert old google analytics script into new async version

Hi experts,

I need some help to convert my old google analytics tracking code into new async version. I think so far I get it work but I have some doubts because of the eventracking and custom variables I used before.

Maybe somebody help help convert the old version into the new version for me. Below is my original old analytics code.

As click events I use in the moment:
<a onclick="ZuraTracker._trackEvent('Menulink','Index',1)">LOJA</a>

Thank you in advance for your help,

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXXX-1");

pageTracker._setCustomVar(1, "Usertype", "Logged_In", 1);


//event tracker
var ToolTracker         = pageTracker._createEventTracker("Tools");
var MadeHomepageTracker = pageTracker._createEventTracker("Made Homepage");
var MadeFavoriteTracker = pageTracker._createEventTracker("Made Favorite");
var AlbumTracker        = pageTracker._createEventTracker("Go to Album");
var ZuraTracker         = pageTracker._createEventTracker("Zura");

Open in new window

Who is Participating?
Oliver2000Author Commented:
This is what I got so far but I am not sure if this is correct.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
      1,                   // This custom var is set to slot #1.  Required parameter.
      'Usertype',          // The name acts as a kind of category for the user activity.  Required parameter.
      'Logged_In',         // This value of the custom variable.  Required parameter.
      1                    // Sets the scope to session-level.  Optional parameter.

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


Open in new window

I guess I made so far everything correct and also the custom variable (Usertype) should hopefully work like this.

Remains my big doubt about the click events I used to track. In the old version I used for example:
var ToolTracker         = pageTracker._createEventTracker("Tools");

but as far as I read so far I dont really need this in my new async version and I can just use the new onclick syntax. Is this correct???

This means my onclick would look liks this now:

<a onclick="_gaq.push(['_trackEvent', 'Menulink', 'Index']);">click me</a>

Would be nice if somebody can help me out with this. I want to avoid loosing track or stats in my analytics and want to have the code working before I test it wrong.

thank you in advance for your help.
Oliver2000Author Commented:
I fixed it myself!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.