coderflexx / laravisit
A package to keep track of your pages & understand your audience
Fund package maintenance!
coderflex
Installs: 69 444
Dependents: 1
Suggesters: 0
Security: 0
Stars: 395
Watchers: 3
Forks: 23
Open Issues: 0
Requires
- php: ^8.1
- coderflexx/laravel-presenter: ^2.0
- illuminate/contracts: ^10.0|^11.0
- jaybizzle/crawler-detect: ^1.2
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^7.0|^8.0
- nunomaduro/larastan: ^1.0|^2.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^1.22|^2.34
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.0
README
A clean way to track your pages & understand your user's behavior
Installation
You can install the package via composer:
composer require coderflexx/laravisit
You can publish the config file with:
# linux php artisan vendor:publish --provider="Coderflex\\Laravisit\\LaravisitServiceProvider" # windows php artisan vendor:publish --provider="Coderflex\Laravisit\LaravisitServiceProvider"
then, run database migration
php artisan migrate
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | User Namespace |-------------------------------------------------------------------------- | | This value informs Laravisit which namespace you will be | selecting to get the user model instance | If this value equals to null, "\Coderflex\Laravisit\Models\User" will be used | by default. | */ 'user_namespace' => "\Coderflex\Laravisit\Models\User", ];
Usage
Use HasVisits
Trait
The first thing you need to do is, to use HasVisits
trait, and implement CanVisit
interface.
namespace App\Models\Post; use Coderflex\Laravisit\Concerns\CanVisit; use Coderflex\Laravisit\Concerns\HasVisits; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model implements CanVisit { ... use HasFactory; use HasVisits; ... }
After this step, you are all set, you can now count visits by using visit
method
$post->visit();
You can chain methods to the visit
method. Here are a list of the available methods:
By default, you will have unique visits each day using dailyInterval()
method. Meaning, when the users access the page multiple times in a day time frame, you will see just one record
related to them.
If you want to log users access to a page with different timeframes, here are a bunch of useful methods:
Get The Records With Popular Time Frames
After the visits get logged, you can retrieve the data by the following method:
Visit Presenter
This package is coming with helpful decorate model properties, and it uses Laravel Presenter package under the hood.
Testing
composer test
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.
Inspiration
Credits
License
The MIT License (MIT). Please see License File for more information.