PHP SDK
PHP server-side SDK with Laravel integration
PHP SDK
The entro314labs/entro-php package provides server-side analytics tracking for PHP applications with first-class Laravel support.
Installation
composer require entro314labs/entro-phpcomposer require entro314labs/entro-php
php artisan vendor:publish --tag=entrolytics-configQuick Start
Install via Composer
composer require entro314labs/entro-phpCreate a Client
<?php
use Entrolytics\Client;
$client = new Client('ent_xxx');Track Events
// Track custom event
$client->track([
'website_id' => 'your-website-id',
'event' => 'purchase',
'data' => [
'revenue' => 99.99,
'currency' => 'USD',
'product' => 'pro-plan'
]
]);
// Track page view
$client->pageView([
'website_id' => 'your-website-id',
'url' => '/pricing',
'referrer' => $_SERVER['HTTP_REFERER'] ?? null
]);
// Identify user
$client->identify([
'website_id' => 'your-website-id',
'user_id' => 'user_456',
'traits' => [
'email' => 'user@example.com',
'plan' => 'pro'
]
]);Laravel Integration
Publish Configuration
php artisan vendor:publish --tag=entrolytics-configConfigure Environment
Add to .env:
ENTROLYTICS_WEBSITE_ID=your-website-id
ENTROLYTICS_API_KEY=ent_xxx
ENTROLYTICS_HOST=https://cloud.entrolytics.clickUse Facade
use Entrolytics\Laravel\EntrolyticsFacade as Entrolytics;
// Track event
Entrolytics::track([
'website_id' => config('entrolytics.website_id'),
'event' => 'signup',
'data' => ['plan' => 'pro']
]);
// Identify user
Entrolytics::identify([
'website_id' => config('entrolytics.website_id'),
'user_id' => (string) auth()->id(),
'traits' => [
'email' => auth()->user()->email,
'plan' => auth()->user()->subscription->plan
]
]);Add Blade Directive
<!DOCTYPE html>
<html>
<head>
@entrolytics
</head>
<body>
{{ $slot }}
</body>
</html>API Reference
Client Methods
track(array $params): bool
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
event | string | Yes | Event name |
data | array | No | Event data |
url | string | No | Page URL |
user_id | string | No | User ID |
ip_address | string | No | Client IP |
pageView(array $params): bool
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
url | string | Yes | Page URL |
referrer | string | No | Referrer URL |
title | string | No | Page title |
identify(array $params): bool
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
user_id | string | Yes | User ID |
traits | array | No | User traits |
Advanced Usage
Requirements
- PHP
>= 8.1 guzzlehttp/guzzle >= 7.0
Optional
- Laravel
>= 10.0| ^11.0(for Laravel integration)
Features
- ✅ Simple, fluent API
- ✅ Laravel service provider and facade
- ✅ Blade directive for script injection
- ✅ Middleware for automatic page tracking
- ✅ Dependency injection support
- ✅ Comprehensive error handling
- ✅ Self-hosted instance support