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

Different long URL based on device type. #1557

Closed
12 tasks done
snorkrat opened this issue Sep 28, 2022 · 10 comments · Fixed by #1668
Closed
12 tasks done

Different long URL based on device type. #1557

snorkrat opened this issue Sep 28, 2022 · 10 comments · Fixed by #1668
Labels
Milestone

Comments

@snorkrat
Copy link

snorkrat commented Sep 28, 2022

I would love it if we could specify different (long) URLS based on device type.
This would be super useful for setting up a short url to download an app. Shlink would detect the device the user visits from, redirect on android would go to the play store, and the redirect on iOS would go to the app store.
A 3rd URL could be added for any device that isn't iOS or android - which could go to a landing page. Perhaps this could even be built into Shlink. We could specify a message to be displayed if the user is visiting from an "unsupported" device. These settings could all be in the "advanced options".


Added by maintainer to track progress

  • Persistence of device long URLs.
  • Define API contract for read operations.
  • Define API contract for write operations (creation and edition).
  • Document API contract changes.
  • Allow "deleting"/"detaching" device URLs during edition, if explicitly provided with value null (or whatever is suitable).
  • Conditionally redirect to proper long URL, based on user agent.
  • Validate every device long URL if requested, during creation/edition. Not for now (https://twitter.com/shlinkio/status/1617113528162308097 and https://fosstodon.org/@shlinkio/109732478541676141)
  • API tests
    • Short URL creation
    • Short URL edition (including "detaching" device long URLs)
    • Redirect to proper place based on user agent (including fallback to regular long URL if impossible to match)
  • Document feature in website (Document device long URLs feature shlink.io#342)
@acelaya
Copy link
Member

acelaya commented Sep 28, 2022

This would definitely be something nice to have. I can think on many services which do something similar.

As a starting point, I would support "android", "ios", "desktop" and "default", leaving the door open to make it smarter in the future.

In order to support this, I would extend the short URL creation to allow something like this:

{
    "longUrl": {
        "android": "optional string",
        "ios": "optional string",
        "desktop": "optional string",
        "default": "required string",
    }
}

The only one required would be the default one, which would be the one used if the visitor is not identified as none of the other explicitly provided ones.

Current approach of { "longUrl": "whatever" } would continue working for backwards compatibility, and behave as if only default was provided.

Then redirects would also change. Shlink would try to identify the visitor and determine the proper redirect to use. This part is tricky, but there are promising libraries focused on this topic (like https://github.com/WhichBrowser/Parser-PHP).

Apart from this, the database would also need changes, validation would be affected, and a couple of other things, but in general, I think it's doable and useful.

@acelaya acelaya added this to the 3.4.0 milestone Sep 28, 2022
@snorkrat
Copy link
Author

Thanks for checking this out and putting it on the roadmap. I think it would definitely fit in with, and improve what Shlink has to offer. The only other (self-hosted) solution that I found that does this is Yourls. However the UI and workflow is not half as nice as Shlink. And the functionality is only added by way of a plugin so it's a bit fiddly and not very smooth.

The proposed solution is perfect, and your right; it leaves the door open to make it smarter in the future. Eg: you could have "Microsoft, Amazon, Apple (instead of iOS), etc"

Looking forward to seeing this implemented, and thanks for the hard work. Shlink is definitely the best self-hosted URL shortener that I've tried!

@ouquoi
Copy link

ouquoi commented Dec 4, 2022

This feature will be highly appreciate !
Thanks

@acelaya acelaya added this to Shlink Dec 4, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Dec 4, 2022
@acelaya acelaya moved this from Todo 🗒️ to In Progress 📝 in Shlink Dec 16, 2022
@acelaya acelaya moved this from In Progress 📝 to Todo 🗒️ in Shlink Dec 16, 2022
@acelaya acelaya removed the status in Shlink Dec 16, 2022
@acelaya acelaya modified the milestones: 3.4.0, 3.5.0 Dec 16, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Jan 2, 2023
@acelaya acelaya moved this from Todo 🗒️ to In Progress 📝 in Shlink Jan 3, 2023
@acelaya
Copy link
Member

acelaya commented Jan 3, 2023

I need to look for an alternative to https://github.com/WhichBrowser/Parser-PHP, as it is not compatible with PHP 8.2, and the PR to fix it that someone provided is stuck with no review, which makes me think the project is not very much maintained.

@acelaya
Copy link
Member

acelaya commented Jan 3, 2023

This one is better maintained, and more up to date https://github.com/serbanghita/Mobile-Detect

@acelaya
Copy link
Member

acelaya commented Jan 3, 2023

After some considerations, I have decided to implement this in a slightly different way.

When creating/editing the short URL, the request will look like this:

{
    "longUrl": "required string",
    "deviceLongUrls": {
        "android": "optional string",
        "ios": "optional string",
        "desktop": "optional string"
    }
}

being deviceLongUrls and everything inside of it completely optional.

The reasons are:

  • It's easier to model in a backwards compatible way, both at domain level and at persistence level.
  • The device long URLs will have to be exposed also in some endpoint (I haven't decided yet if there will be a new dedicated endpoint, or if I will include this in some existing one).

@acelaya acelaya moved this from In Progress 📝 to In review 👀 in Shlink Jan 22, 2023
@github-project-automation github-project-automation bot moved this from In review 👀 to Done ✅ in Shlink Jan 22, 2023
@acelaya
Copy link
Member

acelaya commented Jan 22, 2023

This feature is now implemented and will be released with Shlink 3.5.0

Right after, I will start working to integrate it in the next version of shlink-web-client.

@klinux
Copy link

klinux commented Mar 8, 2023

When do you think that this feature will be in the shlink-web-client?

Thank you.

@acelaya
Copy link
Member

acelaya commented Mar 14, 2023

Already implemented shlinkio/shlink-web-client#813

It will be released when this list is completed https://github.com/shlinkio/shlink-web-client/milestone/49

@acelaya
Copy link
Member

acelaya commented Mar 19, 2023

shlink-web-client 3.10 has just been released supporting this feature. It's already applied on https://app.shlink.io

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

Successfully merging a pull request may close this issue.

4 participants