prajwal89/lara-click-insights

There is no license information available for the latest version (v0.1.0) of this package.

Track impressions and clicks

v0.1.0 2024-05-11 06:06 UTC

This package is auto-updated.

Last update: 2024-05-11 06:23:17 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.