lancodev/laravel-analytics is a Laravel package for laravel analytics.
It currently has 2 GitHub stars and 18 downloads on Packagist (latest version 0.7).
Install it with composer require lancodev/laravel-analytics.
Discover more Laravel packages by lancodev
or browse all Laravel packages to compare alternatives.
Last updated
This package provides a simple way to capture site analytics within your existing Laravel application.
Install the package via composer:
composer require lancodev/laravel-analytics
Publish the components and views:
php artisan vendor:publish --tag="laravel-analytics-components"
php artisan vendor:publish --tag="analytics-views"
Run the package's install command:
php artisan analytics:install
The package provides an optional Trackable trait that can be used to assign page view analytics to a model. The trait provides a pageViews relationship that can be used to retrieve the page views for the model.
This would typically be implemented by the User model. However, it could also be implemented by any other model that you wish to track page views for.
To use the trait, simply add the following to your model:
namespace App\Models;
use Lancodev\LaravelAnalytics\Traits\Trackable;
class User
{
use Trackable;
}
To begin tracking analytics, add the <x-analytics-analytics /> component to your layout file(s).
This will add the necessary JavaScript to your application.
<html>
<head>
<title>My Application</title>
</head>
<body>
``` content ```
<x-analytics-analytics />
</body>
</html>
The <x-analytics-analytics /> component accepts the following props:
<x-analytics-analytics :trackable="auth()->user()" />The package also provides a simple dashboard component that can be used to display analytics for your application.
The dashboard can be added to any view by adding the following:
<x-analytics-dashboard />
This will add the following to your page:

composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.