Reviewed-on: Github/laravel-plausible-proxy#18
laravel-plausible-proxy
A Laravel package for proxying Plausible Analytics, improving performance and privacy.
Requirements
- Laravel 11 or 12
- PHP 8.3 or 8.4
Installation
-
Install the package via Composer:
composer require mattitja/laravel-plausible-proxy -
Publish the configuration file:
php artisan vendor:publish --tag=plausible-proxy-config -
Add the following environment variable to your
.envfile:PLAUSIBLE_DOMAIN=https://plausible.io
Configuration
The config/plausible-proxy.php file allows you to customize the Plausible domain:
return [
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
];
Usage
1. Proxying the JavaScript file
This package proxies Plausible's script.js while caching it to improve performance and reduce external requests.
After installation, you can include the script like this:
<script defer data-domain="example.com" src="/js/script.js"></script>
The route /js/script.js is handled automatically and caches the script for 6 hours.
2. Sending events to Plausible
The script loaded from /js/script.js sends events to /api/event on your own domain, which forwards them to Plausible. This helps prevent blocking by ad blockers.
Only the visitor's User-Agent and IP address (as X-Forwarded-For) are forwarded to Plausible, which is what Plausible needs to count unique visitors. Cookies and other request headers are never forwarded.
If your application runs behind a load balancer or reverse proxy, make sure Laravel's trusted proxies are configured so the correct visitor IP is resolved.
Upgrading from mattitjaab/laravel-plausible-proxy
Version 2.0 renames the package and its namespace:
- Replace the package:
composer remove mattitjaab/laravel-plausible-proxy composer require mattitja/laravel-plausible-proxy - If you reference any package classes directly, change the namespace from
MattitjaAB\LaravelPlausibleProxytoMattitja\LaravelPlausibleProxy. - Laravel 10 is no longer supported.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please report security vulnerabilities by email to hej@mattitja.se.
Credits
License
The MIT License (MIT). Please see License File for more information.