Skip to content

feat(brands): detect the site type when a brand is created, and say so in Brand settings - #1767

Merged
gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/site-type-detection-web
Oct 29, 2026
Merged

gkhngyk merged 6 commits into
ansvisor:mainfrom
cihan-gyk:feature/site-type-detection-web

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Step 0, web part: call the site type detection (#1761) when a brand is created, and say in Brand settings when the type was detected.

  • ai-brand-setup.ts: new detectSiteType(brandId) calls POST /api/brands/:id/detect-site-type.
    • A 429 onboarding_daily_limit becomes SetupDailyLimitError.
    • An unknown type or skipped gives { siteType: null, industry: null }.
  • Onboarding and Brands › Add a brand: after createBrand succeeds, detection runs in the background (void detectBrandType(brand.id)), so setup never waits.
    • The result updates the created brand and the brand store: siteType, siteTypeSource: 'auto' and the industry when one comes back.
    • An error is logged and the guess stays.
    • Onboarding sends onboarding_site_type_detected.
  • markBrandAsEcommerce runs when competitor research finds a shop. It now also sets the type to e-commerce, unless a person picked one, and stamps site_type_detected_at, which keeps it auto. RLS refusing the row is an error. It returns siteType for both pages' stores.
  • Brand settings › General: with an automatic type the form hasn't changed, the hint adds "Detected automatically from your website. Pick another if it's wrong." (brands.settings.siteTypeDetected). Saving another pick makes it manual through feat(brands): detect a brand's site type and industry from its home page #1761's trigger.
  • Types:
    • Brand.siteTypeSource;
    • site_type_source and site_type_detected_at in supabase.ts.
  • Docs: content-editor.mdx › Site type covers detection, the switch to e-commerce with a catalog, and that a manual pick never changes.

Related issue

None (AC business-type action plan, step 0).

Stacked on #1761 (detection, server and 00379). The diff against it holds only this change.

Type of change

  • feat — New feature

How to test

  1. Apply 00379 and run the server from feat(brands): detect a brand's site type and industry from its home page #1761.
  2. Add a brand (onboarding or Brands › Add a brand) for a shop's domain. Within seconds Brand settings › General › Site type shows E-commerce with "Detected automatically…".
  3. Pick another type and save. The note goes, and running detection again leaves the type alone.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: format, lint (0 errors, 7 warnings), typecheck, 555 test files / 5,322 tests and build pass
  • Tests added or updated (setup client, markBrandAsEcommerce, Add a brand, onboarding, read-only)
  • Browser check of the hint, light and dark at 1024 px: in the next batched local test

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits October 29, 2026 14:14
Step 0 of the action plan by business type. A brand's site type was only
ever chosen by hand, and the app guessed B2B for nearly everyone, shops
included: page types, quality rules and opportunities all read it.

- site-type-detect.js reads the brand's own home page (free): products, a
  cart and checkout make a shop; a demo, seat pricing or trial a SaaS;
  bookings a consumer service. When the page doesn't settle it, one small
  model call (SITE_TYPE_MODEL) names the type and the industry from the
  app's list.
- POST /api/brands/:id/detect-site-type keeps the result, for admins and
  managers; it counts among onboarding's daily calls for a workspace that
  never subscribed.
- 00379: brands.site_type_source (auto | manual) and site_type_detected_at.
  A trigger marks any type change that doesn't stamp a detection as a
  person's, so a manual choice always wins; another makes a brand with a
  new catalog source a shop, unless a person chose its type. Existing
  types are marked manual; brands with a catalog become shops.
- scripts/detect-site-types.js detects the brands that have no type yet
  (--limit, --dry-run), printing counts only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ger signs

Review follow-ups on the site type detection.

- Detection only fills an empty type now: a type a person chose, or one a
  catalog or an earlier detection set, is left alone (skipped 'manual' or
  'set'). A brand in Shopping mode becomes a shop without a read, and
  00379 types the brands already in Shopping mode as shops too, so a shop
  can't be detected back to B2B. The industry is written by its own update,
  only while still empty.
- A shop platform counts from asset addresses, classes and scripts, never
  the page's words (an agency writing "we build WooCommerce stores"); an
  offer counts only on a product, not an event, a course or a product only
  reviewed; a shop needs two signals of its own. Scripts and styles are
  left out of the words read.
- The home page is read at the host as added, then with "www."; the model
  call has a 30 s limit.
- Nothing is stamped when the type can't be told, so a later try reads the
  brand again. The backfill skips inactive brands and organizations without
  an active plan, logs each failure, and asks no model on a dry run.
- The catalog trigger runs as the person who adds the source (admins and
  managers may update the brand too), not as its owner.
- Route tests: roles that may not change a brand get 403, another
  organization's brand 404.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in its settings

Step 0, web side. Right after onboarding or "Add a brand" makes the brand,
setup asks the API to detect its kind of site from its home page (in the
background; setup never waits on it, and the app goes on guessing when it
can't tell), and takes the type and industry into the brand.

- Setup's competitor research finding an online store is a detection too:
  markBrandAsEcommerce now also makes the site type e-commerce, stamped as
  detected, unless a person chose one.
- Brand settings say "Detected automatically from your website. Pick
  another if it's wrong." under a type that was detected; choosing another
  makes it the person's (00379's trigger).
- Brand.siteTypeSource, the types for 00379's columns, the content-editor
  guide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 28f75e6.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
Wrapping each element in $(el), and removing scripts and styles one by
one, grow with the square of the page's elements: a page of tens of
thousands of them took seconds to a minute. The links, traces and
visible text are now read straight off the parsed elements.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with 6c1d342: that's this PR's head with my #1761 change merged in (one-pass page reading). Nothing in this PR's own diff needed changing.

What I checked (this PR's own diff against #1761)

  • Setup. Both the onboarding wizard and the new-brand page call detectBrandType in the background right after createBrand returns. createBrand inserts the domains before it returns, so the server sees the domain. A failure is caught and logged, and setup goes on. A result only updates the store when it's for the brand being set up.
  • markBrandAsEcommerce. It still starts with assertWritable({ onboarding: true }). It writes site_type = 'ecommerce' with site_type_detected_at, so the 00379 trigger keeps it auto, and it does that only when the type isn't manual and isn't already ecommerce. An update that touches 0 rows throws, as the industry write does. A brand already in Shopping mode still keeps its industry and mode, and now gets the type too.
  • Brand settings. "Detected automatically…" shows only while the select still holds the stored type and its source is auto. Picking another type hides it, and saving marks it manual through the trigger.
  • mapBrandRow. It maps site_type_source only to auto/manual. The brand reads already select *, so no select changed.
  • Read-only workspace. No new server action. read-only.test.ts and subscription-guard-coverage.test.ts pass.
  • No PostgREST embeds are added or changed (the existing brand_domains(*) embed is untouched).
  • Copy: the new en.json line and the content-editor doc change read well.
  • Tests: the onboarding and new-brand page tests, brand-ecommerce, read-only, ai-brand-setup and the subscription guard pass (37). Web tsc passes. The server suite runs as noted on #1761.
  • Merges clean on current main, and build-schema.sh leaves schema.sql unchanged on the merge.

Follow-up

  1. onboarding_site_type_detected is tracked in the wizard but not on the new-brand page. That's fine if that's on purpose (other events differ between the two pages too).

@gkhngyk
gkhngyk merged commit 0c0810c into ansvisor:main Oct 29, 2026
5 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
gkhngyk added a commit that referenced this pull request Oct 29, 2026
…1778)

#1761 and #1767 read brands.site_type_source and write
site_type_detected_at (00379). If the code is deployed before the
migration, markBrandAsEcommerce threw during onboarding's competitor
step for any shop, and detection errored. Both now treat Postgres'
undefined-column error (42703) as 'not yet': Shopping mode still goes
on and the site type is left for detection once 00379 is applied.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants