Thursday, June 20, 2013

Tracking redirects with google analytics

I have tried to use php headers, but no success. Google analytics cant track page with php header location.

meta tag is not good way for me... so i found fastest redirector with javascript.

Here is code:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-******-*']);
_gaq.push(['_trackPageview']);
_gaq.push(function() {
      setTimeout(function() {
        window.location = "http://pilotaz.blogspot.com";
    }, 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);
})();
It is a simple google analytics script with window.location method in function. 

No comments:

Post a Comment