Debugging surveys

From PostHog/posthog · View interactive version

Debugging surveys is an AI agent skill from the GitHub repository PostHog/posthog. Diagnose PostHog Surveys configuration and responses across all five SDKs (web/posthog-js, iOS, Android, Flutter, React Native). Use whenever a Surveys support ticket is pasted ("survey not showing", "fewer responses than expected", "responses disappeared", "responses are incomplete", "only the firs

How to use this skill

Skill file

Debugging surveys

PostHog Surveys is a no-code in-app form builder. A customer creates a survey in the

PostHog UI; it must then be evaluated and rendered by whichever SDK their app runs.

Most "survey not showing" tickets are eligibility problems, not rendering bugs — the

SDK correctly decided the user is not eligible, and the job is to find _which_ gate

failed and _why_.

Access requirements

Use PostHog MCP tools or the survey API to inspect survey configuration and responses.

A checkout of the PostHog repository is not required for these diagnostic steps.

Cross-SDK feature parity (check this FIRST)

A large class of tickets is "customer expects a feature their platform doesn't support."

Confirm the survey's lib / the customer's platform before anything else, then consult

this table. Verified against the SDK source — re-verify if it's been months, the gaps

get filled over time.

| Feature | Web (posthog-js) | iOS | Android | Flutter | React Native |

| -------------------------------- | ------------------------------- | ----------------------------------------- | ---------------------------------- | ---------------------------------- | --------------------------------- |

| Rendering | DOM + shadow root | Native SwiftUI (SurveysWindow) | No built-in UI — delegate only | Dart widgets (SurveyBottomSheet) | RN components (SurveyModal) |

| Event-based triggers | yes (since 1.137.0, 2024-06-05) | yes | yes | yes (native side) | yes |

| URL / screen targeting | yes | decoded but NOT evaluated (// TODO) | decoded but NOT evaluated | NOT evaluated (native gap) | explicitly excluded in filter |

| Feature-flag / cohort targeting | yes | yes | yes | yes (native side) | yes |

| seenSurveyWaitPeriodInDays | yes | yes | yes | yes (native side) | yes (≥ 4.81.5) |

| surveyPopupDelaySeconds | yes | yes (≥ 3.54.0) | yes (≥ 3.49.0) | yes (≥ 5.54.0) | yes (≥ 4.85.0) |

| enable_partial_responses | yes (≥ 1.240.0) | yes (≥ 3.79.0) | yes (≥ 3.70.0) | yes (≥ 5.48.0) | yes (≥ 4.75.0) |

| skipSubmitButton (auto-submit) | yes (≥ 1.244.0) | yes (≥ 3.77.0) | yes (≥ 3.66.4; Compose UI ≥ 0.3.0) | yes (≥ 5.45.0) | yes (≥ 4.26.0) |

The minimum versions match the SDK version warnings in the survey editor.

Consequences worth memorizing:

For a deeper version-by-version capability audit, see the survey-sdk-audit skill if available.

How a survey actually gets shown (the web eligibility pipeline)

The web SDK is the most complex and the most common in tickets. Mental model from

packages/browser/src/extensions/surveys.tsx (checkSurveyEligibility) — checks run in

order, first failure wins:

  1. isSurveyRunning — has start_date, no end_date.
  2. survey type is in-app (Popover / Widget / API).
  3. linked_flag_key enabled (if set).
  4. targeting_flag_key enabled (if set) — customer-defined property targeting.
  5. _internalFlagCheckSatisfied — the auto-generated internal targeting flag.
  6. hasWaitPeriodPassed — seenSurveyWaitPeriodInDays vs localStorage.lastSeenSurveyDate.
  7. getSurveySeen — per-survey seen flag.

Then in getActiveMatchingSurveys: URL/device/selector match, event/action trigger fired, and flag re-check.

Two non-obvious facts that drive real tickets:

How a response actually gets stored

Showing a survey and storing a response are separate pipelines. "Wrong data" tickets are about the

second one, and its UI copy is genuinely misleading — reason from the code, not from the label.

"Response collection" maps to `enable_partial_responses`

The radio in frontend/src/scenes/surveys/SurveyResponsesCollection.tsx. "Any question: when at

least one question is answered…" is true; "Complete survey: the response is stored when all

questions are answered" is false.

question answered, all sharing a $survey_submission_id with $survey_completed running

false ... true.

The setting controls capture, not response visibility. The results include every survey sent

and every survey dismissed or survey abandoned marked $survey_partially_completed = true.

buildMergedSubmissionsSubquery in frontend/src/scenes/surveys/utils.ts merges the latest

answer per question for each submission ID; events without an ID stay separate. **Raw event

counts can exceed response counts.** A completed event takes precedence over earlier partial

closures. Otherwise the outcome chip reads "Dismissed" when the latest response event is a

dismissal, and "Abandoned" for other unfinished submissions. "Abandoned" does not prove a

page-unload event or inactivity timeout occurred; a later completion updates the same row.

The defaults disagree by creation path: NEW_SURVEY sets true

(frontend/src/scenes/surveys/constants.tsx) but the Django model default is False

(products/surveys/backend/models.py). Read it, don't infer it from the creation date.

"All questions answered" does not mean what it says

isSurveyCompleted is getNextSurveyStep(...) === End — **the respondent reached the end of their

own branching path.** Nothing checks that every question holds a value, and two things then blank

out cells on a complete response: questions skipped by branching have no key at all

(onNextButtonClick prunes to visitedIndices before capture, so absent rather than "" or

null), and optional: true questions clicked past are stored as null

(submitDisabled is isNull(rating) && !question.optional).

So on a branching survey with optional tail questions, "only the first question was answered" is

the expected shape of a complete response. Blank ≠ unanswered. Check branching and optional

on every question before believing a bug.

Branching is in the API — read it, don't ask for it

It's questions[].branching, returned verbatim by both the management API and the SDK payload, in

four shapes: next_question, end (the confirmation message), specific_question + index, and

response_based + responseValues. Two traps: for rating questions responseValues is keyed

by _bucket_ (negative/neutral/positive, or NPS detractors/passives/promoters), not by

value; and a bucket missing from responseValues silently falls through to

currentQuestionIndex + 1. So {negative: 3, neutral: 3} on a 5-scale is a complete, working

config that reads like an omission. Bucket boundaries per scale are in

references/reading-responses.md — don't guess them, scale 2 is

inverted.

The event vocabulary

survey shown (fired inside showSurvey() at the moment the popup becomes visible, i.e. after

surveyPopupDelaySeconds, so shown→sent latency is real time-on-popup), survey sent,

survey dismissed (explicit close), survey abandoned (handlePageUnload →

sendSurveyAbandonedEvent). $survey_partially_completed appears on dismissed and abandoned

only, never on sent. All of them carry sessionRecordingUrl, so a disputed submission can often

be watched instead of theorized about. A populated URL only proves a session id was captured,

not that a recording exists: replay is off by default, and the default cloud retention of 30 days is

well short of these queries' 180-day window. Open the link before offering it as evidence.

Read answers with `getSurveyResponse`, never a guessed key

getSurveyResponse(<index>, '<questionId>') is the HogQL helper the product itself reads

answers with (posthog/hogql/functions/survey.py, used across

products/surveys/backend/responses/). Prefer it over hand-writing a property key: response keys

come in three formats, and the helper coalesces the current UUID-keyed one

($survey_response_<questionId>) with the legacy index-keyed one, so it returns what the customer's

own results table shows. Pass true as a third argument for multiple-choice questions. A

hand-written properties.$survey_response_<uuid> misses legacy-keyed answers, and inside a

countIf that silently converts a real answer into "unanswered" and inflates the incomplete ratio.

Whichever you use, the index and id must come from questions[] in the survey JSON. Guessing

which UUID belongs to which question is the fastest route to a wrong conclusion: it reads one

question's answers under another's label, and the resulting ratio looks like a serious bug. If you

have no survey JSON, unroll $survey_questions, which carries the question text alongside the

answer. Formats and templates: references/reading-responses.md,

references/diagnostic-queries.md.

Sanity check the mapping before trusting the numbers: if a column you labeled as a

single-choice question contains free text, the mapping is wrong.

Debugging workflow

  1. Parse the ticket. Extract: org/project ID, instance (US vs EU — URLs differ), survey ID(s), the lib (platform), the symptom in precise terms, and what the customer already tried. If the ticket is aged or has prior support replies, the config may have been edited mid-thread — treat earlier claims as stale and re-pull current state.
  1. Disambiguate "none" vs "fewer." Customers say "no responses" when they mean "fewer." Pull the survey shown vs survey sent counts before/after the suspected change (see references/diagnostic-queries.md). If the _response rate_ (sent/shown) is stable, the problem is upstream eligibility (fewer people shown), not rendering or submission. This single check redirects most investigations correctly.

2b. For a data-quality ticket, disambiguate "incomplete" vs "complete but sparse." Before anything else, check whether the blank cells are questions the respondent was never asked. Branching plus optional questions makes a complete response look abandoned, and this is the single most common reason a survey gets reported as broken when it isn't. See How a response actually gets stored.

  1. Platform parity check. Confirm the lib and consult the parity table. Eliminate features the platform doesn't support before investigating them.
  1. Pull the survey definition. GET /api/projects/<id>/surveys/<sid>/. Inspect conditions (events, url, seenSurveyWaitPeriodInDays, repeatedActivation), appearance.surveyPopupDelaySeconds, appearance.position, schedule, linked_flag, targeting_flag, internal_targeting_flag.filters, responses_limit, iteration_*, enable_partial_responses — and then go inside each question: id, type, scale, optional, skipSubmitButton, branching. The per-question fields answer most "wrong data" tickets on their own and are easy to miss, since a shallow look at top-level keys doesn't surface them.
  1. Pull the targeting-flag activity log for any "stopped showing" ticket. Cohort swaps and rollout changes are invisible in the current config but show up here: GET /api/projects/<id>/activity_log/?scope=FeatureFlag&item_id=<flag_id>&limit=20. Also ?scope=Survey&item_id=<sid> to see whether the survey itself was edited.
  1. Confirm with events. Use $feature_flag_called to see what the gating flag actually returned for affected users, and whether $groups is set (see group-aggregation cause below). Use survey shown to see real reach vs the stats UI.
  1. Diagnose against the known-cause catalog, confirm with one targeted query, then write the reply.

Before you call it an SDK bug

These tickets attract a specific failure mode: the symptom looks impossible, so the SDK gets blamed

and the customer is told to pause the survey, file a bug, and rebuild their questions. That advice

is expensive and hard to walk back — restructuring destroys the comparability of every response

already collected, and reordering questions risks the UUID problem below. Clear all four gates

before writing "this is a bug":

  1. Read the survey JSON, per-question branching, optional, skipSubmitButton and scale included. Most "impossible" behavior is configured behavior.
  2. Reproduce it in Preview.
  3. Read the SDK source for the handler you're accusing. Grep the symbol; don't reason from what a setting is named. enable_partial_responses and "all questions answered" both mean something narrower than they sound.
  4. Re-check your own query before trusting a shocking ratio. "89% of responses are incomplete" is more often a bad response-key mapping than a real defect.

If it survives all four it's a bug: name the file and handler, and file it upstream.

Known-cause catalog

Ordered roughly by how often they're the answer.

"Survey shows to fewer users than expected"

"Event-based survey never fires"

"Responses are incomplete — only the first question has a value"

Usually not a bug — see How a response actually gets stored. Work these four first; only then is the completion condition genuinely not being honored.

"The respondent says they didn't mean to submit"

"Responses show as zero in the UI but raw events exist"

"Cohort count shows 0 but the cohort is populated"

General caution

Diagnostic queries

Read-only HogQL templates for the disambiguators and confirmations above live in

references/diagnostic-queries.md. Run them via the

PostHog MCP execute-sql against the customer's project.

Access for debugging

Only investigate a project tied to a genuine support request from that customer — the IDs

should come from a real ticket, not from someone asking you to look up an org/survey they

can't point to a request for. Staff access is broad; don't freelance across projects.

Prefer read-only paths in this order:

  1. PostHog MCP tools (survey, feature-flag, cohorts, execute-sql, activity-log, persons) against the customer's project. This is read-only by default and the safest way to inspect config and run queries — no impersonation, no write risk. Use this first.
  2. Survey/flag API endpoints read via the browser while impersonating (staff). Good for the full JSON the MCP may not surface verbatim (e.g. raw internal_targeting_flag.filters).
  3. Django admin only when 1 and 2 can't answer it. It's powerful and write-capable, so treat it as read-only by discipline: look, don't change. Never edit a customer's survey/flag/cohort from admin without explicit customer consent.

When you need a value the MCP can't infer (project ID, instance, which survey), ask the

operator to paste the survey API JSON — it skips several round-trips.

Writing the customer reply

Voice derived from the PostHog handbook support values (reassuringly human, humble, ship

fixes, clear with no jargon). Rules:

Reply skeleton:

Hi <name>,

<one line: tracked it down + the cause in plain terms.>

**The problem:** <what's happening, with the evidence you pulled.>

**<Fastest fix / two ways to fix it>:**
1. **<action>** — <why / how.>
2. **<action>** — <why / how.>

**Also worth knowing while you're in there:** <secondary finding, softened.>

We're always here if you need a follow-up.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.