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

Geolocation-based dynamic redirection #1774

Closed
tostt opened this issue May 6, 2023 · 8 comments · Fixed by #2263
Closed

Geolocation-based dynamic redirection #1774

tostt opened this issue May 6, 2023 · 8 comments · Fixed by #2263
Labels
Milestone

Comments

@tostt
Copy link

tostt commented May 6, 2023

Summary

Since Shlink provides device-specific redirects, I am wondering if geo-specific redirects would also be within the scope of the application.

Say, for a product page you want customers to be redirected to the website that serves the country (or area) they live in.
For example, Amazon offers the "OneLink" geo-redirection service, but conditions apply.

@tostt tostt added the feature label May 6, 2023
@acelaya acelaya added the 🥇 gold I will implement these features when I reach my sponsorship goal https://github.com/sponsors/acelaya label May 23, 2023
@acelaya
Copy link
Member

acelaya commented May 23, 2023

There was a similar request recently, that I closed as "not planned". You can see the details #1735

I know you are not requesting exactly the same. Your reasoning makes a bit more sense, but I'm still hesitant due to the complexity to implement something like this.

  • During short URL creation/edition you would need to provide the target urls per location. But what is a location. A city? A country? A geofence? A timezone? It's so open that it would require very careful checks and would be very hard to validate.
  • What if this is combined with other rules, like device redirections. Which one applies? Or perhaps it should be combined?
  • It would require extra conditional checks. What if the GeoLite key was not provided? Should creation/edition fail and force you to provide only a long URL? Should it let it through but redirect to default long URL? What if it is removed after the URL is created?
  • What if geolocation is disabled but there are URLs that require it?
  • What if geolocation fails or cannot produce an accurate-enough result?
  • What if the GeoLite DB has not been downloaded yet? This is usually done in background, but if the redirect depends on it, the end user needs to wait until download finishes.

I'll leave this open, but due to the complexity, I'm going to tag it as a gold feature

@tostt
Copy link
Author

tostt commented May 24, 2023

Thank you for your answer and comments. Indeed, this can be a complex subject.
The way you describe all possible issues is definitely valid.

Another way to see things could be the following: if anything goes wrong, log the problem as a configuration warning and redirect to a default ("catch-all") URL. That's already the behaviour for device-specific redirects and, as a worst-case scenario, I think it's great. I believe that the most relevant way to geo-redirect is by country, but that's debatable.

I don't feel the app needs to cater for each and every thing which can go wrong. But of course, it's your project and your decisions. I hope you don't feel I'm making this a big deal. I am extremely satisfied the way the app is.

@acelaya
Copy link
Member

acelaya commented May 24, 2023

Thanks for the feedback.

I believe that the most relevant way to geo-redirect is by country, but that's debatable.

Yeah, my main concern is that any feature makes people ask for the next thing.

I could just decide it's going to be countries, but people will ask for cities, geofences, etc., etc.

Much like adding device-specific redirects is making people ask for geolocation redirects :P

@martyp187
Copy link

I got here by searching for this feature and found this.

This feature was something I was hoping for to make the use case for a sovereign self-hosted/owned solution vs the paid options.

I agree with Tostt. This feature, much like the 'devices' would be a 'best effort' improvement.

A user will end up at the 'normal url' unless a match to the country location is found / possible.

@acelaya
Copy link
Member

acelaya commented Mar 31, 2024

I'm thinking on removing the gold label from this issue, as this is now a bit easier to implement after the new dynamic rule-based redirects introduced in Shlink 4.0.0

Some of the points I mentioned in #1774 (comment) are still valid though, so I'm going to elaborate on them here.

  • During short URL creation/edition you would need to provide the target urls per location. But what is a location. A city? A country? A geofence? A timezone? It's so open that it would require very careful checks and would be very hard to validate.

Redirect rules and conditions should allow to cover this nicely. It would even be possible to add all of the above as different types of conditions.

The tricky part is validating the values though. If the condition is "City", what should be the value? It sadly requires to know the naming convention used by GeoLite2, and could potentially break if they change it, or if GeoLite2 is eventually replaced with something else.

  • What if this is combined with other rules, like device redirections. Which one applies? Or perhaps it should be combined?

This is covered by the dynamic rule-based redirects system, is it allows you to define priorities and combine conditions as desired. Scratching out.

  • It would require extra conditional checks. What if the GeoLite key was not provided? Should creation/edition fail and force you to provide only a long URL? Should it let it through but redirect to default long URL? What if it is removed after the URL is created?

Dynamic rule-based redirects define a general behavior here. During short URL creation/edition, Shlink would not check if the GeoLite2 key/database file is present, and just let the config go through.

During a visit, if the visitor could not be geolocated for whatever reason (missing key, missing GeoLite2 db, missing IP address, geolocation disabled, geolocation not precise enough, etc.), the rule would be considered not matched and that's it.

This is a bit controversial though, as it can be a slightly unintuitive behavior, making people report issues, and having to drive them over some kind of debugging process to verify if any of the situations mentioned above has happened.

  • What if geolocation is disabled but there are URLs that require it?
  • What if geolocation fails or cannot produce an accurate-enough result?
  • What if the GeoLite DB has not been downloaded yet? This is usually done in background, but if the redirect depends on it, the end user needs to wait until download finishes.

These three points are covered by the comment above.

@acelaya
Copy link
Member

acelaya commented Apr 20, 2024

For those interested in this, please vote/comment here #2101

@acelaya acelaya changed the title Geo-redirection Geolocation-based dynamic redirection May 13, 2024
@acelaya acelaya removed the 🥇 gold I will implement these features when I reach my sponsorship goal https://github.com/sponsors/acelaya label Jul 3, 2024
@acelaya acelaya added this to the 4.3.0 milestone Jul 3, 2024
@acelaya acelaya moved this to Todo in Shlink Oct 8, 2024
@acelaya
Copy link
Member

acelaya commented Nov 11, 2024

  • During short URL creation/edition you would need to provide the target urls per location. But what is a location. A city? A country? A geofence? A timezone? It's so open that it would require very careful checks and would be very hard to validate.

Redirect rules and conditions should allow to cover this nicely. It would even be possible to add all of the above as different types of conditions.

The tricky part is validating the values though. If the condition is "City", what should be the value? It sadly requires to know the naming convention used by GeoLite2, and could potentially break if they change it, or if GeoLite2 is eventually replaced with something else.

Since it's clear to me that this is gonna need different redirect conditions (for specific city, specific country, specific geofence, etc), I'm going to start with a country-code based one, where the match is done via the 2-letter ISO country code, which is non-controversial.

City names would be a bit more error-prone, and require some heuristics (expect the name in English, replace spaces with dashes, lowercase comparison, etc.)

@acelaya acelaya moved this from In Progress to In review in Shlink Nov 14, 2024
@github-project-automation github-project-automation bot moved this from In review to Done in Shlink Nov 14, 2024
@acelaya
Copy link
Member

acelaya commented Nov 14, 2024

This feature is now implemented. Shlink 4.3 will ship with two new dynamic redirection rules:

  • geolocation-country-code: Allows to perform redirections based on the ISO 3166-1 alpha-2 two-letter country code resolved while geolocating the visitor.
  • geolocation-city-name: Allows to perform redirections based on the city name resolved while geolocating the visitor.

It's worth mentioning that geolocation is not perfect. Sometimes the city or country cannot be resolved (more frequently the city), or they are incorrectly resolved, so it's important to have that limitation in mind when using these.

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

Successfully merging a pull request may close this issue.

3 participants