Search code examples
ruby-on-railsrubyrubygemsahoy

Ahoy gem, how to not save ahoy.track record into DB when page is reloaded?


I want to count how many views my page has received. So, I try to use the Ahoy gem and add the following line into my action:

https://github.com/ankane/ahoy#ruby

Then it records when a visitor views that action, but it also records every time the action has been called, even when user reloads the page.

What I want is: if this is that the user's first visit we record it. But if they just reload page or they re-visit that page in a short amount of time, we will not save ahoy.track into our DB.

So, do anyone have a solution for this?


Solution

  • try in your view :

    <% ahoy.track_visit unless current_visit %>