lib/mixpanel/middleware.rb in mixpanel-3.5.0 vs lib/mixpanel/middleware.rb in mixpanel-3.5.1

- old
+ new

@@ -5,10 +5,11 @@ class Middleware def initialize(app, mixpanel_token, options={}) @app = app @token = mixpanel_token @options = { + :insert_mixpanel_scripts=> true, :insert_js_last => false, :persist => false, :config => {} }.merge(options) end @@ -34,10 +35,12 @@ @response.each do |part| if is_regular_request? && is_html_response? insert_at = part.index(@options[:insert_js_last] ? '</body' : '</head') unless insert_at.nil? part.insert(insert_at, render_event_tracking_scripts) unless queue.empty? - part.insert(insert_at, render_mixpanel_scripts) #This will insert the mixpanel initialization code before the queue of tracking events. + if @options[:insert_mixpanel_scripts] + part.insert(insert_at, render_mixpanel_scripts) #This will insert the mixpanel initialization code before the queue of tracking events. + end end elsif is_turbolink_request? && is_html_response? part.insert(part.index('</body'), render_event_tracking_scripts) unless queue.empty? elsif is_ajax_request? && is_html_response? part.insert(0, render_event_tracking_scripts) unless queue.empty?