---
id: 06-analytics-protocol-bind-context
epic: product-analytics-channel
title: Add AnalyticsProtocol and BindContext.analytics
type: technical-story
status: done
feature: core-shared
depends-on: [05-assert-feature-conformance-analyzed]
blocks: [09-documentation]
created: 2026-05-18T12:05:00Z
updated: 2026-05-18T15:40:20.464Z
---

## Goal

Add `AnalyticsProtocol` to `core-shared/di/bind-protocols.ts` and an optional `analytics?: AnalyticsProtocol` field to `BindContext`. This is the DI seam that lets feature binders receive an analytics implementation at bind time without importing the concrete class.

## Why

Feature binders that need analytics accept `ctx.analytics` from the aggregator's `BindContext`. Without the protocol type and context field, there's no typed path for passing analytics through the DI layer. Mirrors how `IEventBus`, `IAuditLog`, and `IJobQueue` are threaded through `BindContext`.

## Done when

- `AnalyticsProtocol` structural type exists in `packages/core-shared/src/di/bind-protocols.ts` and is exported.
- `BindContext` (and `BindProductionContext`) gain `analytics?: AnalyticsProtocol`.
- Existing binder call-sites compile without changes (field is optional).
- All gates pass.

## In scope

- `packages/core-shared/src/di/bind-protocols.ts` — `AnalyticsProtocol` type.
- `packages/core-shared/src/di/bind-context.ts` — `analytics?:` field on both context shapes.
- Exports from `@repo/core-shared/di` barrel.

## Out of scope

- Wiring analytics in any actual feature binder (no template feature adopts analytics per PRD).
- `IAnalytics` class methods — `AnalyticsProtocol` is the structural type used for DI; it mirrors the `IAnalytics` shape but lives in `core-shared` to avoid a circular dependency.

## Tasks

- [x] Add `AnalyticsProtocol` structural type to `packages/core-shared/src/di/bind-protocols.ts` and `analytics?: AnalyticsProtocol` to `BindContext` + `BindProductionContext`; export from the `@repo/core-shared/di` barrel — all gates pass on this commit.
