fastly-magento2
fastly-magento2 copied to clipboard
GeoIP redirect only works on first view
Steps to Replicate
- GeoIP Country Mapping is configured in admin to redirect traffic from country code to store A
- update VCL in fastly
- go to a different store (store B) in browser from configured country and get redirected to store A
- return to store B by entering url into browser
Expected Result
User is again redirected to store A
Actual Result
User stays on store B and is not redirected
Findings
If seems the probem is occuring in the ESI request to /fastlyCdn/geoip/getaction/. The code this outputs to redirect the browser would typically look something like this.
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"redirect": {
"component": "Fastly_Cdn/js/redirect",
"redirect_url": "https://www.example.co.nz/stores/store/switch/?___from_store=au&___store=nz"
}
}
}
}
}
</script>
When this is output correctly the redirect works. However when returning to store B the second time this request returns an empty 200 response meaning the redirect does not get triggered. I believe this can be traced back to the following VCL.
if (req.http.cookie:X-Magento-Vary || req.http.cookie:form_key) {
error 980 "GeoIP already processed";
} else {
# append parameter with country code only if it doesn't exist already
if ( req.url.qs !~ "country_code=" ) {
set req.url = querystring.set(req.url, "country_code", if ( req.http.geo_override, req.http.geo_override, client.geo.country_code));
}
}
After this redirect occurs store B has both X-Magento-Vary and form_key cookies set so further redirects will not happen until the users cookies are cleared.
I am not sure if this is intended behaviour or not but to me it makes sense that if the redirect is in place it would happen every time the customer visits the site, not just the first time.
This is the intended behavior as we do not want to be redirecting user over and over.
To clarify is this to stop redirect loops between stores or explicitly to stop them being redirected from a store on the second attempt to view?
It prevents us from popping up the redirect dialog on every page load.
Right so this is set up for the popup really, not the browser redirect? I think for the popup it makes sense. Personally I think for the browser redirect it makes more sense that the same behaviour happens every time the other site is visited, not just the first.
The popup triggers a redirect and the assumption is once the user has been using the site ie. by having a cookie that they have made a decision which country store to use. This is the reason why we avoid putting up again.
I'm not sure that it makes sense. I'd rather have a popup/redirect occur if the referrer is not from one of the other store views. The issue I'm having is that if someone posts a link in Facebook/Insta/blog to us.mysite.com and the user is from Europe, they get taken to eu.mysite.com. Which is good, and what I would want. But if they then hit back, and click a second link in Facebook to us.mysite.com, then they are not redirected a second time. That is very confusing behavior.
Hi, forcibly redirecting a customer to the store view mapped to his GEO location on EVERY visit is a feature we need, too. Does anyone know how to implement it without applying ugly workarounds or major module's core logic overrides?
this is the solution we came up with https://github.com/studioraz/fastly-magento2/commit/a87ac1049fcb51a31e7503f1d34f32deeb0f88a4 currently, we are applying it for our client's project as a composer I would love to here your opinion on how we can allow an admin user to control redirect strategy (force or one-time) by using a system configuration field (flag).