Update README.md
This commit is contained in:
1 parent
2ea193a63a
commit
647d62f787
1 file changed
+53
-25
@@ -7,50 +7,78 @@
|
||||
|
||||
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
|
||||
composer require mattitjaab/laravel-plausible-proxy
|
||||
```
|
||||
|
||||
```bash
|
||||
composer require mattitjaab/laravel-plausible-proxy
|
||||
```
|
||||
2. Publish the configuration file:
|
||||
```sh
|
||||
php artisan vendor:publish --tag=plausible-proxy-config
|
||||
```
|
||||
|
||||
You can publish and run the migrations with:
|
||||
3. Add the following environment variables to your `.env` file:
|
||||
```env
|
||||
PLAUSIBLE_DOMAIN=https://plausible.io
|
||||
PLAUSIBLE_SITE=example.com
|
||||
```
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --tag="laravel-plausible-proxy-migrations"
|
||||
php artisan migrate
|
||||
```
|
||||
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
|
||||
```
|
||||
|
||||
You can publish the config file with:
|
||||
## ⚙️ Configuration
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --tag="laravel-plausible-proxy-config"
|
||||
```
|
||||
|
||||
This is the contents of the published config file:
|
||||
The `config/plausible-proxy.php` file allows you to customize the package settings:
|
||||
|
||||
```php
|
||||
return [
|
||||
'domain' => env('PLAUSIBLE_DOMAIN', 'https://plausible.io'),
|
||||
'site' => env('PLAUSIBLE_SITE', 'example.com'),
|
||||
];
|
||||
```
|
||||
|
||||
Optionally, you can publish the views using
|
||||
## 🔥 Usage
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --tag="laravel-plausible-proxy-views"
|
||||
### **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>
|
||||
```
|
||||
|
||||
## Usage
|
||||
The route `/js/script.js` is automatically handled and caches the script for **6 hours**.
|
||||
|
||||
```php
|
||||
$laravelPlausibleProxy = new MattitjaAB\LaravelPlausibleProxy();
|
||||
echo $laravelPlausibleProxy->echoPhrase('Hello, MattitjaAB!');
|
||||
### **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:
|
||||
```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
|
||||
```
|
||||
|
||||
|
||||
Reference in new issue
Block a user