PHPackages                             clamp/analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. clamp/analytics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

clamp/analytics
===============

Server-side analytics SDK for Clamp. Send tracked events from PHP apps (Laravel, Symfony, WordPress, etc.).

v0.2.0(2mo ago)00MITPHPPHP &gt;=8.1

Since Apr 30Pushed 2mo agoCompare

[ Source](https://github.com/clamp-sh/analytics-php)[ Packagist](https://packagist.org/packages/clamp/analytics)[ Docs](https://clamp.sh)[ RSS](/packages/clamp-analytics/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

clamp/analytics
===============

[](#clampanalytics)

Server-side analytics SDK for [Clamp Analytics](https://clamp.sh) in PHP.

Send tracked events from any PHP server to Clamp. Works with Laravel, Symfony, WordPress, Slim, and anything else that runs PHP 8.1+ and can make outbound HTTPS calls.

Install
-------

[](#install)

```
composer require clamp/analytics
```

PHP 8.1+ supported. Requires `ext-curl` and `ext-json` (both standard).

Quick start
-----------

[](#quick-start)

```
use Clamp\Analytics\Analytics;
use Clamp\Analytics\Money;

Analytics::init(
    projectId: 'proj_xxx',
    apiKey: getenv('CLAMP_API_KEY'),
);

// Simple event
Analytics::track('signup', ['plan' => 'pro', 'method' => 'email']);

// Link a server event to a browser visitor
Analytics::track(
    'subscription_started',
    [
        'plan' => 'pro',
        'total' => new Money(29.00, 'USD'),
    ],
    anonymousId: 'aid_xxx',
);
```

Get a server API key at  (Settings → API Keys, format `sk_proj_...`). Set it as an environment variable; never commit it.

API
---

[](#api)

### `Analytics::init(projectId, apiKey, endpoint = null)`

[](#analyticsinitprojectid-apikey-endpoint--null)

Initializes the SDK. Call once at application bootstrap (Laravel `AppServiceProvider`, Symfony compiler pass, WordPress `plugins_loaded` hook). Stores config in static state.

`endpoint` is optional and overrides the default `https://api.clamp.sh`. Use this for self-hosted Clamp deployments or integration testing.

### `Analytics::track(name, properties = [], anonymousId = null, timestamp = null)`

[](#analyticstrackname-properties---anonymousid--null-timestamp--null)

Sends a server event.

- **`name`**: event name string. Examples: `'signup'`, `'subscription_started'`, `'feature_used'`.
- **`properties`**: optional associative array. Values may be `string`, `int`, `float`, `bool`, or `Money`. No nested arrays (other than `Money`) and no plain objects.
- **`anonymousId`**: optional string. Links the server event to a browser visitor.
- **`timestamp`**: optional. Pass a `DateTimeInterface` (timezone-aware preferred; non-UTC timestamps are normalized to UTC) or an ISO 8601 string. If omitted, the SDK uses the current UTC time.

Returns `true` on success. Throws `ClampHttpException` on a non-2xx response or `ClampNotInitializedException` if `init()` wasn't called.

### `Money(amount, currency)`

[](#moneyamount-currency)

A typed monetary value. Use it for revenue, refunds, taxes; anywhere a currency-denominated amount belongs.

```
Analytics::track('purchase', [
    'plan' => 'pro',
    'total' => new Money(29.00, 'USD'),
    'tax' => new Money(4.35, 'USD'),
]);
```

`amount` is in major units (29.00, not 2900). `currency` is an ISO 4217 code (uppercase, three letters).

### `Analytics::captureError(\Throwable $exception, array $context = [], ?string $anonymousId = null, $timestamp = null)`

[](#analyticscaptureerrorthrowable-exception-array-context---string-anonymousid--null-timestamp--null)

Sends a throwable as a `$error` event. Convenience over `track()` that extracts message, type, and stack from the throwable. The server adds a stable fingerprint at ingest so the same bug groups across occurrences.

```
use Clamp\Analytics\Analytics;

try {
    processWebhook($payload);
} catch (\Throwable $e) {
    Analytics::captureError($e, ['webhook' => 'stripe']);
}
```

- **`$exception`**: any `\Throwable`. Stack via `getTraceAsString`, type via the throwable's short class name.
- **`$context`**: optional associative array of additional properties. Values must be primitives (`string`, `int`, `float`, `bool`); the reserved key `'handled'` is ignored.
- **`$anonymousId`**: optional. Links the error to a browser visitor.
- **`$timestamp`**: optional `DateTimeInterface` or ISO 8601 string.

Same return value and exceptions as `track()`. Lengths are capped (`error.message` 1KB, `error.type` 64 chars, `error.stack` 16KB) to match server-side limits.

Framework integrations
----------------------

[](#framework-integrations)

Per-framework integration patterns (Laravel service provider, Symfony event subscriber, WordPress action hook) are documented at .

Errors
------

[](#errors)

The SDK is synchronous and throws on failure. There are no automatic retries. If you want fire-and-forget behaviour, wrap the call yourself:

```
try {
    Analytics::track('subscription_started', [...]);
} catch (\Clamp\Analytics\ClampException $e) {
    error_log('failed to send to Clamp: ' . $e->getMessage());
}
```

For high-throughput webhook handlers, defer to a background queue (Laravel queues, Symfony Messenger, RabbitMQ).

Links
-----

[](#links)

- Dashboard:
- Docs:
- Source:
- Issues:

###  Health Score

31

—

LowBetter than 65% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

84d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/260181762?v=4)[SBJ](/maintainers/sbj-o)[@sbj-o](https://github.com/sbj-o)

---

Tags

symfonylaraveleventstrackinganalyticsclamp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/clamp-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/clamp-analytics/health.svg)](https://phpackages.com/packages/clamp-analytics)
```

###  Alternatives

[brexis/laravel-workflow

Integerate Symfony Workflow component into Laravel.

287127.4k](/packages/brexis-laravel-workflow)[cornford/googlitics

An easy way to integrate Google Analytics with Laravel.

3310.2k](/packages/cornford-googlitics)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
