Javascript Redirect with Google Analytics

Note: _gaq.push allows pushing of functions onto the queue. The following code should redirect after 250 milliseconds (to allow time for the tracking pixel) after the _trackPageview:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1234567-8']);
_gaq.push(['_trackPageview']);
_gaq.push(function() {
    setTimeout(function() {
        window.location = "https://market.android.com/developer?pub=Fractal%20Systems";
    }, 250);
});

(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);
})();

Leave a Comment