lib/mixpanel/middleware.rb in mixpanel-4.0.3 vs lib/mixpanel/middleware.rb in mixpanel-4.0.4

- old
+ new

@@ -51,10 +51,11 @@ 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? + insert_at = part.index('</body') + part.insert(insert_at, render_event_tracking_scripts) unless insert_at.nil? or queue.empty? elsif is_ajax_request? && is_html_response? part.insert(0, render_event_tracking_scripts) unless queue.empty? elsif is_ajax_request? && is_javascript_response? part.insert(0, render_event_tracking_scripts(false)) unless queue.empty? end