implementing-api-surveys
Was er macht
Dieser Skill zeigt einem Agenten, wie eine PostHog-Umfrage gebaut wird, die innerhalb deines Produkts läuft, mit den eigenen Komponenten und dem Layout deiner App. Er richtet sich an Entwickler, die volle Kontrolle über das Aussehen der Umfrage wollen.
Wann du ihn nutzt
- ✓Wenn du eine PostHog-Umfrage in deiner Website oder App mit eigenem Design zeigen willst.
- ✓Wenn du einen eigenen Umfrage-Bildschirm baust, statt das eingebaute Pop-up von PostHog zu nutzen.
- ✓Wenn du bestätigen musst, dass Umfrageantworten korrekt bei PostHog ankommen.
Link zum Skill
https://github.com/PostHog/posthog/blob/master/products/surveys/skills/implementing-api-surveys/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Kannst du eine PostHog-Umfrage in meine App einbauen, damit sie zu unserem Design passt, und prüfen, dass die Antworten ankommen?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Agent liest deine Umfrage in PostHog, sieht sich deinen Code und die vorhandenen Komponenten an, schreibt den Umfrage-Bildschirm und sendet die richtigen Ereignisse an PostHog. Danach prüft er, dass eine Testantwort angekommen ist.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
Implementing API surveys
An api survey is only a definition in PostHog. PostHog does not render it. The application renders the questions and captures the survey events. If the events or their properties are wrong, responses are missing, double-counted, or unattributed.
1. Get the survey
Fetch it with posthog:survey-get by id. Note each question's id, type, question, choices, scale and optional, plus current_iteration. Never invent question ids.
If the survey does not exist yet, create it first with the creating-surveys skill (type api). Design guidance (short, rating or choice first, open text second) lives there too. Do not restate it here.
2. Read the user's codebase
Before writing UI, find:
- The framework and the existing component library or design system. Build the survey from those components, not a generic modal.
- Where PostHog is initialized, and the installed SDK and version (
package.jsonor lockfile, or the server language's manifest). - Where the survey should appear. Let the app own the trigger: leave the survey's event, URL and selector
conditionsempty, and run the lookup below at the moment the survey should appear.getActiveMatchingSurveysonly returns a survey with event conditions after that event fires, and nothing runs the lookup again at that point.
Pick the path:
- Browser app with posthog-js: continue below.
- Server-rendered pages, other SDKs (Python, Node, Go, Ruby, PHP), or custom mobile UI: read server-and-mobile.md, then return to step 5. Mobile SDKs render only popover surveys natively, so a custom mobile UI follows the server pattern.
3. Browser contract (posthog-js)
Require posthog-js 1.249.2 or newer. Older versions do not set the person properties and seen state on capture. Tell the user to upgrade rather than adding them by hand.
The lookup only works once both flags and the surveys bundle have loaded, because targeting is evaluated with flags and getActiveMatchingSurveys does nothing before surveys load. Register one retry for each at startup, and guard against rendering twice, since onFeatureFlags also runs on every flag reload (after identify, and after each response).
let triggered = false
let rendered = false
function tryShowSurvey() {
if (!triggered || rendered) return
posthog.getActiveMatchingSurveys((surveys) => {
const survey = surveys.find((s) => s.id === SURVEY_ID)
if (!survey || rendered) return
rendered = true
renderSurvey(survey)
})
}
// Register once at startup, not per trigger.
posthog.onFeatureFlags(tryShowSurvey)
posthog.onSurveysLoaded(tryShowSurvey)
function showSurveyIfEligible() {
triggered = true
tryShowSurvey()
}
// Call when the survey closes, after the final send or a dismiss.
function onSurveyClosed() {
triggered = false
rendered = false
}
Call showSurveyIfEligible() from the app's trigger, such as after a checkout completes, or right after setup if the survey belongs on page load. Call onSurveyClosed() when the survey closes, so a survey that can repeat shows again on the next trigger. A survey that cannot repeat stays hidden, because posthog-js marks it as seen. In a single-page app, register the two listeners where the app initializes PostHog, and call the functions they return to unsubscribe if that code can unmount. SURVEY_ID is the id from step 1. renderSurvey mounts the component you build from the app's own UI, and that component calls the handlers below. getActiveMatchingSurveys applies the survey's targeting for this person, so render only what it returns.
Capture three events. answers maps each question id to its answer, and holds every answer given so far in this submission. Exact property names and value shapes are in event-contract.md.
function onShown(survey) {
posthog.capture('survey shown', {
$survey_id: survey.id,
$survey_iteration: survey.current_iteration,
})
// posthog-js reads this key for the survey wait period; only its own renderer writes it.
try {
localStorage.setItem('lastSeenSurveyDate', new Date().toISOString())
} catch {}
}
function onSubmit(survey, answers, submissionId, completed) {
posthog.capture('survey sent', {
$survey_id: survey.id,
$survey_iteration: survey.current_iteration,
$survey_submission_id: submissionId,
$survey_completed: completed,
$survey_questions: survey.questions.map(({ id,
Häufige Fragen
Zeigt PostHog diese Umfrage für mich an?
Nein. Diese Art von Umfrage ist in PostHog nur eine Definition. Deine App zeichnet die Fragen und sendet die Antworten zurück.
Welche Apps können diesen Skill nutzen?
Browser-Apps, Server-Apps und eigene Mobile-Bildschirme, solange der Agent den Code lesen und bearbeiten kann.
Erstellt dieser Skill die Umfrage in PostHog?
Wenn die Umfrage noch nicht existiert, wird der Agent angewiesen, sie zuerst mit einem eigenen Umfrage-Skill zu erstellen.
Details
Originalbeschreibung des Autors
Implements a PostHog API (headless) survey inside the user's own codebase so it renders with their UI components and captures the exact events PostHog expects, then verifies the first response arrived. Use when asked to implement a survey, build a headless survey, build a custom survey UI, render a survey in my app, or wire up a survey of type `api` in a browser, server, or custom mobile UI. Covers the posthog-js event contract, server-side SDK capture, and post-implementation verification through MCP. To design or create the survey definition, use creating-surveys instead. For a survey that i
repo: PostHog/posthog
Beliebtheit
- GitHub-Sterne
- 41k
- Platz im Ranking
- #6960
- Lizenz
- —
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
depot-ci
41kBringt deinem Agenten bei, Depot-CI-Workflows einzurichten, bestehende Workflows zu migrieren und Laufprotokolle auszuwerten.
depot-container-builds
41kHilft deinem Agenten, Docker-Images auf Depot-Remote-Buildern zu bauen, mit Multi-Plattform-Images, Registry-Push und Fehlerbehebung.
depot-github-runners
41kLässt deinen Agenten GitHub-Actions-Jobs auf Depot-Runnern laufen, mit passender Runner-Größe und Labels, und hilft bei Einrichtungsfehlern.
editing-agents-md
41kHilft deinem Agenten zu entscheiden, ob eine Regel in AGENTS.md oder CLAUDE.md gehört, und sie so zu formulieren, dass sie hält.
Ähnliche Skills
angular-developer
280kHilft deinem Agenten bei Angular-Code und gibt Tipps zur Projektstruktur. Nützlich für neue Projekte, einzelne Code-Teile sowie Performance und Barrierefreiheit.
frontend-a11y
280kHilft deinem Agenten, Weboberflächen für alle zugänglich zu machen. Sorgt dafür, dass Websites und Apps gut mit Screenreadern und Tastaturnavigation funktionieren.
frontend-patterns
280kLässt deinen Agenten moderne Muster in der Frontend-Entwicklung anwenden. Optimiert Performance, verwaltet State und folgt Best Practices für React und Next.js.