Created
August 6, 2013 12:51
-
-
Save jcf/6164183 to your computer and use it in GitHub Desktop.
Mixpanel hacks
This file contains hidden or 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
module JavascriptTracking | |
def log_javascript_tracking | |
@mixpanel_registry ||= [] | |
page.execute_script <<-JS | |
window._eindx_cukes = { | |
originalTrack: mixpanel.track, | |
mixpanelRegistry: [] | |
}; | |
mixpanel.track = function() { | |
var args = Array.prototype.slice.apply(arguments); | |
_eindx_cukes.mixpanelRegistry.push(args); | |
_eindx_cukes.originalTrack.apply(this, args); | |
}; | |
JS | |
yield | |
@mixpanel_registry += page.evaluate_script <<-JS | |
window._eindx_cukes.mixpanelRegistry; | |
JS | |
rescue Capybara::NotSupportedByDriverError | |
puts 'You need to run a Javascript-capable driver! Tag your feature with @javascript.' | |
raise | |
end | |
end | |
World(JavascriptTracking) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment