agentleFS
PostHogKnown publisherPostHog/posthog-foss/.agents/skills/creating-customer-analytics-account-widgets/SKILL.md

creating-customer-analytics-account-widgets

Skill731 starsChanged 2 days agoMITView on GitHub

Creates or changes a Customer analytics account widget: a tile on an account detail view, or an account detail tab. Use when adding a widget, tile, or tab to the account page, giving a widget saved settings or a settings editor, or reviewing a diff that touches accountViewComponents.tsx, AccountViewComponent, AccountViewTile, AccountViewTileEditorModal, or account_views.py. Account view widgets follow the composition pattern: each widget is one entry in the ACCOUNT_VIEW_COMPONENTS registry, and shared code never branches on a widget kind. Covers the registry entry, the widget props contract, saved tile config, the backend tag and config validator, system tabs, and feature flags.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 3 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do not add a kind === branch to shared code.

    line 24
  2. Very specific:

    When a widget needs something the others do not, add an optional field to AccountViewComponentBase and let shared code read it.

    line 26
  3. Distinctive:

    Does it save settings?: If the widget has a filter, search, or sort worth keeping, it reads and writes tile config.

    line 32
  4. Distinctive:

    Does it need a settings editor?: Only when the tile's own controls cannot set the config.

    line 33
  5. Distinctive:

    Is it flag-gated?: Ask the user. Do not invent a flag.

    line 34
  6. Very specific:

    Build the widget: Put the component and its logic in frontend/components/Accounts/.

    line 38
  7. Very specific:

    Add the tag to the backend: Add tagName and its label to ACCOUNT_VIEW_COMPONENT_LABELS in backend/logic/account_views.py.

    line 41
  8. Very specific:

    Add the test rows: Add the tag to the parameterized test_accepts_account_widget in backend/test/test_account_views.py.

    line 42
  9. Very specific:

    If bad config can break the widget, add a validator to ACCOUNT_VIEW_CONFIG_VALIDATORS, keyed by tagName.

    line 50
  10. Very specific:

    Add ConfigEditor to the entry.

    line 54
  11. Very specific:

    Add the kind to AccountExpansionTab and ACCOUNT_EXPANSION_TABS in accountsExpansionLogic.ts.

    line 61
  12. Very specific:

    Add the same id to ACCOUNT_DETAIL_SYSTEM_TAB_IDS in backend/logic/user_customer_analytics_config.py.

    line 63
  13. Very specific:

    Never rename either one. A renamed tagName drops the tile from saved views without an error.

    line 74
  14. Very specific:

    No shared file gained a kind === or tag_name == branch.

    line 78

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Creating Customer analytics account widgets

Account view widgets follow the composition pattern. A view is an ordered list of independent widgets. Shared code knows a widget only through its entry in ACCOUNT_VIEW_COMPONENTS. The Accounts guide states the rules. Read that section first. This skill holds the steps.

Paths below are relative to products/customer_analytics/.

The rule that decides most questions

Do not add a kind === branch to shared code. Shared code is AccountViewComponent, AccountViewTile, AccountViewTileEditorModal, AccountViewRenderer, accountViewsLogic, and validate_account_view_content. When a widget needs something the others do not, add an optional field to AccountViewComponentBase and let shared code read it. ConfigEditor, onConfigSaved, and tileInsetClassName are the precedent.

Decide first

  • Tile only, or also a tab? A tile-only widget has no systemTabId. A tab also appears in the account detail tabs.
  • Does it save settings? If the widget has a filter, search, or sort worth keeping, it reads and writes tile config.
  • Does it need a settings editor? Only when the tile's own controls cannot set the config. Properties is the one precedent.
  • Is it flag-gated? Ask the user. Do not invent a flag.

Steps

  1. Build the widget. Put the component and its logic in frontend/components/Accounts/. Model them on AccountMeetingsExpansion and accountMeetingsLogic. Key the logic by account and instanceId, as in `${props.accountId}:${props.instanceId ?? 'default'}`. Without instanceId, two tiles of one kind share state.
  2. Add the kind. For a tile-only widget, add it to both unions in accountViewComponents.tsx. For a tab, see Tabs.
  3. Add the registry entry. Set kind, tagName, label, and Component. Component takes AccountViewWidgetProps and maps them to the widget. Pass getTileLogicProps(props) when the widget saves settings.
  4. Add the tag to the backend. Add tagName and its label to ACCOUNT_VIEW_COMPONENT_LABELS in backend/logic/account_views.py. Without it, the API rejects every view that holds the widget.
  5. Add the test rows. Add the tag to the parameterized test_accepts_account_widget in backend/test/test_account_views.py. Invoke /writing-tests before you add anything more.
  6. Update the Accounts guide. It asks for this in the same change.

Saved settings

  • The widget's logic reads props.initialConfig once, as reducer defaults. Use getTileString, getTileStringArray, and getTileRecord from accountViewTileConfig.ts, because saved config is untyped and can be stale.
  • The logic calls props.onConfigChange?.(config) from a listener with the whole config, not a patch. A read-only viewer gets no onConfigChange.
  • Config never holds an account identity. A view is reused across accounts, so the backend rejects accountId, externalId, projectId, teamId, and their snake_case forms at any depth. It also rejects config over 16 KB.
  • If bad config can break the widget, add a validator to ACCOUNT_VIEW_CONFIG_VALIDATORS, keyed by tagName. validate_properties_widget_config is the model.

Settings editor

Add ConfigEditor to the entry. It takes AccountViewTileConfigEditorProps and does not save. AccountViewTileEditorModal renders it under the tile name, and accountViewsLogic.saveTileEditor saves the name and the config in one queued write. To track a save, add onConfigSaved to the entry. Do not capture the event in accountViewsLogic.

Tabs

A tab needs these on top of the steps above:

  • Add the kind to AccountExpansionTab and ACCOUNT_EXPANSION_TABS in accountsExpansionLogic.ts.
  • Set systemTabId: 'system:<kind>' on the entry.
  • Add the same id to ACCOUNT_DETAIL_SYSTEM_TAB_IDS in backend/logic/user_customer_analytics_config.py. Without it, a user cannot save the tab's order or visibility.

Feature flags

Set featureFlag on the entry. That hides the widget from the picker, the renderer, and the tabs. A flag-gated tab also needs a line in getVisibleAccountExpansionTab, so a direct link falls back to the default tab. Extend the flag cases in accountTabs.test.ts and AccountViewRenderer.test.tsx.

Frozen strings

tagName is stored in every saved view. systemTabId is stored in every user's tab settings. Never rename either one. A renamed tagName drops the tile from saved views without an error.

Before you report done

  • No shared file gained a kind === or tag_name == branch.
  • The widget renders as a tile at a narrow span, and as a tab if it has systemTabId.
  • Two tiles of the new kind on one view keep separate state.
  • Saved settings survive a reload, and a read-only viewer triggers no write.
  • The backend accepts a view that holds the new tag.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.