marekzelezny / plausible
Simple package for managing Plausible with PHP
Requires
- php: ^8.0
- illuminate/support: ^8.24|^9.0|^10.0
- illuminate/view: ^8.24|^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.10
- orchestra/testbench: ^6.23|^7.0|^8.0
This package is auto-updated.
Last update: 2025-05-29 01:48:02 UTC
README
Simple package for managing Plausible tracking with PHP.
Installation
You can install the package via composer:
composer require marekzelezny/plausible
Add the following line to your layout file's <head>
tag:
<x-plausible::script />
Add the plausible domain from config/plausible.php
to env file:
PLAUSIBLE_DOMAIN=example.com
Usage
You can enable tracking of these Plausible features:
- Custom properties for pageview
- Outbound link clicks
- File downloads
Custom properties for pageview
To enable this feature you have to add this line in your ENV file:
PLAUSIBLE_TRACKING_PAGEVIEW_PROPS=true
Then you can add custom properties to your pages by using function plausible()
inside your controllers.
Example usage:
plausible() ->property('pageType', 'article') ->property('category', 'news');
Which in return will output this to your page where you have added <x-plausible::script />
:
<script defer data-domain="example.com" src="https://plausible.io/js/script.manual.pageview-props.js"></script> <script> window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) } plausible('pageview', { props: { pageType: 'article', category: 'news' } }); </script>
You can also add multiple values of one property at once:
plausible() ->property('author', ['John Doe', 'Jane Doe'])
Which in return will add multiple values to one property by calling:
plausible('pageview', { props: {author: 'John Doe'} }); plausible('pageview', { props: {author: 'Jane Doe'} });
Which is currently the only way to add multiple values to one property at the moment, as Plausible does not support arrays yet.
Global default properties
You can also set global default properties for all pageviews by adding them in app service provider's boot()
method.
Outbound link clicks, File downloads
Outbound and File downloads require additional setting of goals in Plausible dashboard. You might get more information here.
Once you have setup goals in Plausible dashboard, you can enable tracking of these features:
PLAUSIBLE_TRACKING_OUTBOUND_LINK_CLICKS=true PLAUSIBLE_TRACKING_FILE_DOWNLOADS=true
This will add Plausible scripts for tracking outbound link clicks and file downloads, which are then tracked automatically.