Created
November 21, 2009 12:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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