Recently I had to write a Javascript redirect function that supports Google Analytics cross domain tracking. You find this function below.
The function below has a 5 second delay before it redirects. Change values in red according to your needs.
- <script type="text/javascript">
- _gaq.push(function() {
- var myRedirectURL = 'http://www.domain2.com/';
- var pageTracker = _gat._getTrackerByName();
- myRedirect = pageTracker._getLinkerUrl(myRedirectURL);
- setTimeout("document.location.replace(\myRedirect\);", 5000);
- });
- </script>
Also remember that you should normally add a regular link on that redirect page for those who have javascript turned off.
If you think the piece of code could be improved, feel fra to comment (I'm not a programmer). Happy Google Analytics cross domain tracking using Javascript redirect.