Permalink
Browse files

Added a request-specific condition to restrict filtering in the scripts

  • Loading branch information...
1 parent 49a1029 commit 22f8f78879e816dad34cf30aacba016344af3a55 @ketzusaka committed Sep 14, 2012
Showing with 19 additions and 2 deletions.
  1. +2 −1 lib/mixpanel/tracker/middleware.rb
  2. +17 −1 spec/mixpanel/tracker/middleware_spec.rb
@@ -18,7 +18,7 @@ def call(env)
@env = env
@status, @headers, @response = @app.call(env)
-
+
if is_trackable_response?
merge_queue! if @options[:persist]
update_response!
@@ -71,6 +71,7 @@ def is_javascript_response?
def is_trackable_response?
return false if @status == 302
+ return false if @env.has_key?("HTTP_SKIP_MIXPANEL_MIDDLEWARE")
is_html_response? || is_javascript_response?
end
@@ -31,7 +31,23 @@ def check_for_default_appends_on(txt)
last_response.body.should == html_document
end
end
-
+
+ describe "Dummy app, handles skip requests properly" do
+ before do
+ setup_rack_application(DummyApp, {:body => html_document, :headers => {"Content-Type" => "text/html"}})
+ end
+
+ it "should not append mixpanel scripts with skip request" do
+ get "/", {}, {"HTTP_SKIP_MIXPANEL_MIDDLEWARE" => true}
+ Nokogiri::HTML(last_response.body).search('script').should be_empty
+ end
+
+ it "should append mixpanel scripts without skip request" do
+ get "/"
+ Nokogiri::HTML(last_response.body).search('script').size.should == 1
+ end
+ end
+
describe "Appending async mixpanel scripts" do
describe "With ajax requests" do
before do

0 comments on commit 22f8f78

Please sign in to comment.