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

Posted on 2011-10-11
Last Modified: 2012-05-12
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

Question by:Oliver2000

    Accepted Solution

    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.

    Author Closing Comment

    I fixed it myself!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Zoom web page in 2 21
    Amazon Product image url. 12 28
    jQuery-Validation-Engine with steps 13 33
    Import csv files to MS SQL 5 38
    Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
    Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now