Update README.md

This commit is contained in:
mathiaspalmqvist committed 2025-01-30 23:02:20 +01:00
1 parent 2ea193a63a
commit 647d62f787
1 file changed
+50 -22
+50 -22
View File
@@ -7,50 +7,78 @@
A Laravel package for proxying Plausible Analytics, improving performance and privacy. A Laravel package for proxying Plausible Analytics, improving performance and privacy.
## Installation ## 🚀 Installation
You can install the package via composer: 1. Install the package via Composer:
```sh
```bash
composer require mattitjaab/laravel-plausible-proxy composer require mattitjaab/laravel-plausible-proxy
``` ```
You can publish and run the migrations with: 2. Publish the configuration file:
```sh
php artisan vendor:publish --tag=plausible-proxy-config
```
```bash 3. Add the following environment variables to your `.env` file:
php artisan vendor:publish --tag="laravel-plausible-proxy-migrations" ```env
PLAUSIBLE_DOMAIN=https://plausible.io
PLAUSIBLE_SITE=example.com
```
4. **(Optional)** If you want to use Laravel Queues to send events in the background, ensure your queue driver is set up correctly:
```env
QUEUE_CONNECTION=database
```
Then run migrations to create the necessary queue tables:
```sh
php artisan queue:table
php artisan migrate php artisan migrate
``` ```
You can publish the config file with: ## ⚙️ Configuration
```bash The `config/plausible-proxy.php` file allows you to customize the package settings:
php artisan vendor:publish --tag="laravel-plausible-proxy-config"
```
This is the contents of the published config file:
```php ```php
return [ return [
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
'site' => env('PLAUSIBLE_SITE', 'example.com'),
]; ];
``` ```
Optionally, you can publish the views using ## 🔥 Usage
```bash ### **1. Proxying the JavaScript file**
php artisan vendor:publish --tag="laravel-plausible-proxy-views" 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>
``` ```
## Usage The route `/js/script.js` is automatically handled and caches the script for **6 hours**.
```php ### **2. Sending Events to Plausible**
$laravelPlausibleProxy = new MattitjaAB\LaravelPlausibleProxy(); Instead of sending events directly to `plausible.io`, you can now send them to `/api/event`, and they will be queued and processed asynchronously.
echo $laravelPlausibleProxy->echoPhrase('Hello, MattitjaAB!');
Example request:
```sh
curl -X POST "https://example.com/api/event" \
-H "Content-Type: application/json" \
-d '{"n":"pageview","u":"https://example.com/page","d":"example.com"}'
``` ```
## Testing ## ✅ Features
```bash - 🚀 **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:
```sh
composer test composer test
``` ```