Skip to content

feat(tracking): capture Perplexity shopping_cards data into prompt_results #46

Closed

Description

@gkhngyk

What

When Perplexity detects shopping intent on a prompt (e.g.
"best running shoes under $150"), it returns a structured
shopping_cards array alongside the usual text + sources. We
currently throw that array away. This issue captures it end-to-end
so the data lands in prompt_results for future use.

Scope is intentionally narrow: data capture only. No UI, no
scoring changes, no brand-presence detection inside the cards. A
dedicated "Shopping" sidebar surface will land in a separate feature
once the data has been collecting for a while and we can design
against real readings.

Why now

Shopping cards are the highest-commercial-intent visibility signal
Perplexity exposes — a product appearing in a card gets clicks the
same way the citation list does. Capturing it now means by the time
the UI lands, every tracking run already has historical data behind
it. If we wait, we lose all retrospective insight.

Data shape (from the Cloro Perplexity endpoint)

Cloro returns result.shopping_cards as an array of card objects,
each with products[] and optional tags[]. See Cloro's shopping
cards endpoint docs

for the full schema — relevant fields per product include title,
url, description, price, original_price, rating,
numReviews, imageUrls, merchant, id, variants, offers.

We store the whole shopping_cards array verbatim as JSONB. No
flattening, no transformation — preserves every field for future
analysis without another schema change.

Where to change

1. Migration

Add supabase/migrations/00005_prompt_results_shopping_cards.sql:

-- Capture Perplexity shopping cards alongside text + citations so the
-- commerce-intent signal isn't lost. Other AI providers leave this
-- empty; only Perplexity populates it today.

ALTER TABLE "public"."prompt_results"
  ADD COLUMN IF NOT EXISTS "shopping_cards" jsonb
    NOT NULL DEFAULT '[]'::jsonb;

Follow the same pattern used by citations and competitor_mentions
on the same table (both are jsonb NOT NULL DEFAULT '[]').

(The maintainer applies this via Supabase Studio after merge.)

2. Supabase types

Update web/src/types/supabase.ts — find the prompt_results table
definition and add shopping_cards: Json (and shopping_cards?: Json
for Insert/Update). The Json type is already declared at the top of
the file.

3. Cloro parser

server/src/lib/cloro-scraper.js — in the function that builds the
parsed response object (currently { text, citations, model }), add
shopping_cards. For the Perplexity branch:

return {
  text,
  citations,
  model,
  shopping_cards: result.shopping_cards ?? [],
};

For the other scraper branches (ChatGPT, Gemini, AI Overview, AI
Mode, Claude, Copilot), return shopping_cards: [] so the field is
always present on the parsed object — keeps downstream typing
trivial. Update the JSDoc return type comments to include the new
field.

4. Result handler (writes to DB)

server/src/lib/cloro-result-handler.js — in the prompt_results
insert (around the existing citations: aiResponse.citations line),
add the field:

shopping_cards: aiResponse.shopping_cards ?? [],

That's the entire pipeline change — capture from Cloro → pass
through parser → write to DB.

How to verify

  • Migration applies cleanly (column appears on prompt_results,
    existing rows have '[]' defaulted in)
  • Trigger a tracking job for a brand with a clearly
    shopping-intent prompt (e.g. "best running shoes under
    $150"
    ) and confirm the resulting prompt_results row has a
    non-empty shopping_cards array containing products with
    title, price, etc.
  • Trigger a tracking job for a non-shopping prompt on Perplexity
    → shopping_cards is [] (Perplexity didn't return cards,
    which is correct)
  • Trigger a tracking job on a non-Perplexity scraper (ChatGPT,
    Gemini, etc.) → shopping_cards is [] (those providers
    don't have the concept)
  • prompt_results rows from before this change still load
    correctly — the default '[]' backfill means they don't break
    any reads

Out of scope (explicitly future)

  • UI to display shopping cards — separate "Shopping" sidebar feature
    is planned, deliberately not in this PR
  • Visibility score changes / shopping-card bonus
  • Brand-in-shopping-cards detection (matching merchant or url
    against brand domains) — needs UI alongside it
  • Aggregated insights / metrics about shopping presence
  • MCP / REST API exposure of the new field

Contribution guide

See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions