---
id: 03-analyzed-brand-and-with-analytics-wrapper
epic: product-analytics-channel
title: Add Analyzed brand and withAnalytics wrapper
type: technical-story
status: done
feature: core-shared
depends-on: [01-scaffold-core-analytics-package]
blocks: [04-manifest-schema-and-wire-use-case]
created: 2026-05-18T12:02:00Z
updated: 2026-05-18T11:55:08.463Z
---

## Goal

Add the `Analyzed<F>` brand to `core-shared/conformance/` and the `withAnalytics(analytics, factory)` higher-order wrapper to `@repo/core-analytics`. Together they enable brand-based conformance detection at DI bind time, mirroring the `Audited` / `withAudit` pattern.

## Why

`wireUseCase` (Story 04) and `assertFeatureConformance` (Story 05) both key off the `Analyzed` brand at runtime. The brand must exist in `core-shared` (so the assertion layer can import it without a circular dep) while the wrapper lives in `core-analytics` (analytics is optional; can't pollute core-shared with the implementation).

## Done when

- `Analyzed<F> = F & { readonly __analyzed: true }` exists in `packages/core-shared/src/conformance/brands.ts` and `isAnalyzed` guard exists in `packages/core-shared/src/conformance/brand-runtime.ts`.
- `withAnalytics(analytics, factory)` lives in `packages/core-analytics/src/with-analytics.ts`, attaches `Analyzed` via `attachBrand` from `core-shared/conformance/brand-runtime`, and is exported from `@repo/core-analytics`.
- `with-analytics.test.ts` asserts brand is present after wrapping and absent before.
- All gates pass on each commit independently.

## In scope

- `packages/core-shared/src/conformance/brands.ts` — `Analyzed<F>` type addition.
- `packages/core-shared/src/conformance/brand-runtime.ts` — `isAnalyzed` guard.
- `packages/core-core-shared/src/conformance/index.ts` — export additions.
- `packages/core-analytics/src/with-analytics.ts` + sibling test.
- `packages/core-analytics/src/index.ts` — export addition.

## Out of scope

- `wireUseCase` composition (Story 04).
- `assertFeatureConformance` extension (Story 05).
- `analyticsEvents` manifest field (Story 04).

## Tasks

- [x] Add `Analyzed<F>` brand type to `packages/core-shared/src/conformance/brands.ts` and `isAnalyzed(f): f is Analyzed<F>` guard to `brand-runtime.ts`; export both from the conformance index — all gates pass on this commit.
- [x] Add `withAnalytics(analytics, factory)` wrapper to `packages/core-analytics/src/with-analytics.ts` using `attachBrand` from `core-shared/conformance/brand-runtime` + `with-analytics.test.ts` asserting brand attached after wrapping and absent before; export from `@repo/core-analytics` root barrel — all gates pass on this commit.
