Ahoy on Rails — is it supposed to track automatically?

Jamie A. Source

I've set up Ahoy in Rails 5.1.5 but it doesn't track visits automatically.

From https://github.com/ankane/ahoy:

Add this line to your application’s Gemfile:
gem 'ahoy_matey'

And run:
bundle install
rails generate ahoy:install
rails db:migrate

Restart your web server, open a page in your browser, and a visit will be created 🎉

I interpret that last line as: An entry will automatically appear in Ahoy::Visit.last when there's a new visit. Unfortunately, there were no rows in this table after a pageview. So I did this in application_controller.rb:

after_action :ahoy_track


def ahoy_track
  properties = request.path_parameters
  properties[:url] = request.url
  ahoy.track "Pageload", properties

and now I'm getting visitor data. However, when someone comes from Google, Ahoy::Visit.last.search_keyword is nil.

Are these two problems related? What gives? This is deployed to Heroku on a plain vanilla PostgreSQL setup.



comments powered by Disqus