Managing and sharing long, cluttered URLs can be a hassle—this is where Shrinkr steps in. Shrinkr is an open-source Laravel package for shortening URLs, providing a simple yet powerful way to create short links with added functionality like click tracking, logging, analytics, and future support for branded domains, password protection, and QR codes. Whether you’re building a custom SaaS or just need a tool for personal projects, Shrinkr offers a solid foundation for your URL management needs.
Why Shrinkr?
Shrinkr goes beyond just shortening URLs. It offers built-in analytics to monitor link performance and flexible logging mechanisms for tracking user activity. With an easy-to-use API, Shrinkr ensures that developers can integrate it seamlessly into their existing Laravel applications.
GitHub Repository: Shrinkr on GitHub
Feature Discussions: Shrinkr Feature Ideas
Core Features
- Shorten URLs: Create short links with or without custom slugs.
- Click Analytics: Track visitor IPs, referrers, user agents, and devices.
- Flexible Logging: Log data to files or store logs in the database.
- Configurable API Support (Planned): Programmatically create and manage URLs.
- Branded Domains (Planned): Use custom domains to brand your links.
- Password-Protected URLs (Planned): Add a layer of security by restricting access.
- QR Codes (Planned): Generate and share QR codes for easier access on mobile devices.
- Link Health Monitoring (Planned): Ensure your links remain valid and notify users if they break.
- Event & Listeners (Planned): Decouple logic and handle tasks asynchronously with Laravel’s event system.
Getting Started with Shrinkr
Installation
Install the package via Composer:
composer require cleaniquecoders/shrinkr
Publish and run the migrations:
php artisan vendor:publish --tag="shrinkr-migrations"
php artisan migrate
Publish the config file:
php artisan vendor:publish --tag="shrinkr-config"
You can now customize your settings in the config/shrinkr.php
file.
How to Use Shrinkr
Shrinkr is easy to integrate into your Laravel application with the provided facade.
use CleaniqueCoders\Shrinkr\Facades\Shrinkr;
// Shorten a URL
$shortUrl = Shrinkr::shorten('https://example.com/long-url', auth()->id());
echo $shortUrl; // Outputs: https://yourdomain.com/abc123
// Retrieve the original URL
$originalUrl = Shrinkr::resolve('abc123');
echo $originalUrl; // Outputs: https://example.com/long-url
Logging and Analytics
Shrinkr captures detailed analytics during every redirect, including IP addresses, browsers, platforms, referrers, and query parameters. This data is stored in the redirect_logs
table or can be logged to a file, depending on your configuration.
Example database log entry:
url_id | ip | browser | platform | referrer | created_at |
---|---|---|---|---|---|
1 | 192.168.1.1 | Chrome | Windows | google.com | 2024-10-18 12:34:56 |
Configuring Logging
You can switch between logging to a file or database by changing the logger in config/shrinkr.php
:
'logger' => \CleaniqueCoders\Shrinkr\Actions\Logger\LogToFile::class, // Default
Or use database logging:
'logger' => \CleaniqueCoders\Shrinkr\Actions\Logger\LogToDatabase::class,
Future Roadmap: What’s Coming Next?
We have several exciting features planned to enhance Shrinkr:
- Rate Limiting: Prevent abuse by limiting requests to the API.
- Protected URLs: Add password protection to sensitive links.
- QR Code Support: Generate QR codes for mobile sharing.
- Link Health Monitoring: Automatically detect and notify users of broken URLs.
- Events & Listeners: Handle tasks asynchronously, such as sending notifications when a link is accessed.
For more discussions on upcoming features, visit the Shrinkr GitHub Discussions.
Conclusion: Build Smarter with Shrinkr
Shrinkr isn’t just a URL shortener—it’s a powerful tool that helps you manage and analyze your links with precision. Whether you need basic URL shortening, advanced analytics, or custom branded links, Shrinkr has got you covered.
Explore the project on GitHub: Shrinkr Repository.
Join the conversation: Future Feature Discussions.
Get started today and take control of your links with Shrinkr! 🚀
Photo by Campaign Creators on Unsplash
Top comments (5)
🚀 New in Shrinkr v1.0.3: Customizable middleware for routes (default
['throttle:60,1']
), support for custom domains, and enhanced code compliance with PHPStan Level 9. 🎉🔗 Full details: Shrinkr v1.0.3 Release Notes - github.com/cleaniquecoders/shrinkr...
Update on v1.0.1 - Adding Event & Expiry - github.com/cleaniquecoders/shrinkr...
Update on v1.0.2 - Adding Health Check - github.com/cleaniquecoders/shrinkr...
Full disclosure: I'm not a fan of link shorteners for any purpose.
That over with, I'm curious about the password protection you mention. If the password protection prevents the end user from being redirected to the destination URL, but the destination itself isn't password-protected, then isn't this security by obscurity but with extra steps?
The "Link Health Monitoring" feature is a good idea, but since you're adding an intermediary, you're adding another point of failure anyway. If your shortener glitches or goes away, people who only have the short version saved can't get to the real URL.
Analytics will also depend on how the redirect works. If it's a permanent redirect, then you won't be able to track repeat visitors. Even if it's a temporary redirect, then whether a hit gets registered depends whether the repeat visitor returns from a bookmark or by using their browser history. It's these extra layers of "maybe" that make analytics end up looking like the Drake equation!
Thanks so much for the thoughtful feedback! 🙌 I really appreciate you taking the time to share your concerns—it’s exactly this kind of input that helps us make Shrinkr better.
On Password Protection: "Security by Obscurity?"
You make a really good point. If the destination URL isn’t password-protected, putting a password on the shortener might feel like just an extra hurdle. But, in some cases, it can still be useful! For example, say you’re sharing a temporary link on a public platform, or you want to share something sensitive but only with a select few—it gives you a bit more control without having to tinker with the original content’s settings.
That said, you're absolutely right: it’s not a replacement for real security. The idea is to use it where quick access control makes sense, like event invites or private media links. We’ll definitely make sure we communicate that better to manage expectations!
On Link Health Monitoring: "Another Point of Failure?"
Absolutely valid concern. If the shortener itself goes down, it’s a problem. 😅 And yeah, that’s the trade-off of adding a middle layer—it’s a double-edged sword. But the monitoring feature helps catch those broken destination links before users start complaining about them.
We’re thinking of building in redundancy (like backups or failover systems) to keep the shortener running smoothly. Also, we’ll likely introduce an export feature so users can always access their original URLs, even if the shortener goes offline. It’s all about minimizing risks without giving up the convenience of having the shortener in the first place!
On Analytics: "Is This the Drake Equation?" 😂
Haha, I love that analogy! You’re absolutely right—analytics with URL shorteners can feel more like detective work than science. Depending on how the visitor interacts with the link (e.g., via bookmarks, browser history, or direct clicks), it can be hard to get accurate counts.
To make things more reliable, we’ll probably lean on temporary redirects (302) rather than permanent ones (301) since they give us a better shot at tracking return visitors. We’ll also explore adding UTM tracking so users can see more detailed reports. And while cookies or session tracking could improve things, we want to be careful not to step on privacy concerns. It’s a balancing act, for sure!
In Closing
Thanks again for sharing your thoughts! I totally get your points, and I’ll make sure the team keeps these in mind as we keep building Shrinkr. It’s feedback like this that helps us improve—not just to add features but to build something that makes sense and solves real problems.
If you have more thoughts or ideas, I’d love to hear them! Feel free to jump into the discussion here: Shrinkr Feature Ideas. Let’s keep the conversation going and make Shrinkr even better! 🚀