ankane / ahoy

Simple, powerful, first-party analytics for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Visit tokens and anonymity sets

Obversity opened this issue · comments

Hi there!

Context: we started using anonymity sets recently, and put validates :visit_token, uniqueness: { allow_blank: true } in our Ahoy::Visit model a while back and have been seeing Validation failed: Visit token has already been taken errors every few hours.

Question: When using anonymity set settings, should it be possible for there to be multiple visit records with the same visitor_token — e.g. when their masked IP and user agent happens to be the same?

What should happen when two of these requests come through at exactly the same time, given that there's a unique constraint on visitor_token in the database?

Hey @Obversity, you'll want to remove the uniqueness validation. Ahoy already has code to handle errors from unique constraints.