I am integrating keen.io with a Rails 3.2 app. Everything works great except e.g. of 500 pageviews recorded, 400 are from Google an other engines crawling the site. Especially since we will be paying by the event, I am trying to prevent Keen from recording these non-user events. Is there an easy way to check for the user agent before recording an event?
Asked
Active
Viewed 239 times
2 Answers
1
I ended up doing the following in the controller:
bots = /googlebot|bingbot|CCBot|008|ABACHOBot|Accoona-AI-Agent|AddSugarSpiderBot|Arachmo|B-l-i-t-z-B-O-T|...|ZyBorg/ unless request.env["HTTP_USER_AGENT"].downcase.match(bots) if user_signed_in? @user = current_user Keen.publish...
Not sure if that is the best way, but it seems to be working to show events from real users.

Darius Goore
- 43
- 5
1
Sounds like a reasonable solution to me.
If you were looking to implement this behavior globally that as a Rack middleware you could consider a gem like fnando/browser. At a glance it appears to have bot detection capabilities as well as an included middleware.

Josh Dzielak
- 1,803
- 17
- 19
-
1Thanks Josh. I will check out the gem. I am somewhat shocked that no one seems to have dealt with this. We are using Keen to build a dashboard for our clients, but if we can't exclude the bots effectively, the data is not that helpful. – Darius Goore Jan 05 '15 at 23:53
-
1This gem seems to be working perfectly. Thanks Josh! – Darius Goore Jan 07 '15 at 04:34
-
Great to hear Darius! – Josh Dzielak Jan 16 '15 at 17:54