Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoIP redirect only works on first view #352

Open
andrewkett opened this issue Apr 1, 2020 · 9 comments
Open

GeoIP redirect only works on first view #352

andrewkett opened this issue Apr 1, 2020 · 9 comments

Comments

@andrewkett
Copy link
Contributor

andrewkett commented Apr 1, 2020

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.

@andrewkett
Copy link
Contributor Author

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.

@vvuksan
Copy link
Contributor

vvuksan commented Apr 1, 2020

This is the intended behavior as we do not want to be redirecting user over and over.

@andrewkett
Copy link
Contributor Author

andrewkett commented Apr 1, 2020

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?

@vvuksan
Copy link
Contributor

vvuksan commented Apr 2, 2020

It prevents us from popping up the redirect dialog on every page load.

@andrewkett
Copy link
Contributor Author

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.

@vvuksan
Copy link
Contributor

vvuksan commented Apr 14, 2020

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.

@AndrewPenry
Copy link

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.

@itaymesh
Copy link

itaymesh commented Jan 20, 2024

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?

@itaymesh
Copy link

this is the solution we came up with studioraz@a87ac10
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants