Files
laravel-plausible-proxy/README.md
T
mathiaspalmqvist 8e7bff9e61
dependabot-auto-merge / dependabot (pull_request_target) Skipped
run-tests / P8.3 - L11.* - prefer-lowest - ubuntu-latest (push) Failing after 33s
run-tests / P8.4 - L11.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L12.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-lowest - ubuntu-latest (push) Canceled after 0s
run-tests / P8.4 - L13.* - prefer-stable - ubuntu-latest (push) Canceled after 0s
run-tests / P8.3 - L11.* - prefer-stable - ubuntu-latest (push) Canceled after 1s
Add support for Laravel 13
- Allow illuminate/contracts ^13.0
- Allow orchestra/testbench ^11.0 and Pest 4 (with plugins) for dev
- Add Laravel 13 to the CI test matrix
- Update requirements in README
2026-11-12 08:31:34 +01:00

97 lines
3.3 KiB
Markdown

# laravel-plausible-proxy
[![Latest Version on Packagist](https://img.shields.io/packagist/v/mattitja/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitja/laravel-plausible-proxy)
[![Tests](https://git.mattitja.se/Github/laravel-plausible-proxy/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://git.mattitja.se/Github/laravel-plausible-proxy/actions?workflow=run-tests.yml)
[![Code Style](https://git.mattitja.se/Github/laravel-plausible-proxy/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://git.mattitja.se/Github/laravel-plausible-proxy/actions?workflow=fix-php-code-style-issues.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/mattitja/laravel-plausible-proxy.svg?style=flat-square)](https://packagist.org/packages/mattitja/laravel-plausible-proxy)
A Laravel package for proxying Plausible Analytics, improving performance and privacy.
## Requirements
- Laravel 11, 12 or 13
- PHP 8.3 or 8.4
## Installation
1. Install the package via Composer:
```sh
composer require mattitja/laravel-plausible-proxy
```
2. Publish the configuration file:
```sh
php artisan vendor:publish --tag=plausible-proxy-config
```
3. Add the following environment variable to your `.env` file:
```env
PLAUSIBLE_DOMAIN=https://plausible.io
```
## Configuration
The `config/plausible-proxy.php` file allows you to customize the Plausible domain:
```php
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:
```html
<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](https://laravel.com/docs/requests#configuring-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:
1. Replace the package:
```sh
composer remove mattitjaab/laravel-plausible-proxy
composer require mattitja/laravel-plausible-proxy
```
2. If you reference any package classes directly, change the namespace from `MattitjaAB\LaravelPlausibleProxy` to `Mattitja\LaravelPlausibleProxy`.
3. Laravel 10 is no longer supported.
## Testing
```sh
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Security Vulnerabilities
Please report security vulnerabilities by email to hej@mattitja.se.
## Credits
- [Mathias Palmqvist](https://github.com/mathiaspalmqvist)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.