Skip to content

Instantly share code, notes, and snippets.

@jcf
Created August 6, 2013 12:51
Show Gist options
  • Save jcf/6164183 to your computer and use it in GitHub Desktop.
Save jcf/6164183 to your computer and use it in GitHub Desktop.
Mixpanel hacks
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