diff --git a/lib/first_click_free.rb b/lib/first_click_free.rb index 378b88f..4c58468 100644 --- a/lib/first_click_free.rb +++ b/lib/first_click_free.rb @@ -9,7 +9,7 @@ class << self require 'yaml' - attr_accessor :test_mode, :permitted_paths, :free_clicks + attr_accessor :test_mode, :permitted_paths, :free_clicks, :crawler_bot_strict_if def root File.expand_path(File.join(File.dirname(__FILE__), '..')) @@ -30,6 +30,10 @@ def free_clicks def test_mode @test_mode || false end + + def crawler_bot_strict_if + @crawler_bot_strict_if || false + end end class Railtie < Rails::Railtie diff --git a/lib/first_click_free/concerns/controller.rb b/lib/first_click_free/concerns/controller.rb index b297d8f..2c6bad8 100644 --- a/lib/first_click_free/concerns/controller.rb +++ b/lib/first_click_free/concerns/controller.rb @@ -61,7 +61,7 @@ def user_for_first_click_free # if this is the first click recorded for this session. def record_or_reject_first_click_free! # Always allow requests from Googlebot - return true if googlebot? + return true if googlebot? FirstClickFree.crawler_bot_strict_if # Always allow requests from authenticated users return true if user_for_first_click_free diff --git a/lib/first_click_free/helpers/google.rb b/lib/first_click_free/helpers/google.rb index 7c76db9..cb4dfa3 100644 --- a/lib/first_click_free/helpers/google.rb +++ b/lib/first_click_free/helpers/google.rb @@ -15,8 +15,9 @@ module Google # # Returns true if a Googlebot has been identified, false if not. def googlebot?(use_dns_lookup = true) + user_agent = request.user_agent || "" (FirstClickFree.test_mode && params.key?(:googlebot)) ||\ - (request.user_agent == "Googlebot" && (use_dns_lookup ? verify_googlebot_domain : true)) + (user_agent.include?("Googlebot") && (use_dns_lookup ? verify_googlebot_domain : true)) end private @@ -38,4 +39,4 @@ def verify_googlebot_domain end end -end \ No newline at end of file +end