Build a product quiz for a Shopify store
The merchant writes questions in the admin and points each answer at products; shoppers take the quiz from a theme block and land on their matches, rendered in the theme. It needs no Shopify scopes: the block renders from an app-data metafield, and the app proxy does the rest.
What you'll build
What it shows: Publishing app data to an app-data metafield, a theme block that is a plain Liquid form with no script, and results answered as Liquid through the app proxy.
Before you start
- The CLI:
npm i -g @inferencebureau/apps, thenib-apps loginonce. - A Shopify Partner organization, and a development store to install on.
- Resend, for data requests.
Create the app from the recipe
One command creates the app on Inference Bureau and downloads its files into ./my-quiz. Shopify recipes need --platform shopify.
ib-apps create my-quiz --platform shopify --recipe quizTour what the recipe loaded
The recipe lies over the Shopify starter: files of the same path are replaced, and the starter's storefront block is dropped. Here's where each piece lives.
| Where | What's there |
|---|---|
api/models/quiz/, api/lib/quiz.ts | The quiz model (one per store) with questions as JSON, checked on save; ids are kept across edits and never reused. |
actions/publish.ts, unpublish.ts, update.ts | Publish writes the questions, without their products, to app.metafields.quiz.definition; Unpublish deletes it; an edit republishes a live quiz, and so does a reinstall. |
extensions/quiz/ | The Product quiz block: a form rendered in Liquid, posting to the app proxy. |
web/app/proxy/quiz/, api/models/quizResponse/ | quizResponse.create scores the answers against the live quiz (top 3 products), then redirects to a results page answered as Liquid with all_products. |
api/actions/shopifyCustomers*.ts | Shopify's privacy webhooks: customers/redact deletes the customer's responses, for a customer who took the quiz signed in; customers/data_request emails them to the store's owner through the team's own Resend account. |
tests/quiz.test.ts | The actions, scoring and publishing, with the Admin API mocked. |
{%- liquid
assign quiz = app.metafields.quiz.definition.value
assign proxy = app.metafields.ib_app.proxy_path.value
-%}
{%- if quiz.questions.size > 0 and proxy != blank -%}
<form class="ibq" method="post" action="{{ proxy | escape }}/quiz">
<input type="hidden" name="return_to" value="{{ request.path | escape }}">
{%- for q in quiz.questions -%}
<fieldset><legend>{{ q.text | escape }}</legend>
{%- for a in q.answers -%}
<label><input type="radio" name="q_{{ q.id | escape }}" value="{{ a.id | escape }}" required> {{ a.text | escape }}</label>
{%- endfor -%}
</fieldset>
{%- endfor -%}
<button type="submit" class="button">{{ block.settings.submit_label | escape }}</button>
</form>
{%- endif -%}Check what it set on the app
Nothing to do here: this is what the recipe configured, so you know where to look in Settings later.
customers/redact, customers/data_requestConnect Shopify and install
- Create the Shopify app in your Partner organization
- Install on a development store
- Write the questions in the admin and publish; add the Product quiz block in the theme editor
Run it
ib-apps dev syncs both ways while you work and runs the development server. Saving anything under extensions/ releases it to the development Shopify app by itself.
cd my-quiz
ib-apps devLogs show a succeeded config release once the extension is live.
Try it end to end
Make it yours
extensions/quiz/assets/quiz.css and blocks/product-quiz.liquid.
It's in api/models/quizResponse/; run ib-apps test after.
ib-apps test runs its tests, then ib-apps deploy sends development to production. See Deploys.