Shrinkr: Your Ultimate Laravel URL Shortener
Nasrul Hazim Bin Mohamad
Posted on October 19, 2024
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
Posted on October 19, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.