# UI Event Naming Schema

## Objective

Give every tracked interaction a name that still means the same thing in a year.

A documented vocabulary and structure for event names and properties, applied across the app's existing tracking.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Audit the events the app already sends and list them. The duplicates, the near-synonyms, and the ones nobody can explain are the reason the schema is needed, and they are also the migration list.
2. Fix a structure of object, action, and context: what was acted on, what happened to it, and where. Fix a closed set of actions — viewed, clicked, opened, submitted, selected, failed — and require every new event to reuse one of them.
3. Keep variable detail in properties, never in the name. A record identifier, a plan name, or a workspace slug baked into an event name produces thousands of unaggregatable one-off events.
4. Separate product events, which describe what a user achieved, from operational events, which describe how the interface behaved. They have different audiences, different retention, and often different destinations.
5. Version the schema and treat a change of meaning as a new name rather than a redefinition. A chart that silently changes what it counts halfway through is worse than one that visibly breaks.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Without a fixed object, action, and context structure, two teams will record the same interaction under three names and the numbers will never reconcile. The structure has to be enforced at the point events are declared, not agreed informally.
- Identifiers, search terms, and other variable values in event names create unbounded cardinality that no analytics tool can aggregate and every analytics bill will reflect. They belong in properties.
- A breaking change needs a new name and an overlap period where both are sent, so historical comparisons stay possible rather than showing a cliff on the day of the rename.
- Product and operational events must be distinguishable at a glance, because an operational event counted as product usage inflates engagement with things like retries and background refreshes.
- Property names and value shapes need the same discipline as event names; the same concept appearing as workspaceId in one event and workspace in another defeats every join.
- The schema must cover failures as first-class events, not just successes, or the funnel shows what worked and nothing about what did not.
- A deprecated name must remain documented after it stops being sent, so anyone reading an old dashboard can tell what it used to mean.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every event in the app follows the documented object, action, and context structure.
- [ ] Actions come from a fixed, published list rather than being invented per screen.
- [ ] No event name contains an identifier, a search term, or any other variable value.
- [ ] Product and operational events are separated and labelled.
- [ ] Property names and value shapes are consistent across every event that carries them.
- [ ] Breaking changes ship as new names with a documented overlap period.
- [ ] The existing events that predated the schema have been migrated or explicitly deprecated in writing.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
