Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephanschubert/240111 to your computer and use it in GitHub Desktop.
Save stephanschubert/240111 to your computer and use it in GitHub Desktop.
Track your real bounce rate by triggering a custom no-bounce event with Google Analytics after a given timeout.
def google_analytics_real_bounce_rate_fix(timeout = 10)
name = "NoBounce"
msg = "Over #{timeout} seconds"
ms = timeout * 1000
<<-JS
function disqualifyAsBounce() {
pageTracker._trackEvent('#{name}', '#{name}', '#{msg}');
}
setTimeout("disqualifyAsBounce()", #{ms});
JS
end
# Usage:
# Output the method's return value RIGHT AFTER the call to '_trackPageView'.
# Example - Your JS has to look like this (variables may vary):
#
# <script type="text/javascript">
# try {
# var pageTracker = _gat._getTracker("UA-XXXXXXX-XX");
# pageTracker._trackPageview();
# function disqualifyAsBounce() {
# pageTracker._trackEvent('NoBounce', 'NoBounce', 'Over 10 seconds');
# }
# setTimeout("disqualifyAsBounce()", 10000);
#
# } catch(err) {}
# </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment