2

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?

2 Answers2

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.

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