13th
September
2013
How to Capture Google Analytics Before Redirect
Up until today, everyone I know has struggled to capture a Google Analytics event on redirect links. We’ve all had to come up with hacks and workarounds to ensure that the initial landing page is tracked. Today I finally figured out a solution that works. Google analytics now offers a callback event which lets you fire the redirect (or any custom functionality after the main tracking event fires.
The snippet to add after the Google analytics tracking code setup is below:
ga('send', 'pageview', { 'page': '/my-new-page', 'hitCallback': function() { window.location.replace = "[new url]"; } });