prajwal89 / lara-click-insights
Track impressions and clicks
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.21
This package is auto-updated.
Last update: 2025-04-14 15:30:26 UTC
README
Record impressions and clicks of any model with Lara Click Insights
Installation
- Install the package via composer:
composer require prajwal89/lara-click-insights
- Publish frontend assets:
php artisan vendor:publish --tag=lara-click-insights-assets
- Publish Database migrations:
php artisan vendor:publish --tag=lara-click-insights-migrations
- Publish Database config (optional):
php artisan vendor:publish --tag=lara-click-insights-config
Alternatively, you can publish all of the above with the following command:
php artisan vendor:publish
When prompted, select Prajwal89\LaraClickInsights\LaraClickInsightsProvider.
In your HTML <head>
tag, add the following directive and meta tag:
<html> <head> <meta name="csrf-token" content="{{ csrf_token() }}"> ... @LaraClickInsightsJs </head>
Do not forget to run php artisan migrate
Usage
The Eloquent models you want to track impressions for should use the Prajwal89\LaraClickInsights\Traits\ImpressionTrackable
trait.
namespace App; use Prajwal89\LaraClickInsights\Traits\ImpressionTrackable; use Illuminate\Database\Eloquent\Model; class YourEloquentModel extends Model { use ImpressionTrackable; ... }
The trait contains an abstract method trackingAttribute()
that you must implement yourself on your frontend. this should look something like this
<!-- cards that you want to track --> @foreach($yourEloquentModels as $yourEloquentModel) <a href="/xyz" {!! $yourEloquentModel->trackingAttribute() !!}> <!-- card content --> </a> @foreach
this will add data attribute for identifying the clickable link like data-clickable="yourEloquentModels:23:default"
do not forget to use {!! !!}
License
The MIT License (MIT). Please see License File for more information.