kilden/laravel

Kilden for Laravel — server-side events, queued delivery and the /kilden/identity endpoint.

v0.1.0-alpha.2 2026-07-14 13:22 UTC

This package is auto-updated.

Last update: 2026-07-14 16:24:17 UTC


README

Kilden PHP SDK

kilden/laravel

Packagist license

Kilden is a customer data platform — analytics, campaigns and session replay on one event pipeline. This package wraps the PHP SDK for Laravel: a configured singleton, a facade, queued delivery, and the identity endpoint your frontend needs for identity verification.

Requires PHP 8.2+ and Laravel 11–13. For plain PHP (7.4+), use kilden/kilden-php directly.

Install

composer require kilden/laravel:@alpha kilden/kilden-php:@alpha

(Both @alpha flags are needed while we ship prereleases — Composer ignores stability flags on transitive requirements. They go away at 0.1.0.)

php artisan vendor:publish --tag=kilden-config

Set your secret write key — never the public wk_ one, which belongs in the browser SDK:

KILDEN_WRITE_KEY=sk_...

Track from anywhere

use Kilden\Laravel\Facades\Kilden;

Kilden::track($user->id, 'order_completed', ['revenue' => 99.9, 'currency' => 'CLP']);
Kilden::identify($user->id, ['plan' => 'pro', 'email' => $user->email]);

Events flush automatically at the end of the request (and on queue workers, when the job finishes). With KILDEN_QUEUE=true, calls dispatch a job instead of sending inline — the timestamp is stamped at call time, so nothing shifts.

Identity verification

The browser SDK can prove who its events belong to — but only your backend can sign that proof. One route makes it work:

// routes/web.php
use Kilden\Laravel\KildenRoutes;

KildenRoutes::identity();   // POST /kilden/identity, behind your auth middleware
KILDEN_IDENTITY_SECRET=...   # from your Kilden project settings
KILDEN_IDENTITY_KID=k1

The route signs a short-lived token for auth()->user() and returns { distinct_id, token, traits } — the web SDK refreshes against it automatically. To attach signed traits:

KildenRoutes::traitsUsing(fn ($user) => ['plan' => $user->plan]);

Only ever sign the authenticated user. Signing an id taken from request input lets anyone impersonate anyone — with a "verified" stamp on top.

Feature flags

if (Kilden::isEnabled('new_checkout', $user->id, ['default' => false])) {
    // ...
}

$variant = Kilden::getFeatureFlag('pricing_test', $user->id, [
    'person_properties' => ['plan' => $user->plan],
]);

Testing

use Kilden\Laravel\Facades\Kilden;

Kilden::fake();

// ... run code that tracks ...

Kilden::assertTracked('order_completed');
Kilden::assertNothingTracked();

With KILDEN_WRITE_KEY unset (or KILDEN_ENABLED=false) the client is a silent no-op, so test and local environments need no configuration at all.

About this repository

Read-only subtree split of kilden-sdk-php/packages/laravel — issues and pull requests go there. Behavior is governed by the server SDK spec.

License

MIT