# Kanject.Insights

A backend analytics engine you deploy into your own AWS — it ingests your domain events and computes six proven analysis kinds (funnels, cohorts, correlations, and more) with background workers. Define event types in code, run analyses through typed manager services.

> **Note:** Developer guide. For the analytics-pattern showcase and the action/trigger layer, see the [Insights product page](https://www.kanject.com/baas/insights/).

**You'll learn**

- Provision Insights into your AWS account
- Register the client surface and the background workers
- Define event types with `IInsightEventManager`
- Know the six built-in analysis kinds and the alerting surface

## Provision

```bash
kanject baas deploy insights --env dev
```

## Register it in your service

Insights has two registration surfaces from `Kanject.Insights.Provider.AwsV2.Extensions`: `AddKanjectInsight` wires the client (define events, run analyses), and `AddKanjectInsightWorkers` wires the background consumers that ingest events and compute snapshots. Both take a typed `InsightOption` delegate; generic overloads accept your own data context.

```csharp
using Kanject.Insights.Provider.AwsV2.Extensions;

var builder = WebApplication.CreateBuilder(args);

// The client surface (define events, run analyses).
builder.Services.AddKanjectInsight(options =>
{
    options.Region    = appSettings.AwsRegion;
    options.Namespace = appSettings.Stage;
});

// The background workers that ingest events and compute snapshots.
builder.Services.AddKanjectInsightWorkers(options => { /* … */ });

var app = builder.Build();
app.Run();
```

## Define events, run analyses

This is a server-side engine, not a `Track()` client. You register the event types you want to analyse through `IInsightEventManager`, and run each analysis through the manager service for its kind:

```csharp
// Define the event types you'll analyse through IInsightEventManager.
public class AnalyticsSetup(IInsightEventManager events)
{
    public Task DefineCheckoutEventAsync(CreateInsightEventRequest request)
        => events.CreateInsightEventAsync(request);
}

// Run an analysis through the manager service for its kind.
public class Reporting(IFunnelInsightManagerService funnels)
{
    // Build/query a funnel (InsightKind.Funnel) over the ingested events.
    // Each InsightKind has its own manager service.
}
```

## Six built-in analysis kinds

Every kind is a real `InsightKind` with its own manager service over the ingested event stream:

- **Standard** — deconstruct single events across metrics (`IStandardInsightManagerService`).
- **Funnel** — map a conversion journey and find the friction step.
- **Correlation** — relate distinct events and measure significance.
- **Cohort** — track a segment's behaviour over time.
- **Comparative** — period-over-period trend changes.
- **Event sequence** — ordered patterns with temporal constraints.

## What you get

- **Backend ingestion** — event ingestion + snapshot computation on SQS/EventBridge/SNS workers, in your account.
- **Six analysis kinds** — Standard, Funnel, Correlation, Cohort, Comparative, Event Sequence, each a typed manager service.
- **Alert rules** — `AlertRuleType.Threshold` and `AlertRuleType.AnomalyDetection` with configurable sensitivity.
- **Scheduled evaluation** — EventBridge-scheduled alert/snapshot evaluation.
- **Event management** — define and toggle event types via `IInsightEventManager`.

> **Pitfall:** Analyses can only slice the fields your events carry, so **model your event types clean and complete**. Add a field and every analysis can use it going forward — but events ingested *before* that change won't have it retroactively.

**Recap**

- Provision with `kanject baas deploy insights`; register `AddKanjectInsight` + `AddKanjectInsightWorkers`.
- It's a backend engine — define event types via `IInsightEventManager`, not a client-side `Track()`.
- Six `InsightKind` analyses (Standard/Funnel/Correlation/Cohort/Comparative/EventSequence) via manager services.
- Threshold and anomaly alert rules run on scheduled evaluation.

## Related modules

- **[EventHub](https://www.kanject.com/docs/baas-eventhub/)** — A natural event source to feed into Insights.
- **[Identity](https://www.kanject.com/docs/baas-identity/)** — User attribution for cohorts and funnels.
- **[Wallet](https://www.kanject.com/docs/baas-wallet/)** — Revenue events — GMV, refunds, payouts.

> **Next step:** Want events flowing automatically? Read [EventHub](https://www.kanject.com/docs/baas-eventhub/), or the [BaaS deployment guide](https://www.kanject.com/docs/baas/) for how the modules compose.

---
_Source: https://www.kanject.com/docs/baas-insights/ · Kanject Docs_
