›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-customer-health
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Product events
  • Features and milestones
  • Onboarding
  • Health scores
  • Summaries and tenancy

Operations

  • Querying customer health
  • Queueing events
  • Recomputing scores
  • Retention and erasure
  • Production operations

Reference

  • Configuration
  • Public API
  • Events
  • Console commands
  • Database storage
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Product events
  • Features and milestones
  • Onboarding
  • Health scores
  • Summaries and tenancy

Operations

  • Querying customer health
  • Queueing events
  • Recomputing scores
  • Retention and erasure
  • Production operations

Reference

  • Configuration
  • Public API
  • Events
  • Console commands
  • Database storage
  • Testing
  • Troubleshooting

byrcsc/laravel-customer-health · 1.x

Public API.

Reference the package facade, contracts, declarations, signals, value objects, and readable models.

Use this page when you need an exact public method signature or return type. All types live under ByRcsc\LaravelCustomerHealth.

CustomerHealth facade

The facade resolves the singleton CustomerHealthManager.

use ByRcsc\LaravelCustomerHealth\Facades\CustomerHealth;
MethodReturn
track(ProductEvent $event)void
features()array<string, list<class-string<ProductEvent>>>
hasAdopted(Trackable $subject, string $feature)bool
featureUsage(string $feature)FeatureUsageQuery
lastSeen(Trackable $subject)?CarbonImmutable
inactive(int $days)InactiveSubjectsQuery
onboarding(Trackable $subject, ?string $checklist = null)Progress
stalledInOnboarding(int $days)StalledOnboardingQuery
compute(Trackable $subject, ?string $score = null)ScoreResult
score(Trackable $subject, ?string $score = null)?ScoreResult
scoreHistory(Trackable $subject, ?string $score = null)Collection<int, ScoreResult>
summaries()Builder<HealthSummary>
inState(string $state, ?string $score = null)Builder<HealthSummary>
purge(Trackable $subject)void

FeatureUsageQuery::for(Trackable $subject) returns FeatureUsage. InactiveSubjectsQuery::get() and StalledOnboardingQuery::get() return a collection of morph identities with public type and id values.

Trackable contract

Contracts\Trackable is a marker interface with no methods. A value passed as a customer health subject must implement it and be a persisted Eloquent model.

use ByRcsc\LaravelCustomerHealth\Contracts\Trackable;
use Illuminate\Database\Eloquent\Model;

final class Team extends Model implements Trackable
{
}

TracksCustomerHealth concern

Concerns\TracksCustomerHealth adds model helpers:

public function productEvents(): MorphMany;
public function milestones(): MorphMany;
public function lastProductActivity(): ?CarbonImmutable;
public function hasAdopted(string $feature): bool;

The two query helpers delegate to the facade.

ProductEvent declaration

abstract class ProductEvent
{
    public static string $feature;
    public static bool $milestone = false;
    public static string $name;

    public function __construct(
        Trackable $subject,
        (Authenticatable&Model)|null $actor = null,
        array $properties = [],
        ?DateTimeInterface $occurredAt = null,
    );

    public static function name(): string;
}

Instances expose readonly subject, actor, properties, and occurredAt properties.

Checklist declaration

abstract class Checklist
{
    public static string $name;

    abstract public function steps(): array;

    public static function name(): string;
    public function stepNames(): array;
    public function stepForName(string $name): string;
}

steps() returns a list of registered milestone ProductEvent classes.

HealthScore declaration

abstract class HealthScore
{
    public static string $name;

    abstract public function signals(): array;
    abstract public function states(): array;

    public static function name(): string;
}

signals() returns a list of Signal. states() returns array<string, int> mapping state names to inclusive lower thresholds.

Signal contracts

interface Signal
{
    public function evaluate(Trackable $subject): int;
    public function weight(): float;
}

interface WindowedSignal extends Signal
{
    public function windowDays(): int;
}

Built-in signal constructors are:

new RecentActivity(int $days, float $weight);
new FeatureAdopted(string $feature, float $weight);
new FeatureActivity(string $feature, int $days, float $weight);
new DistinctActors(int $days, float $weight);
new OnboardingProgress(string $checklist, float $weight);

OnboardingProgress::$checklist accepts a registered checklist name or class.

TenantResolver contract

interface TenantResolver
{
    public function __invoke(): int|string|null;
}

The package includes NullTenantResolver and the optional SpatieTenantResolver.

FeatureUsage value

Public properties:

public ?CarbonImmutable $firstUsedAt;
public ?CarbonImmutable $lastUsedAt;

Methods:

public function eventCount(?int $days = null): int;
public function distinctActors(?int $days = null): int;

Progress value

public function completedSteps(): int;
public function totalSteps(): int;
public function percent(): int;
public function currentStep(): ?string;
public function isComplete(): bool;
public function stalledSince(): ?CarbonImmutable;

currentStep() returns a ProductEvent class name or null.

ScoreResult value

Readonly public properties:

public string $score;
public int $value;
public string $state;
public array $breakdown;
public CarbonImmutable $computedAt;

Each breakdown entry has signal, raw, weight, and contribution keys.

Readable models

The supported readable Eloquent models are:

ModelMain public behavior
ProductEventRecordsubject(), actor(), and prunable()
Milestonesubject() and actor()
HealthScoreRecordsubject() and toScoreResult()
HealthSummarysubjectIdentity()

Write product events through CustomerHealth::track() and scores through CustomerHealth::compute(). Direct model inserts bypass event registration, milestone uniqueness handling, onboarding reconciliation, score events, and summary synchronization.

What to read next

  • Events for the public properties on every dispatched event.
  • Console commands for command arguments and options.
  • Database storage for model attributes and table indexes.
PreviousConfigurationNextEvents
View source

On this page

  1. CustomerHealth facade
  2. Trackable contract
  3. TracksCustomerHealth concern
  4. ProductEvent declaration
  5. Checklist declaration
  6. HealthScore declaration
  7. Signal contracts
  8. TenantResolver contract
  9. FeatureUsage value
  10. Progress value
  11. ScoreResult value
  12. Readable models
  13. What to read next