Search by

sumly / sdk

meetprimo

Sumly for PHP and Laravel: events, payments, costs and feature flags from your server.

v1.0.0 2026-11-21 14:50 UTC

This package is auto-updated.

Last update: 2026-11-21 14:55:23 UTC


README

Send events, payments and costs to Sumly from your server, and read feature flags and experiments. No dependencies; a Laravel service provider and facade come with it.

composer require sumly/sdk

Laravel

Add the project's secret key (Sumly › Visitors › Active users) to .env:

SUMLY_KEY=sk_sumly_…
use Sumly\Laravel\Facades\Sumly;

Sumly::track($user->id, 'trial_started', ['plan' => 'pro']);
Sumly::identify($user->id, ['name' => $user->name, 'email' => $user->email, 'properties' => ['plan' => 'pro']]);

if (Sumly::isEnabled($user->id, 'new-billing')) {
    // …
}
$plan = Sumly::getVariant($user->id, 'paywall', 'year');

A user's flags are kept in your cache for SUMLY_FLAGS_TTL seconds (60). When a flag is in an experiment, reading it sends one $flag_seen event per user and value, so Sumly counts who saw which variant and what they paid after. If Sumly cannot be reached, flags answer with your fallback and never throw.

php artisan vendor:publish --tag=sumly-config copies config/sumly.php (key, endpoint, timeout, flags_ttl).

Plain PHP

$sumly = new Sumly\Sumly(getenv('SUMLY_KEY'));
$sumly->payments(['id' => 'inv_1042', 'amount' => 29.00, 'currency' => 'EUR', 'user_id' => 'u_1842']);
$sumly->costs(['id' => 'ads-2026-11', 'date' => '2026-11-01', 'name' => 'Google Ads', 'amount' => 120]);
$flags = $sumly->flags('u_1842', ['properties' => ['plan' => 'pro'], 'country' => 'SI']);

Signed user ids

Where a project trusts signed user ids only, sign the id on your server and pass the hash to the app's identify(id, { hash }):

$hash = Sumly\Sumly::signUserId($user->id, config('services.sumly.flag_secret'));

The whole API: https://sumly.dev/docs/api · Flags: https://sumly.dev/docs/flags

Versions

  • 1.0.0: events (track, screen, identify, forget), payments and costs, flags (flags, isEnabled, getVariant, getFlagPayload, $flag_seen for experiments), signUserId, the Laravel service provider and facade.