SWFAddress and the new Google Analytics (ga.js)

I’m always playing a bit with SWFAddress, SWFObject and Google Analytics. SWFAddress has a nice features which is that it will advise Google Analytics when you change a page inside your main swf movie. That gives you the ability to do tracking on your website. Pretty neat!

Has some of you might know, Google Analytics has released a new tracker code (from urchin.js to ga.js). What more does it do for you right now? Not much, it’s supposed to be smaller in size and that’s about it. No event yet (there was a lot of buzz around events in Google Analytics and there is actually documentation on how to implement them but they are still in closed beta; we will have to wait on this one), no new functions. But if your launching a new website I would advise putting the new tracker code (ga.js) because it will save you maintenance time when you will want the new features.

So does SWFAddress works with the new code? Well the answer is yes, and it is pretty easy to make it work here is sample code showing you how to do it:

<script type=“text/javascript”>
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=“text/javascript”>
var pageTracker = _gat._getTracker(”UA-xxxxxx-xx”);
pageTracker._initData();
</script>
<script type=“text/javascript” src=“js/swfobject.js”></script>
<script type=“text/javascript” src=“js/swfaddress.js?tracker=pageTracker._trackPageview”></script>

The most important part of the code is the last line where you tell SWFAddress which tracker to use. That’s it! I hope this saves you some time.

9 Responses to “SWFAddress and the new Google Analytics (ga.js)”

  1. Gene Says:

    Quick question. Does the tracking code have to be above the two included javascript files for it to work or can I put the tracking code just above the tag like usual?

  2. Gene Says:

    Oops, it pulled out the body tag from my comment. It was supposed to be the closing body tag I was referring to.

  3. dgelineau Says:

    Yes the tracking code has to be over the two included javascript files. The reason for that is quite simple, look at the code to include the swf address javascript, it is a bit different than usual and it needs the Google Analytics tracker to be defined before in order to work.

  4. george Says:

    HI there i was wondering what version of SWFAddress are you using? 2.0? I cant seem to get it to work.
    so “pageTracker._trackPageview();” is taken out of the code that google recommends to use for ga.js?

    All this code goes before the closing ?

  5. george Says:

    sorry for kinda repeating the body tag question, but if, as google suggests, the tracker code goes before the closing body tag and then the swfobject + address follows that, that means your replacement content has to go before all this since it within the body no?

    Its causing my page to display its replacement content for a second then the swf is displayed afterwards.

    I guess you just go against what google says about the ordering?

  6. dgelineau Says:

    Yep I am using SWFAddress 2.0.

    I have put all the code that I pasted in the header of my HTML document. It is only a sugestion to put the tracker code before the body tag but you can put it where you want.

    Ya, you have to remove the “pageTracker._trackPageview();” from the recommended code from google, but you have to put it in the import statement of the SWFAddress javascript so that it knows to use the ga.js tracker.

    I thought I could just point you to the website I’m using it on so you could just view the source, but it is not online yet… I’ll post it when it is.

    I hope this help.

  7. estebanz Says:

    the parameter ?tracker=pageTracker._trackPageview seems to work fine on firefox but on IE, it’s very buggy
    I tried to call SWFAddress.setTracker(”pageTracker._trackPageview”); but it does not seems to be working (no call to __utm.gif on google’s server)
    Finnaly I redefine the urchinTracker function :
    function urchinTracker(u){
    pageTracker._trackPageview(u);
    }
    not very clean but it works !

  8. james Says:

    Has anyone else tried and verified that this works?

  9. Mark Kemper Says:

    I just used standard script include tags then set the function as below.

    var pageTracker = _gat._getTracker(”UA-31057-60″);
    pageTracker._initData();
    SWFAddress.setTracker(pageTracker._trackPageview);

    Seems to work just fine.

Leave a Reply


Close
E-mail It