Added option to track bots
Andrew Kane
committed May 14, 2014
commit 386e7f3e2916704e196f8740dc4897410f19b8d5
Showing 4
changed files with
13 additions
and 2 deletions
README.md
+6
-0
| @@ | @@ -367,6 +367,12 @@ Use a different model for events |
| Ahoy.subscribers << Ahoy::Subscribers::ActiveRecord.new(model: Event) | |
| ``` | |
| + | Track bots |
| + | |
| + | ```ruby |
| + | Ahoy.track_bots = true |
| + | ``` |
| + | |
| ## Upgrading | |
| In `0.1.6`, a big improvement was made to `browser` and `os`. Update existing visits with: | |
app/controllers/ahoy/base_controller.rb
+1
-1
| @@ | @@ -12,7 +12,7 @@ module Ahoy |
| end | |
| def halt_bots | |
| - | if browser.bot? |
| + | if Ahoy.track_bots and browser.bot? |
| render json: {} | |
| end | |
| end | |
ahoy/model.rb b/lib/ahoy/model.rb
+3
-1
| @@ | @@ -36,7 +36,9 @@ module Ahoy |
| browser = Browser.new(ua: user_agent) | |
| self.device_type = | |
| - | if browser.tv? |
| + | if browser.bot? |
| + | "Bot" |
| + | elsif browser.tv? |
| "TV" | |
| elsif browser.console? | |
| "Console" | |
ahoy_matey.rb b/lib/ahoy_matey.rb
+3
-0
| @@ | @@ -48,6 +48,9 @@ module Ahoy |
| mattr_accessor :subscribers | |
| self.subscribers = [] | |
| + | |
| + | mattr_accessor :track_bots |
| + | self.track_bots = false |
| end | |
| ActionController::Base.send :include, Ahoy::Controller | |