/url-tracker

Laravel URL Shortener and URL visit statistics/tracking package

Primary LanguagePHPMIT LicenseMIT

Laravel URL Tracker

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

If a user create short url, this package will track the url and store the data in database.

Installation

You can install the package via composer:

composer require kaantanis/url-tracker

You can publish and run the migrations and config with:

php artisan install:url-tracker

This is the contents of the published config file:

return [
    'prefix' => 'url-tracker', // example.com/url-tracker/QSGHG2
    'check-last-visit-minute' => 30 // check last 30 min same user visited this url. if not, increase view count
];

Usage

// Send post request to this url with tracked_url parameter
// example.com/url-tracker/generate-url (route name is url-tracker.generate-url)

Http::post(route('url-tracker.generate-url'), [
    'tracked_url' => 'https://google.com'
]);

// This return a string url path like this with a unique code
// example.com/url-tracker/QSGHG2

// If any visitor visit this url, user redirect to tracked_url
// and visitor data will be stored in database

Which data will be stored in database?

// main table
[
    'created_by' => auth()->id() ?? null,
    'url' => $request->tracked_url,
    'placeholder' => $uniqueCode
]

// and log table
[
    'url_tracker_table_id' => $urlFound->id,
    'ip_address' => request()->ip(),
    'user_agent' => request()->userAgent(),
    'referer' => request()->headers->get('referer'),
    'method' => request()->method(),
]

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.