[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

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,
Oliver

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

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

pageTracker._trackPageview();

//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");
</script>

Open in new window

0
Oliver2000
Asked:
Oliver2000
  • 2
1 Solution
 
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']);
  _gaq.push(['_setCustomVar',
      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.
   ]);
  _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>

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.
0
 
Oliver2000Author Commented:
I fixed it myself!
0

Featured Post

Eye-catchers on the conference table

Challenge: The i-unit group was not satisfied with the audio quality during remote meetings. They were looking for a portable solution with excellent audio quality for use in their conference room but also at their client’s offices.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now