›
byrcsc/laravel-customer-health · 1.x
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.
The facade resolves the singleton CustomerHealthManager.
use ByRcsc\LaravelCustomerHealth\Facades\CustomerHealth;| Method | Return |
|---|---|
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.
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
{
}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.
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.
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.
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.
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.
interface TenantResolver
{
public function __invoke(): int|string|null;
}The package includes NullTenantResolver and the optional
SpatieTenantResolver.
Public properties:
public ?CarbonImmutable $firstUsedAt;
public ?CarbonImmutable $lastUsedAt;Methods:
public function eventCount(?int $days = null): int;
public function distinctActors(?int $days = null): int;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.
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.
The supported readable Eloquent models are:
| Model | Main public behavior |
|---|---|
ProductEventRecord | subject(), actor(), and prunable() |
Milestone | subject() and actor() |
HealthScoreRecord | subject() and toScoreResult() |
HealthSummary | subjectIdentity() |
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.