ruby-on-railsahoy

Rails Ahoy new visits not being created


Using Ahoy for Rails app. Existing visits do not seem to be expiring -- events are attached to visits that are 2, 3, or more days old (rather than to a new visit).

For example, here's a visit from production, from Apr 7:

<Ahoy::Visit id: 336, visit_token: "XXXXXXX", visitor_token: "XXXXXXX", user_id: 27, ip: "XXXXXXX", user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) Ap...", referrer: nil, referring_domain: nil, landing_page: "XXXXXX", browser: "Chrome", os: "Mac", device_type: "Desktop", country: nil, region: nil, city: nil, latitude: nil, longitude: nil, utm_source: nil, utm_medium: nil, utm_term: nil, utm_content: nil, utm_campaign: nil, started_at: "2020-04-07 15:22:02"

And here are the first two events associated with that visit:

[#<Ahoy::Event id: 7398, visit_id: 336, user_id: 27, name: "Page visit", properties: {"path"=>"XXXXX", "slug"=>"XXXXX"}, time: "2020-04-21 15:53:11">, #<Ahoy::Event id: 7397, visit_id: 336, user_id: 27, name: "Page visit", properties: {"path"=>"XXXXX", "slug"=>"XXXXX"}, time: "2020-04-21 15:53:03">]

I have Ahoy.visit_duration = 30.minutes set in config/initializers/ahoy.rb. Here's the entire config/initializers/ahoy.rb file:

class Ahoy::Store < Ahoy::DatabaseStore
end

Ahoy.api = false
Ahoy.mask_ips = true
Ahoy.cookies = false
Ahoy.visit_duration = 30.minutes

The Ahoy::Visit model:

class Ahoy::Visit < ActiveRecord::Base

  self.table_name = "ahoy_visits"
  has_many :events, class_name: "Ahoy::Event"
  belongs_to :user, optional: true

end

Thanks for any suggestions.


Solution

  • The Ahoy.visit_duration is used when creating cookies.

    Since you are setting Ahoy.cookie = false, a visit would be the same, as long the UserAgent and RemoteIP are the same.

    That is the part of Anonymity Sets & Cookies