You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with a fairly old version of Ahoy in my project, but the bit of code I'm wrestling with is still present in master.
The following is from tracker.rb on master. See comment just inside the if defer conditional block.
deftrack_visit(defer: false,started_at: nil)ifexclude?debug"Visit excluded"elseifdefer# Why is this 4th argument (Which set_cookie defines as use_domain) false here?set_cookie("ahoy_track",true,nil,false)elsedelete_cookie("ahoy_track")data={visit_token: visit_token,visitor_token: visitor_token,user_id: user.try(:id),started_at: trusted_time(started_at),}.merge(visit_properties).select{ |_,v| v}@store.track_visit(data)Ahoy::GeocodeV2Job.perform_later(visit_token,data[:ip])ifAhoy.geocode && data[:ip]endendtruerescue=>ereport_exception(e)end
This false on use_domain stops Ahoy's JS from attempting to hit the /visits endpoint, which would persist the Visit in my store.
Example, I have a route that is on www but then redirects the visitor to some subdomain. I'm trying to work with the scenario where the visitor to my www URL has never been to our site before and thus, has no ahoy_visit and ahoy_visitor cookies set.
When the visitor hits the www route, Ahoy::Controller calls set_ahoy_cookies to set my visit and visitor IDs. It sets those cookies respecting Ahoy.cookie_domain = :all setting in my configuration. The ahoy_track cookie however, is created via set_cookie with use_domain set to false. This means that cookie is set specifically to my www domain and cannot be read by the subdomain where I will ultimately redirect the visitor.
The end result, is when the user lands on my subdomain, they have the following cookies:
ahoy_visit: XXXX-XXXX (Domain .mydomain.com)
ahoy_visitor: XXXX-XXXX (Domain .mydomain.com)
ahoy_track: true (Domain www.mydomain.com) *The troubled one
Because the JS firing on the now subdomain can't read the ahoy_track cookie, it never makes an attempt to hit /visits and actually persist the Visit.
Is this intentional?
Doesn't it seem like if Ahoy.cookie_domain = :all the ahoy_track cookie should also respect that policy and allow this cookie to be read cross domain?
This seems intentional and has persisted many versions, so I want to get a sense of whether or not I'd be getting into trouble submitting a PR to alter this behavior.
Thank you!
The text was updated successfully, but these errors were encountered:
Hi there,
I'm working with a fairly old version of Ahoy in my project, but the bit of code I'm wrestling with is still present in
master
.The following is from
tracker.rb
onmaster
. See comment just inside theif defer
conditional block.This
false
onuse_domain
stops Ahoy's JS from attempting to hit the /visits endpoint, which would persist theVisit
in my store.Example, I have a route that is on
www
but then redirects the visitor to some subdomain. I'm trying to work with the scenario where the visitor to mywww
URL has never been to our site before and thus, has noahoy_visit
andahoy_visitor
cookies set.When the visitor hits the
www
route,Ahoy::Controller
callsset_ahoy_cookies
to set my visit and visitor IDs. It sets those cookies respectingAhoy.cookie_domain = :all
setting in my configuration. Theahoy_track
cookie however, is created viaset_cookie
withuse_domain
set tofalse
. This means that cookie is set specifically to mywww
domain and cannot be read by the subdomain where I will ultimately redirect the visitor.The end result, is when the user lands on my subdomain, they have the following cookies:
ahoy_visit
:XXXX-XXXX
(Domain.mydomain.com
)ahoy_visitor
:XXXX-XXXX
(Domain.mydomain.com
)ahoy_track
:true
(Domainwww.mydomain.com
) *The troubled oneBecause the JS firing on the now subdomain can't read the
ahoy_track
cookie, it never makes an attempt to hit /visits and actually persist theVisit
.Is this intentional?
Doesn't it seem like if
Ahoy.cookie_domain = :all
theahoy_track
cookie should also respect that policy and allow this cookie to be read cross domain?This seems intentional and has persisted many versions, so I want to get a sense of whether or not I'd be getting into trouble submitting a PR to alter this behavior.
Thank you!
The text was updated successfully, but these errors were encountered: