asbiin / laravel-plausible

A simple package to add plausible to Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Plausible

Latest Version on Packagist Total Downloads

This package provides a blade view with the script tag for plausible and a wrapper to easily send custom events to Plausible.

Installation

You can install the package via composer:

composer require vincentbean/laravel-plausible

You can publish the config file with:

php artisan vendor:publish --provider="VincentBean\LaravelPlausible\LaravelPlausibleServiceProvider" --tag="config"

Add the following to your env:

PLAUSIBLE_TRACKING_DOMAIN=DOMAIN_YOU_WANT_TO_TRACK
PLAUSIBLE_DOMAIN=OPTIONAL_IF_SELF_HOSTING

Usage

This package supports both client side and server side tracking.

Client Side Tracking

Include the view in your layout to include the plausible script.

@include('plausible::tracking')

Plausible will be available on the window object for sending custom events via Javascript:

plausible('event')

Server Side Tracking

Track pageviews server side using middleware.

// app/Http/Kernel.php
    'web' => [
        // Add this middleware to the web group to track globally
        \VincentBean\LaravelPlausible\Middleware\TrackPlausiblePageviews::class,
    ],

Custom Events

You can trigger custom events on the server.

\VincentBean\LaravelPlausible\PlausibleEvent::fire('custom event', ['country' => 'netherlands']);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A simple package to add plausible to Laravel

License:MIT License


Languages

Language:PHP 96.3%Language:Blade 3.7%