›
byrcsc/laravel-customer-health · 1.x
Laravel Customer Health derives customer health signals from product events stored in your application.
Customer health becomes difficult to explain when onboarding progress, product activity, and score calculations live in separate systems. Laravel Customer Health records those inputs against your Eloquent models and keeps the derived history in your application database.
You declare the events that matter, group milestone events into onboarding checklists, and combine signals into health scores. The package then answers questions such as:
The package supports Laravel 12 and 13 on PHP 8.3 or later.
Imagine Acme is setting up its account. Taylor creates the team's first approval workflow. That action shows that Acme has moved from signing in to using the workflow feature.
Describe that action with a product event:
namespace App\CustomerHealth\Events;
use ByRcsc\LaravelCustomerHealth\Events\ProductEvent;
final class WorkflowCreated extends ProductEvent
{
// Group this event with other workflow activity.
public static string $feature = 'workflows';
// Preserve the first workflow as a lasting sign of adoption.
public static bool $milestone = true;
}Read the declaration as: when a customer creates a workflow, count it as workflow activity and remember the first occurrence as an adoption milestone. Later workflow creations are still recorded as raw product events.
Register the event in config/customer-health.php. When the create-workflow
operation succeeds, track who performed it and which template they used:
use App\CustomerHealth\Events\WorkflowCreated;
use ByRcsc\LaravelCustomerHealth\Facades\CustomerHealth;
CustomerHealth::track(new WorkflowCreated(
subject: $team,
actor: $user,
properties: ['template' => 'approval'],
));Here, $team is Acme, the customer whose health you measure. $user is
Taylor, the person who created the workflow.
The subject must be a persisted Eloquent model that implements Trackable.
The actor is optional, but when present it must be a persisted authenticatable
Eloquent model.
Every call to track() writes a raw product event. A milestone event also
writes its first occurrence to the milestones table.
Raw events answer time-window and frequency questions. Milestones remain after raw events are pruned, so adoption and onboarding completion do not disappear with retention cleanup.
All event times are stored and returned in UTC as CarbonImmutable values.
A health score combines one or more signals. Each signal returns an integer from 0 through 100 and carries a positive weight.
Each computation stores:
Computing a score appends history. It also updates one compact summary row for the subject and score, which is the table to query for current state.
The package does not decide which events, onboarding steps, signals, weights, or state thresholds fit your business. You declare them in application code.
It does not ingest analytics from a browser or third-party platform. Your
application calls CustomerHealth::track() when a verified business event
occurs.
It also does not schedule score recomputation or raw-event pruning. It provides Artisan commands that you add to Laravel's scheduler at the cadence your application needs.