This is my package laravel-plausible-proxy
A Laravel package for proxying Plausible Analytics, improving performance and privacy.
🚀 Installation
-
Install the package via Composer:
composer require mattitjaab/laravel-plausible-proxy -
Publish the configuration file:
php artisan vendor:publish --tag=plausible-proxy-config -
Add the following environment variables to your
.envfile:PLAUSIBLE_DOMAIN=https://plausible.io PLAUSIBLE_SITE=example.com -
(Optional) If you want to use Laravel Queues to send events in the background, ensure your queue driver is set up correctly:
QUEUE_CONNECTION=databaseThen run migrations to create the necessary queue tables:
php artisan queue:table php artisan migrate
⚙️ Configuration
The config/plausible-proxy.php file allows you to customize the package settings:
return [
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
'site' => env('PLAUSIBLE_SITE', 'example.com'),
];
🔥 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 automatically handled and caches the script for 6 hours.
2. Sending Events to Plausible
Instead of sending events directly to plausible.io, you can now send them to /api/event, and they will be queued and processed asynchronously.
Example request:
curl -X POST "https://example.com/api/event" \
-H "Content-Type: application/json" \
-d '{"n":"pageview","u":"https://example.com/page","d":"example.com"}'
✅ Features
- 🚀 Fast & Optimized: Caches the Plausible script to reduce external calls.
- 🔒 Privacy-Friendly: Prevents direct calls to
plausible.io. - 📊 Improved Performance: Events are processed via Laravel Queues to avoid blocking user interactions.
- 🛠 Fully Configurable: Easily set your own Plausible instance and domain via
.env.
🛠 Testing
You can run tests with:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.