# Plausible Goal Event

## Objective

Record real conversions in Plausible without collecting anything that identifies a person.

A small, fixed set of named goal events fired from confirmed outcomes, with low-cardinality properties and consent respected.

## 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. List the outcomes that genuinely count as conversions — a completed signup, an activated workspace, a first successful action, a completed purchase — and give each one a short fixed name agreed up front. Keep the list small enough that someone can read it on one screen.
2. Fire each goal only after the outcome has actually succeeded and been committed, not when the user clicks the button that begins it. A goal fired on intent overstates every number that follows it.
3. Decide per goal whether it is sent from the browser or from the server and record that decision alongside the goal name. Sending the same conversion from both is the usual cause of doubled numbers.
4. Keep custom properties to a handful of low-cardinality values such as plan tier or source, and never attach an email address, a user identifier, a record identifier, or anything typed by a user. The point of this provider is that it does not build a profile of the visitor.
5. Route the sends through the app's existing consent or regional privacy handling rather than adding a second check. If the app has a separate brief for a fuller analytics pipeline, this entry owns only the named conversion goals and leaves general page and behaviour tracking to that one.

## 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

- Goal names must be stable constants, because the provider treats a changed name as a new goal and the historical series simply stops. Never build a name from user content, a plan name that marketing can rename, or an identifier.
- The same conversion fired from the browser and again from the server doubles the count, and the two will disagree because one is blocked by ad blockers and the other is not. Pick one origin per goal and enforce it.
- Custom properties with unbounded values make the reports unusable and can carry personal data by accident. Restrict properties to an allowed key list with a known set of values.
- Consent and regional rules configured elsewhere in the app must gate these sends too. A goal that fires before the user has answered the consent prompt is a compliance problem regardless of how little data it carries.
- A goal fired optimistically before the transaction commits will count conversions that were rolled back. Send after commit, from the code path that knows the outcome succeeded.
- Client-side sends are blocked for a meaningful share of visitors, so browser-origin goals will always undercount. Note which goals are affected rather than treating the numbers as complete.
- When the provider is unreachable, the send must fail quietly. Analytics must never block a checkout, a signup, or any user-facing flow, and a failed send is not worth an error shown to the user.
- Retries on a fire-and-forget send create duplicates without improving accuracy. Either accept the loss or send server-side with a deduplication key, but do not blindly retry.

## 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 goal has a fixed name from an agreed list, with no dynamic or user-supplied content in it.
- [ ] Each goal has exactly one declared origin, browser or server, and is not sent from both.
- [ ] Goals fire only after the underlying outcome is committed and successful.
- [ ] Custom properties are restricted to an allowed low-cardinality set and contain no personal or identifying data.
- [ ] Consent and regional privacy settings gate every send through the app's existing handling.
- [ ] A provider outage or a blocked request never blocks, delays, or errors a user-facing flow.
- [ ] 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.
