# Survey + User Journey POC

A standalone proof of concept for the Survey and User Journey modules. No backend, no auth: all data is mock and lives in memory, so a page reload resets it.

## Use as a package

```bash
npm install @shiva004/surveys
```

```tsx
import { SurveyApp, JourneyApp, npsOf } from '@shiva004/surveys';
import '@shiva004/surveys/style.css';

export default function Page() {
  return <SurveyApp />;
}
```

### User Journey docs page (new in 0.3.0)

```tsx
import { UserJourneyDocs } from '@shiva004/surveys';
import '@shiva004/surveys/style.css';

<UserJourneyDocs githubUrl="https://github.com/your-org/your-repo" defaultTheme="dark" />
```

Self-contained (no Bootstrap needed): sidebar, "On this page" list with scroll-spy and a light/dark toggle. Props: `defaultTheme`, `githubUrl`, `className`.

Requires React 18 or newer. Also exported: `SurveyJourneyApp` (both modules with tabs), the NPS helpers, the journey analytics functions and all types.

## Run the demo

```bash
npm install
npm run dev      # http://localhost:5173
npm run build    # type-check + production build
```

## What it proves

**Survey**
- Create a survey with a question builder (nps, rating, multiple choice, open text) and validation
- Change status (draft / active / paused / closed); only active surveys accept answers
- Take a survey; each submission becomes a response
- Results page: NPS (promoters 9-10 minus detractors 0-6), category split, responses table
- Delete a survey and its responses

**User Journey**
- A simulated page-view session stream (400 seeded sessions, "+ Simulate 50 sessions" adds more)
- Navigation Analysis: views, share, bounce rate, exit rate per page
- Paths: top 8 sequences (first 4 steps) with share reaching /signup
- Userflows: where users go next from each page, as a percentage
- Journey Maps: build stages with emotion and touchpoint pages; each stage's reach is computed from the same sessions

The point of the Journey half: one event stream feeds all four views, so adding more traffic updates every tab.

## Layout

```
src/
  types.ts              shared types (mirror survey.types.ts / journeys.types.ts)
  ui.tsx                Stat, Tabs, Bar, Page + seeded rng
  survey/
    nps.ts              NPS maths (pure functions)
    data.ts             seed surveys and responses
    SurveyApp.tsx       list, create, take, results
  journey/
    analytics.ts        simulator + navigation / path / flow / reach calculations
    JourneyApp.tsx      four views + map builder
```

## From POC to the real modules

| POC | Real module |
| --- | --- |
| `survey/nps.ts`, `journey/analytics.ts` | Move to the backend (or a shared util); the real UI only renders summaries |
| In-memory state | `surveysApi` / `journeysApi` with react-query |
| Plain tables and cards | shared `DataTable`, `Header`, `StatCard`, `Card` |
| Simulated sessions | Real page-view events from tracking |
