Add Picked to your application
In this tutorial we make a color survey and put it on a page. We build the flow in the Picked dashboard, connect the SDK to it, and see the survey in a browser.
At the end you have one experience, one step, one field, and a page that shows them.
Before you start
- A Picked account, and an organization in it.
- Node 20 or later.
- A web application that runs React or Svelte. A new Vite application is enough.
1. Make a project
A project is one site or one application.
- Sign in to the dashboard.
- Open your organization.
- Click New Project.
- Enter the name
Tutorial. - Click Create.
The project home page opens. It shows a project ID near the top. Copy that ID. Every step after this one needs it.
2. Make a field
A field collects one answer from your visitor.
- Click Fields in the sidebar.
- Click New field.
- Enter the name
Color. The dashboard fills in the label and the key for you. - Change the label to
Which color do you like most?. - Leave the key as
color. - Choose the type Text.
- Click Create field.
The field now appears in the fields list.
3. Make the experience
- Click Flows in the sidebar. The experiences list opens.
- Click New experience.
- Enter the name
Color survey. - Leave Type on the Flow option.
- Open Advanced.
- Enter the component name
ColorSurvey. - Click Create flow.
The flow builder opens with an empty canvas. One gray circle is on the left. That circle is the origin, and every flow starts there.
4. Make a step
A step is one screen that your visitor sees. It holds your field. You make one from the library, on the left of the flow builder.
- Find the Steps section in the library.
- Click the + next to it.
- Enter the name
Question. The key fills in asquestion. - Click Create step.
The flow builder opens again, and your step is in the library.
5. Build the flow
- Find your
Questionstep in the library on the left. - Drag it onto the canvas.
- Drag from the output handle of the origin to the input handle of your step. An arrow joins them.
- Drag your
Colorfield from the library onto the step node. - Click Save in the toolbar.
The subtitle of the step node now reads one field. Your flow is one step long, and it starts at the origin.
6. Publish the workspace
Your visitors see nothing until you publish.
- Click Publish in the workspace toolbar.
- Read the change preview.
- Click Publish to confirm.
7. Connect the SDK
Install the client and the adapter for your framework.
npm install picked @picked/reactnpm install picked @picked/svelteNow write the component that renders the step. Put it in ColorSurvey.tsx, or in
ColorSurvey.svelte. It reads the fields of the active step and
puts each one in a form.
import { useStep, useStoreGlobal } from '@picked/react/hooks'
export function ColorSurvey() {
const { fields, form } = useStep()
const currentFields = useStoreGlobal(fields)
return (
<form {...form.props}>
{currentFields.map((field) => (
<div key={field.id}>
<label htmlFor={field.id}>{field.label}</label>
<input
id={field.id}
name={field.id}
value={field.value ?? ''}
onChange={field.onChange}
onBlur={field.onBlur}
/>
</div>
))}
<button type="submit">Continue</button>
</form>
)
}<script lang="ts">
import { getStep } from '@picked/svelte/hooks'
const { fields, form } = getStep()
</script>
<form {...form.props}>
{#each $fields as field}
<div>
<label for={field.id}>{field.label}</label>
<input
id={field.id}
name={field.id}
value={field.value ?? ''}
onchange={field.onChange}
onblur={field.onBlur}
/>
</div>
{/each}
<button type="submit">Continue</button>
</form>Then start the client from picked.ts. Put your project ID in projectId. The key in components must
match the component name that you entered in step 4.
import { createClient } from 'picked'
import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
import { adaptReactComponent } from '@picked/react'
import { reactFrameworkPlugin } from '@picked/react/plugins/framework'
import { ColorSurvey } from './ColorSurvey'
export const picked = createClient({
projectId: 'your-project-id',
components: {
ColorSurvey: adaptReactComponent(ColorSurvey),
},
plugins: [reactFrameworkPlugin({ components: {} }), dynamicExperiencesPlugin()],
})
picked.start()import { createClient } from 'picked'
import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
import { adaptSvelteComponent } from '@picked/svelte'
import { svelteFrameworkPlugin } from '@picked/svelte/plugins/framework'
import ColorSurvey from './ColorSurvey.svelte'
export const picked = createClient({
projectId: 'your-project-id',
components: {
ColorSurvey: adaptSvelteComponent(ColorSurvey),
},
plugins: [svelteFrameworkPlugin({ components: {} }), dynamicExperiencesPlugin()],
})
picked.start()dynamicExperiencesPlugin reads the published configuration of your project. It registers your
experience, your step, and your field. You declare none of them in code.
8. See it
Start your application and open it in a browser.
Your survey appears. It shows the label Which color do you like most? and one text
input. Both come from the dashboard, and neither is in your code.
9. Change it without a deployment
This step shows you what the dashboard controls.
- Go back to the dashboard.
- Open your
Colorfield. - Change the label to
Which color do you like least?. - Click Save.
- Publish the workspace again.
- Open the page in your browser again.
The question changes. You edited no code and you deployed nothing.
What you built
You have an experience that you control from the dashboard and render in your own application. The dashboard holds the flow, the step, and the field. Your code holds only the component and the client.
To change the label, the field type, or the order of the steps, edit the workspace and publish again. You deploy no code.
Where to go next
- Your first server-rendered page — a page that a search engine can read.
- How to build a flow — branches, actions, and conditions.
- About how Picked works — what happens between publish and render.
