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-php
composer require entro314labs/entro-php
php artisan vendor:publish --tag=entrolytics-config

Quick Start

Install via Composer

composer require entro314labs/entro-php

Create 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-config

Configure Environment

Add to .env:

.env
ENTROLYTICS_WEBSITE_ID=your-website-id
ENTROLYTICS_API_KEY=ent_xxx
ENTROLYTICS_HOST=https://cloud.entrolytics.click

Use 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

resources/views/layouts/app.blade.php
<!DOCTYPE html>
<html>
<head>
    @entrolytics
</head>
<body>
    {{ $slot }}
</body>
</html>

API Reference

Client Methods

track(array $params): bool

ParameterTypeRequiredDescription
website_idstringYesWebsite ID
eventstringYesEvent name
dataarrayNoEvent data
urlstringNoPage URL
user_idstringNoUser ID
ip_addressstringNoClient IP

pageView(array $params): bool

ParameterTypeRequiredDescription
website_idstringYesWebsite ID
urlstringYesPage URL
referrerstringNoReferrer URL
titlestringNoPage title

identify(array $params): bool

ParameterTypeRequiredDescription
website_idstringYesWebsite ID
user_idstringYesUser ID
traitsarrayNoUser 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

Support