PHP SDK
Server-side tracking for PHP 8.1+. Events are queued, batched, and delivered to /v1/batch
with your write key. The client registers a shutdown function that flushes pending messages
when the PHP process exits, so an explicit close() is only needed when you must guarantee
delivery mid-script.
Installation
Section titled “Installation”composer require origamy/php-sdkBasic usage
Section titled “Basic usage”<?php
use Origamy\AnalyticsClient;use Origamy\Config;use Origamy\Messages\Track;
[$client, $err] = AnalyticsClient::newWithConfig( getenv('ORIGAMY_WRITE_KEY'), new Config(endpoint: 'https://events.origamy.io'),);if ($err !== null) { throw $err;}
$client->enqueue(new Track( event: 'Signed Up', userId: 'user-123',));
$client->close();Message types
Section titled “Message types”The message types mirror the event spec:
use Origamy\Messages\{Track, Identify, Page, Group, Alias};use Origamy\Properties;use Origamy\Traits as OrigamyTraits;
// Track an action$client->enqueue(new Track( event: 'Order Completed', userId: 'user-123', properties: (new Properties()) ->set('orderId', 'ORD-9999') ->setRevenue(99.99) ->setCurrency('USD'),));
// Identify a user with traits$client->enqueue(new Identify( userId: 'user-123', traits: (new OrigamyTraits()) ->setName('Alice Smith') ->set('plan', 'pro'),));
// Track a page view$client->enqueue(new Page( userId: 'user-123', name: 'Pricing', properties: (new Properties()) ->set('url', 'https://example.com/pricing'),));
// Associate a user with a group/company$client->enqueue(new Group( groupId: 'company-acme', userId: 'user-123', traits: (new OrigamyTraits())->setName('Acme Corp'),));
// Alias an anonymous ID to an identified user$client->enqueue(new Alias( previousId: 'anon-session-abc', userId: 'user-123',));For anonymous tracking, pass anonymousId instead of (or alongside) userId.
Configuration
Section titled “Configuration”use Origamy\AnalyticsClient;use Origamy\Config;
[$client, $err] = AnalyticsClient::newWithConfig('your-write-key', new Config( endpoint: 'https://events.origamy.io', batchSize: 100, verbose: true,));Development mode
Section titled “Development mode”Use the NoopDispatcher to log events to the console instead of sending them:
use Origamy\Config;use Origamy\Dispatcher\{DispatcherConfig, NoopDispatcher};
[$client, $err] = AnalyticsClient::newWithConfig('your-write-key', new Config( endpoint: 'https://events.origamy.io', dispatcher: new NoopDispatcher(new DispatcherConfig(verbose: true)),));Custom queue and transport
Section titled “Custom queue and transport”use Origamy\Config;use Origamy\Queue\InMemoryQueue;use Origamy\Dispatcher\DispatcherInterface;
// Bounded queuenew Config(queue: new InMemoryQueue(capacity: 1000));
// Custom transport — implement DispatcherInterfaceinterface DispatcherInterface{ public function send(string $payload): void; public function close(): void;}Wire format
Section titled “Wire format”Batches post to POST /v1/batch using the same payload as every Origamy SDK, authenticated
with HTTP Basic auth (write key as username, empty password). See the
Ingestion API for endpoints, limits, and response codes.
