wdev-rs / laravel-analytics
Collect page view data in your application without third party tracking
Installs: 1 128
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 1
Forks: 1
Open Issues: 6
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- jaybizzle/crawler-detect: ^1.2
Requires (Dev)
- liip/rmt: ^1.7
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-05 21:47:14 UTC
README
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
Installation
You can install the package via composer:
composer require wdev-rs/laravel-analytics
Install the vue-chartjs integration
npm install vue-chartjs@^4.0.0 chart.js
Publish the vendor files by running
php artisan vendor:publish --provider="WdevRs\LaravelAnalytics\LaravelAnalyticsServiceProvider"
Usage
Run migration
php artisan migrate
Add alias to middleware in app/Http/Kernel.php
protected $routeMiddleware = [ ... 'analytics' => \WdevRs\LaravelAnalytics\Http\Middleware\Analytics::class, ... ];
Add the analytics
middleware to the routes you'd like to track
Route::middleware(['analytics'])->group(function () { Route::get('/', [PagesController::class,'index'])->name('pages.home'); });
Admin
Register the vue components to display analytics
Vue.component('page-views-per-days', require('./vendor/laravel-analytics/components/PageViewsPerDays.vue').default); Vue.component('page-views-per-paths', require('./vendor/laravel-analytics/components/PageViewsPerPaths.vue').default);
Use the components in your dashboard or where you like :)
Pass the data from controller
$pageViewRepository = app(PageViewRepository::class); $pageViewsPerDays = $pageViewRepository->getByDateGroupedByDays(Carbon::today()->subDays(28)); $pageViewsPerPaths = $pageViewRepository->getByDateGroupedByPath(Carbon::today()->subDays(28)); return view('admin.dashboard.index', [ 'pageViewsPerDays' => $pageViewsPerDays, 'pageViewsPerPaths' => $pageViewsPerPaths ]);
<page-views-per-days :initial-data="{{json_encode($pageViewsPerDays)}}"/> <page-views-per-paths :initial-data="{{json_encode($pageViewsPerPaths)}}"/>
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email daniel@wdev.rs instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.