Surveys
Ask visitors a question inside your app, such as "How likely are you to recommend us?" after checkout or "What stopped you?" on the pricing page, and read the answers in the same console as your analytics. Answers are ordinary analytics events, so there is no second store to run.
Surveys are Beta, see what Temps supports. The question types and display conditions may still change. The SDK that shows them and the surveys CLI commands are in the beta packages: @temps-sdk/react-analytics@beta, @temps-sdk/analytics-core@beta and @temps-sdk/cli@beta. The stable releases don't have them yet.
Surveys need analytics to be on for your site.
- Five question types: NPS, rating (3, 5, 7 or 10 points), single choice, multiple choice and open text.
- Show a survey on a page pattern, after an event, to a share of visitors, or only where a feature flag serves a value you choose.
- Once per visitor, or every time.
- A built-in widget, or only the definitions so you can draw your own interface.
- Results per survey: response rate, the spread of answers for each question, the average and the NPS score.
Create a survey
Open a project, then Analytics → Surveys → New survey. A new survey is a draft. Nobody sees it until you Launch it.
From the CLI, questions are a JSON array:
cat > questions.json <<'JSON'
[
{ "id": "nps", "kind": "nps", "prompt": "How likely are you to recommend us to a friend?" },
{ "id": "why", "kind": "open_text", "prompt": "What is the main reason for your score?", "optional": true }
]
JSON
bunx @temps-sdk/cli@beta surveys create "Checkout feedback" --questions @questions.json \
--targeting '{"path_pattern": "/checkout/*", "trigger_event": "checkout_completed"}'
bunx @temps-sdk/cli@beta surveys launch 1
| Kind | Answer | Options |
|---|---|---|
nps | A whole number from 0 to 10 | lower_label, upper_label |
rating | A whole number from 1 to scale | scale: 3, 5, 7 or 10 (default 5), and labels |
single_choice | One of choices | choices: 2 to 20, all different |
multiple_choice | Any of choices | choices |
open_text | Up to 2,000 characters | None |
A question's id (a-z, 0-9 and _) is the key its answer is stored under. Keep it when you reword the question, so old and new answers are counted together.
A survey can have up to 20 questions. A project can have at most 50 active surveys, and a survey's questions and display conditions can take up to 16 KiB together.
When a survey is shown
| Condition | Field | Decided by |
|---|---|---|
| Page | path_pattern, for example /checkout/* (* matches anything, empty means every page) | The browser |
| After an event | trigger_event: the name you pass to trackEvent (empty means on page load) | The browser |
| Once per visitor | once_per_visitor (on by default), remembered in localStorage. In cookieless mode nothing is stored on the device, so it means once per page load | The browser |
| Share of visitors | sample_rate, from 0 to 1 (default 1) | The server |
| Feature flag | flag: { "key": "checkout.v2", "value": true } | The server |
Sampling is sticky: the same visitor is always in or out of a survey's sample. Below 100%, only visitors Temps can recognise are sampled, through the visitor cookie or a key you pass. Anyone else doesn't see the survey.
A flag condition is evaluated with the same rules, environment and attributes as the feature flag itself. If the flag doesn't exist, is archived or can't be evaluated, the survey is not shown. The server never sends a survey's sample rate or flag condition to the browser, only the surveys this visitor should see.
Show surveys in your app
The analytics SDK fetches surveys from your own origin (POST /api/_temps/surveys), with no key and no CORS. It records answers as analytics events, so surveys appear only where analytics is enabled. That excludes localhost unless you set ignoreLocalhost={false}.
React
Place <TempsSurveys /> once inside the analytics provider:
import { TempsAnalyticsProvider, TempsSurveys } from '@temps-sdk/react-analytics'
import { usePathname } from 'next/navigation'
export function Providers({ children }: { children: React.ReactNode }) {
return (
<TempsAnalyticsProvider>
{children}
<TempsSurveys pathname={usePathname()} />
</TempsAnalyticsProvider>
)
}
Pass your router's path so a survey for /checkout/* appears on client-side navigation. A survey with a trigger_event opens when you call trackEvent with that name. visitorKey (for example a signed-in user id) and attributes feed sampling and the flag condition. When either changes, for example when a user signs in, the surveys are fetched again for the new visitor.
Any page
import { createAnalytics } from '@temps-sdk/analytics-core'
const analytics = createAnalytics({ surveys: { enabled: true } })
The built-in widget opens on load, on navigation and after a matching trackEvent. To draw your own interface, set autoShow: false and use analytics.surveys:
const analytics = createAnalytics({ surveys: { enabled: true, autoShow: false } })
await analytics.surveys.load()
const [survey] = analytics.surveys.eligible(location.pathname)
if (survey) {
analytics.surveys.markShown(survey)
// ...render survey.questions, then:
const result = analytics.surveys.submit(survey, { nps: 9, why: 'Fast checkout' })
if (!result.ok) console.log(result.errors) // one error per question id
}
If the surveys request fails, nothing is shown and a later load() tries again.
Answers are events
| Event | When | Properties |
|---|---|---|
survey_shown | The survey was displayed | survey_id, survey_name |
survey_dismissed | Closed without answering | survey_id, survey_name |
survey_sent | Answered | survey_id, survey_name, responses (question id to answer) |
They go through the same ingest path as your other events and count toward the same limits. You can break them down, use them as funnel steps, or query them like any other event. Deleting a survey removes its definition and its results page. The events already recorded stay.
Read the results
A survey's page shows, for the last 7, 30 or 90 days:
- Shown, answered, dismissed and the response rate (answered divided by shown).
- Per question: how many answered, the count and share of each choice or score, the average for scales, and the NPS (the percentage of 9 and 10 scores minus the percentage of 0 to 6).
- Responses, newest first, each with the page it was answered on and a link to the visitor.
Answers that no longer match a current choice, because the question changed after they were given, are counted as other and not dropped.
bunx @temps-sdk/cli@beta surveys results 1 --days 30
bunx @temps-sdk/cli@beta surveys responses 1 --environment production --json
The other surveys commands are list, get, update, launch, pause, complete and delete.
Permissions and limits
- Reading surveys needs
surveys:read. Creating, editing and deleting needssurveys:write. Deployment tokens can't change surveys. - Every change is in the audit log with its status, question count and display conditions before and after.
- The browser endpoint resolves the project from the request's
Hostand returns only the active surveys the visitor should see. It is limited to 30,000 requests a minute per project and 600 per client address, and answers429above that. Requests are capped at 16 KiB. - Survey definitions are cached in memory for at most 5 seconds, so a change is live on the next request on a single server.