PHP SDK
PHP server-side SDK with Laravel integration
PHP SDK
The entrolytics/php-client package provides server-side analytics tracking for PHP applications with first-class Laravel support.
Installation
composer require entrolytics/php-clientQuick Start
Install via Composer
composer require entrolytics/phpCreate a Client
<?php
use EntrolyticsNG\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://entrolytics.devUse Facade
use EntrolyticsNG\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 |
Phase 2: Web Vitals
trackVital(array $params): bool
Track Core Web Vitals metrics.
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
metric | string | Yes | Vital type (LCP, INP, CLS, TTFB, FCP) |
value | float | Yes | Metric value |
rating | string | Yes | Rating (good, needs-improvement, poor) |
delta | float | No | Difference from previous |
id | string | No | Unique identifier |
navigation_type | string | No | Navigation type |
attribution | array | No | Debug attribution |
url | string | No | Page URL |
path | string | No | URL path |
session_id | string | No | Session ID |
$client->trackVital([
'website_id' => 'abc123',
'metric' => 'LCP',
'value' => 2500.0,
'rating' => 'good',
'url' => 'https://example.com/page',
'path' => '/page'
]);Phase 2: Form Analytics
trackFormEvent(array $params): bool
Track form interaction events.
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
event_type | string | Yes | Event type (start, field_focus, field_blur, submit, abandon, validation_error) |
form_id | string | Yes | Form identifier |
url_path | string | Yes | Page path |
form_name | string | No | Human-readable form name |
field_name | string | No | Field name |
field_type | string | No | Input type |
field_index | int | No | Field position |
time_on_field | int | No | ms spent on field |
time_since_start | int | No | ms since form start |
error_message | string | No | Validation error |
success | bool | No | Submission success |
session_id | string | No | Session ID |
$client->trackFormEvent([
'website_id' => 'abc123',
'event_type' => 'submit',
'form_id' => 'contact-form',
'url_path' => '/contact',
'form_name' => 'Contact Form',
'success' => true,
'time_since_start' => 45000
]);Phase 2: Deployment Tracking
setDeployment(array $params): bool
Register deployment context.
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Website ID |
deploy_id | string | Yes | Deployment ID |
git_sha | string | No | Git commit SHA |
git_branch | string | No | Git branch |
deploy_url | string | No | Deployment URL |
source | string | No | Platform (vercel, netlify, etc.) |
$client->setDeployment([
'website_id' => 'abc123',
'deploy_id' => 'deploy_456',
'git_sha' => 'abc1234567890',
'git_branch' => 'main',
'source' => 'vercel'
]);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
- ✅ Phase 2: Web Vitals tracking
- ✅ Phase 2: Form Analytics
- ✅ Phase 2: Deployment tracking
- ✅ Self-hosted instance support