Sha256: dc9b6dd178a4bd1dd27acab8adfb1b0e02c932adef05b52b5f8499e07ce28bc4

Contents?: true

Size: 1.5 KB

Versions: 44

Compression:

Stored size: 1.5 KB

Contents

module Analytical
  module BotDetector

    def analytical_is_robot?(user_agent)
      unless user_agent.blank?
        user_agent = user_agent.to_s.downcase

        # We mark something as a bot if it contains any of the $bot_indicators
        # or if it does not contain one of the $browser_indicators. In addition,
        # if the user-agent string contains "mozilla" we make sure it has version
        # information. Finally anything that starts with a word in the $whitelist
        # is never considered a bot.

        whitelist = %w(w3m dillo links elinks lynx)
        whitelist.each do |word|
          return false if user_agent.index(word) == 0
        end

        bot_indicators = %w(bot spider search jeeves crawl seek heritrix slurp thumbnails capture ferret webinator scan retriever accelerator upload digg extractor grub scrub)
        bot_indicators.each do |word|
          return true if user_agent.index word
        end

        browser_indicators = %w(mozilla browser iphone lynx mobile opera icab)
        has_browser_indicator = false

        browser_indicators.each do |word|
          if user_agent.index word
            has_browser_indicator = true
            break
          end
        end

        return true if not has_browser_indicator

        # Check for mozilla version information
        if user_agent.include? "mozilla"
          return true if not user_agent.include? "("
          return true if user_agent !~ /mozilla\/\d+/i
        end
      end
      return false
    end

  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
analytical-3.0.12 lib/analytical/bot_detector.rb
analytical-3.0.11 lib/analytical/bot_detector.rb
analytical-3.0.9 lib/analytical/bot_detector.rb
analytical-3.0.8 lib/analytical/bot_detector.rb
analytical-3.0.7 lib/analytical/bot_detector.rb
analytical-3.0.6 lib/analytical/bot_detector.rb
gsiener-analytical-2.10.2 lib/analytical/bot_detector.rb
gsiener-analytical-2.10.1 lib/analytical/bot_detector.rb
analytical-2.11.0 lib/analytical/bot_detector.rb
analytical-2.10.0 lib/analytical/bot_detector.rb
gsiener-analytical-2.10.0 lib/analytical/bot_detector.rb
analytical-2.9.0 lib/analytical/bot_detector.rb
analytical-2.8.0 lib/analytical/bot_detector.rb
analytical-2.7.2 lib/analytical/bot_detector.rb
analytical-2.7.1 lib/analytical/bot_detector.rb
analytical-2.7.0 lib/analytical/bot_detector.rb
analytical-2.6.0 lib/analytical/bot_detector.rb
analytical-2.5.0 lib/analytical/bot_detector.rb
analytical-2.4.0 lib/analytical/bot_detector.rb
analytical-2.3.0 lib/analytical/bot_detector.rb