Category pages, navigation and filters that help people find
TL;DR
Difficulty: Intermediate
People find the right product when the shop is organised the way they think.
- Build the category tree from a card sort with 15 customers, then check it with a tree test.
- Categories are kinds of thing, properties are filters. Do not split what people want to compare.
- Each product card shows the one detail that decides, such as height or width.
- Offer the four sorts people expect and a smoothed default that is fair to new products.
- Filters combine with OR inside a facet and AND across facets, show honest counts and need complete data first.
- Use a load more button that keeps people's place, and keep filtered addresses away from crawlers.
- Measure the list click through rate and put a euro figure on each fix.
What to read first
Most visitors to an online shop browse before they buy, and many of them never open a single product from the category list they land on. This chapter takes the browsing path apart piece by piece, from the shape of the category tree to the code behind a filter click, with an invented homeware shop in Limerick worked through at every step.
Most visitors browse before they buy
Someone arrives at your shop wanting "a lamp for the reading corner". They do not know your product names. They do not know that you file it under "Lighting", then "Floor lamps", then "Arc lamps". They have a picture in their head, a rough budget and a room with a socket in an awkward place. Your job is to get them from that picture to the right product page in as few confident steps as possible.
There are two ways to do that. One is the search box, which gets its own chapter, site search that sells. The other is browsing: the main menu, the category pages, the product cards on them, the sort order and the filters. This chapter is about browsing, from the shape of the category tree down to the Ruby code that answers a filter click, and how to measure whether any of it works.
A few words first, because they come up all the time:
- Information architecture is the way your products are grouped and labelled: which categories exist, what they are called and what sits inside each one.
- A category page (also called a product list page) shows the products in one category, as a grid of product cards.
- A facet is one property of a product that people can narrow by, such as colour or material. A filter is the control on the page that applies it. "Faceted navigation" means narrowing a list by several facets at once.
- Sorting changes the order of the list without removing anything. Filtering removes what does not match.
If you have not read the first chapter of this series, the eCommerce funnel, stage by stage, it explains how to find where a shop loses people. This chapter goes deep on one of those stages: the walk from landing to a product page.
Example: how Shannonside Home's visitors reach a product
All numbers in this chapter's examples are invented. Shannonside Home is an online homeware shop in Limerick (shannonsidehome.example). Niamh owns it, Callum is her developer. It sells about 1,400 products in four ranges: ceramics, kitchen textiles, lamps and small furniture. The shop has 110,000 sessions a month, a conversion rate of 1.8%, an average order value of €84 and a gross margin on product of 52%. That makes about 1,980 orders a month.
Callum pulls one month of sessions and splits out the browsing path:
| Step | Sessions | Share of the step before |
|---|---|---|
| All sessions | 110,000 | |
| Saw at least one category page | 63,800 | 58.0% |
| Clicked from a list into a product page | 36,370 | 57.0% |
| Added something to the basket | 5,820 | 16.0% |
| Placed an order | 1,250 | 21.5% |
So 1,250 of the 1,980 monthly orders come from sessions that browsed a category. Browsing is the main road into this shop, not a side street. And 43% of the sessions that saw a category list never opened a single product from it. That second number is where this chapter starts.
Build the category tree from how customers think
The most common reason people fail to find a product is not a slow page or an ugly grid. It is a category tree built from how the business thinks: supplier ranges, warehouse zones, the buyer's spreadsheet. Customers bring their own mental model, and when the two do not match they guess, click the wrong branch and leave.
There are two research methods for this, and both are inexpensive.
Card sorting asks people to group your products into piles that make sense to them. Nielsen Norman Group describe it as a research method in which participants place cards, each with one label, into groups that make sense to them1. In an open card sort, participants make and name their own groups, which shows you how they think. In a closed card sort, you give them your categories and they place the cards, which checks a structure you already have. A hybrid sort gives some categories and allows new ones.
How many people do you need? Jakob Nielsen looked at data from Tullis and Wood and found that the results from five users correlate only 0.75 with the final results, while 15 users reach 0.90 and 30 users 0.95. His recommendation is to test 15 users2. A later Nielsen Norman Group article keeps 15 as the minimum for a qualitative card sort and suggests 30 to 50 when you need numbers that generalise1.
Tree testing checks a finished tree. Participants see only the text labels of your categories, no design, and get tasks such as "where would you find a lampshade for a floor lamp?". You measure how many find the right place (the success rate) and how many go there directly without backtracking (directness)3. Card sorting helps you build the tree. Tree testing tells you whether it works.
Example: an open card sort for Shannonside Home
Niamh writes 40 typical products on cards: a stoneware mug, a linen tea towel, a table runner, a brass table lamp, a plant pot, a side table and so on. Fifteen customers from her newsletter sort them online and name their groups. For each card, Callum works out the agreement, the share of participants who put it in the most popular group:
where is the agreement for card , is the number of participants who put card in its most common group, and is the number of participants. It is a simple share, explained in Foundations: ratios and rates.
The table runner: 9 people put it with kitchen textiles, 5 with "dining" and 1 with gifts.
So : a clear majority, but not a landslide.
The plant pot: 7 put it with ceramics, 6 with "home accents", 2 with gifts.
So : fewer than half agree.
Niamh's rule is simple. Above 0.70, the card goes in one obvious place. Between 0.50 and 0.70, it goes in its main place and gets a link from the second one. Below 0.50, people are genuinely split, so the product lives in both categories. Solidus, like most shop systems, lets one product sit in several categories, so this costs nothing.
Then a tree test with 15 new participants and the task "find a lampshade for a floor lamp". Eleven find it, so the success rate is . Only six go there directly, the rest try "Lamps" first and then backtrack. The label "Lighting accessories" means nothing to them. Renamed to "Lampshades and bulbs" and tested again, 14 of 15 find it.
Categories or filters: do not split what people want to compare
Here is a mistake that looks tidy in a spreadsheet: turning every property into a category. "Lamps" becomes "Brass lamps", "Ceramic lamps", "Rattan lamps". It feels organised. It is a trap, because a customer who wants a lamp under €90 now has to open three lists and compare them in their head.
Baymard Institute's navigation benchmark calls this overcategorisation and finds that 79% of sites use categories where filters should be used. In their words, "Presenting filters as mutually exclusive categories prevents users from refining the product list"4. The same research found that most participants began to feel overwhelmed when they were offered more than about 10 subcategories to choose from4.
The test is easy. A category answers "what kind of thing is it?" (a lamp, a mug, a side table). A filter answers "which one of these do I want?" (brass, under €90, in stock). If a customer would ever want to compare across the split, it is a filter.
Example: the lamps category at Shannonside Home
Shannonside's lamps range has 186 products in nine subcategories: table lamps, floor lamps, brass lamps, ceramic lamps, rattan lamps, kids' lamps, outdoor lamps, lampshades, and bulbs. Callum sorts them with the test above:
- Table lamps, floor lamps, outdoor lamps: kinds of thing. They stay as categories.
- Lampshades and bulbs: kinds of thing, and the tree test said so. One category, "Lampshades and bulbs".
- Brass, ceramic, rattan: materials. They become values of a "Material" filter.
- Kids' lamps: a theme, not a kind. It becomes a value of a "Room" filter (living room, bedroom, kids' room, home office).
Nine subcategories become four, each with the same set of filters. A customer who wants "a brass floor lamp" now opens Floor lamps, ticks Brass and sees every match in one list, instead of guessing whether to start with "brass" or "floor".
The main menu on a large screen
The main menu does two jobs: it shows what the shop sells at a glance, and it lets people jump straight to a category. On a laptop or desktop it usually opens as a large panel (often called a mega menu) when someone hovers over or clicks a top level item.
Baymard's navigation research lists several small details that cause real trouble4:
- 31% of sites do not make the headings inside the menu clickable, although most participants expected them to be.
- 62% of sites have no hover delay, so the menu flickers open and shut as the mouse crosses it. A delay of 300 to 500 milliseconds removes most of that.
- 96% of sites do not highlight where the user currently is in the main navigation.
The number of top level items matters too. Every extra choice slows the decision a little, an effect known as Hick's law, which conversion and UX psychology explains with its own example. Fewer, clearer top level items beat many clever ones.
Example: Shannonside's desktop menu
Shannonside's menu had seven top level items: New in, Ceramics, Textiles, Lighting, Furniture, Gifts, Sale. Hovering over "Lighting" opened a panel with headings that could not be clicked, and the panel flickered whenever the mouse moved diagonally towards it.
Callum makes four changes. He renames "Lighting" to "Lamps", the word customers used in the card sort. He makes every heading in the panel a link. He adds a hover delay of 300 milliseconds, and opens the panel on click too, for people using a keyboard or a touch screen laptop. And when someone is inside Lamps, the "Lamps" item stays underlined in the menu, so they always know where they are.
None of these changes needs a redesign. Together they take Callum two days, tests included.
The main menu on a phone
On a phone there is no room for a panel, so most shops hide the menu behind an icon with three lines (the "hamburger"). That is convenient, and it has a cost.
Nielsen Norman Group tested hidden, visible and combined navigation with 179 participants. On desktop, people used hidden navigation in 27% of tasks against 48% for visible navigation. On mobile, hidden navigation was used in 57% of tasks against 86% for a combined design, where some items are visible and the rest sit behind a menu. Hidden navigation also made people 15% slower on mobile than the combined version5. Their summary: "Discoverability is cut almost in half by hiding a website's main navigation."
Baymard adds a detail for shops: 22% of sites do not make product categories the first level of the mobile menu, burying them under items like "Inspiration" or "About us"4.
Example: Shannonside's mobile menu
68% of Shannonside's category sessions happen on a phone. The hamburger menu opened with "Inspiration", "Our story", "Journal" and only then the four ranges.
Callum puts the four ranges first in the menu, and adds a row of four visible links under the header on the home page and on every category page: Ceramics, Textiles, Lamps, Furniture. They scroll sideways if the screen is narrow. Everything else stays behind the menu icon. This is the combined pattern from the research: the most important routes are visible, the rest is one tap away.
Category landing pages: subcategories first
When someone clicks "Lamps", what should they see? Two options: the full list of 186 lamps straight away, or a page that first shows the subcategories (table lamps, floor lamps, outdoor lamps, lampshades and bulbs) with a picture each.
Baymard calls the second kind an intermediary category page. They find that such pages "perform best when they prioritize subcategory navigation", and that 38% of sites do not put the subcategories first. They also find that 39% of sites have missing or unclear subcategory thumbnails, and that people hesitate more when choosing between text links only4.
The practical rule: a top level category with clearly different kinds of product inside gets a landing page with picture links to its subcategories, followed by a short list of best sellers. A category whose products are all the same kind (mugs, say) goes straight to the product list.
Example: the Lamps landing page
Callum builds the Lamps page with four large picture links, one per subcategory, each showing a typical product photographed in a room. Under them comes a strip of eight best sellers across all lamps, for people who just want to browse. The Ceramics page works the same way. Mugs, a subcategory of Ceramics, goes straight to the product grid, because every product in it answers the same question.
The product card: what each one must show
The product card is the small block in the grid: picture, name, price and a few details. Its job is to let someone decide whether this product is worth opening, without opening it. When a card shows too little, people have to open product after product and come back, and they tire quickly.
Baymard's product list research found that 46% of sites show too little or poorly chosen information in their list items6, and that 42% of sites do not combine the variations of one product into a single card, so the same mug in eight colours fills eight places in the grid7.
For a homeware shop, I would put these on every card:
| On the card | Why | Shannonside example |
|---|---|---|
| One good photo, a second on hover or swipe | People judge homeware by eye | Lamp lit, in a room, second photo on white |
| Product name in plain words | So people know what it is | "Arc floor lamp, brushed brass" |
| Price, and the price range if variants differ | The first filter in everyone's head | "€149" or "€28 to €36" |
| Colour swatches with names | Variants on one card, not eight cards | Sage, ochre, chalk |
| The one spec that decides | Fit is the main worry with homeware | "Height 165 cm" for lamps, "W 45 × D 35 cm" for side tables |
| Rating and number of reviews | Social proof, if real | 4.6 from 38 reviews |
| Availability and delivery | Stock and timing decide many orders | "In stock, delivered in 2 to 3 days" |
Two details people often miss. First, what is legally required in a displayed price differs by country, and the product page chapter covers it for each edition. Second, a crossed out "was" price on a card is a legal statement about a previous price, and the chapter on persuasion and the law explains when it is allowed.
Example: one card, before and after
Before, a Shannonside card showed a photo of the lamp on white, the name "Hana", and "€149". To learn that Hana is a brass arc floor lamp, 165 cm tall, that it needs an E27 bulb and that it is in stock, a customer had to open it.
After, the card reads: photo of the lamp lit in a living room, "Hana arc floor lamp, brushed brass", "€149", two swatches named brass and black, "Height 165 cm", "4.6 from 38 reviews", "In stock, delivered in 2 to 3 days". A customer who needs a lamp under 150 cm now skips Hana without opening it. That is a good outcome: the card did its job by saving a wasted click.
Sorting: the orders people expect, and a fair default
Sorting matters most when the list is long and people already know what they value: the lowest price, the best rated, the newest. Baymard identifies four sort types people expect (price, user rating, best selling and newest) and finds that 68% of desktop sites and 69% of mobile sites do not offer all four7.
The hardest sort is the default one, usually labelled "Recommended". It decides what most people see first, because most people never change the sort. A good default puts the products most likely to be bought near the top. The obvious way to do that, ranking by orders per product page view, has a trap: a product with few views can look brilliant or terrible by pure chance.
The fix is to pull every product's rate towards the category average until it has enough views to speak for itself. This is called smoothing, or a Bayesian average:
where is the smoothed order rate of product , is the number of orders containing product , is the number of views of its product page, is the average order rate across the category, and is a weight in views that says how much evidence you need before trusting a product's own rate. With few views, stays close to . With many, it moves to the product's own rate. The averages behind it are explained in Foundations: mean.
Example: two vases at Shannonside Home
In the last 90 days, vase A had 20 product page views and 3 orders. Vase B had 1,000 views and 40 orders. The category average is 2.5% and Callum sets views.
The raw rates:
Ranked raw, vase A (, or 15%) beats vase B (, or 4%) by a mile. But three orders could easily be luck.
The smoothed rates, with :
Now vase B () ranks just above vase A (). The smoothing has done its job, as described in Foundations: mean. Vase A still moves up the list, so it gets more views, and if it keeps selling at that rate it will overtake B within weeks. Callum recalculates the score every night, stores it on each product and adds two business rules on top: products out of stock drop to the end of the list, and new products get a fixed place in the top 24 for their first 14 days, so they have a chance to collect views.
Filters: which facets a homeware shop needs
A filter is only useful if it matches a question the customer actually has. Baymard's rule of thumb is that any product detail important enough to show on a card must also be available as a filter, and they found that 38% of sites miss this6. They also recommend category specific filters for every product type you carry, on top of the basics like price that work everywhere6. In their product list benchmark, 51% of sites do not offer all five filter types they consider essential across most shops: price, user rating, colour, size and brand7. Brand matters less in a shop that sells mostly its own range, so for Shannonside it gives way to material.
For homeware, the facets follow what can go wrong after delivery: it does not fit, it is the wrong colour, it cannot go in the dishwasher, it needs a bulb nobody has. Here is a working set:
| Category | Facets |
|---|---|
| All categories | Price, colour, rating, availability, delivery time |
| Ceramics | Material (stoneware, porcelain, earthenware), dishwasher safe, microwave safe, capacity, set size |
| Kitchen textiles | Fabric (linen, cotton, blend), washing temperature, dimensions, pattern |
| Lamps | Type, bulb fitting (E27, E14, GU10), bulb included, dimmable, height, room |
| Small furniture | Width, depth, height, material, assembly needed, delivery method |
A facet is only as good as the product data behind it. If half the lamps have no "dimmable" value, ticking "dimmable" hides half the dimmable lamps, and the customer never knows. So before a facet goes live, check its coverage: the share of products in the category that have a value for it.
where is the coverage of facet , is the number of products in the category with a value for facet , and is the number of products in the category. Another simple share, see Foundations: ratios and rates.
Example: checking facet coverage in Shannonside's lamps
Callum queries the 186 lamps for each planned facet:
| Facet | Products with a value | Coverage |
|---|---|---|
| Type | 186 | 100.0% |
| Bulb fitting | 181 | 97.3% |
| Height | 179 | 96.2% |
| Bulb included | 174 | 93.5% |
| Room | 150 | 80.6% |
| Dimmable | 122 | 65.6% |
The working shows how each line is made. For bulb fitting: . For dimmable: .
Niamh's rule: a facet goes live at 90% coverage or more. Type, bulb fitting, height and bulb included pass. Room and dimmable do not, so Niamh spends an afternoon with the supplier sheets filling the 64 missing dimmable values and the 36 missing room values. Both facets go live the following week, at 100%. The same rule makes the data better for other channels too: the Google Shopping product feed needs exactly these attributes.
How filters should behave
Good facets can still be spoiled by how the filter controls work. Baymard's product list research names three behaviours that matter7:
- More than one value per facet. People want sage or ochre, not just one. 14% of sites do not allow several values in one filter type. In testing, participants applied 5 or 6 filters, some up to 10.
- An overview of applied filters. A visible list of what is switched on, each with a way to remove it. 20% of sites do not have one.
- Filters that are easy to reach. On desktop, a horizontal bar of filters above the grid works well when there are not too many (Baymard mention apparel sites that need no more than about eight).
The logic underneath is worth getting right, because it decides what the numbers next to each filter value mean:
- Within one facet, values combine with OR. Sage or ochre shows both.
- Across facets, they combine with AND. Sage or ochre, and stoneware, and under €45.
- The count next to each value shows how many products the list would have if that value were added to everything else already selected, but ignoring the other values of the same facet. That way, a count never promises a list that turns out empty.
Example: three filters in Shannonside's ceramics
The ceramics category has 212 products. A customer ticks the colour sage. 31 products show. She also ticks ochre. Ochre on its own has 24 products, but 4 products come in both colours, so the list shows:
The products with both colours are subtracted once, because a product in the list counts once, however many of its colours match. Then she ticks the material stoneware. Of the 51, 38 are stoneware, and the list shows 38. Then she sets the price to €45 or less, and 26 products are left.
Now look at the colour facet while all this is applied. Next to "chalk" it shows "(9)". That means: with stoneware and under €45 applied, adding chalk to her colour choice would bring 9 more products into the list. The count is computed with every facet except colour itself. If chalk showed "(0)", Callum would grey it out rather than let her click into an empty list.
When a filter returns nothing
Even with honest counts, a good few people still reach an empty list, for example through a bookmarked link after a product sold out. An empty list is where browsing sessions go to die, unless the page offers a way back.
A good empty state says plainly what happened, keeps the applied filters visible, and offers the nearest way out: remove one filter, with the number of products each removal would bring back. It never says only "No products found".
For search engines, Google asks for something different. When a filter combination yields no results, the page should return an HTTP 404 status, the code for "not found", and not redirect to a generic error page8. For people, the page can still look friendly and helpful. The status code is for crawlers, the content is for humans.
Example: Shannonside's empty list
A customer opens a saved link for "sage, stoneware, dimmable" lamps. There were two; both sold out yesterday and were hidden. The page now reads: "No lamps match all three filters right now." Below that, three buttons: "Remove sage (6 lamps)", "Remove stoneware (11 lamps)", "Remove dimmable (4 lamps)". Under them, a strip of the best selling lamps. The page answers with status 404, so it drops out of Google's index, and the customer never sees anything that looks like an error.
Pagination, load more or infinite scroll
A category with 212 products does not show them all at once. There are three common ways to show the rest:
- Pagination: numbered pages, 1, 2, 3.
- Load more: a button at the end of the list that adds the next set to the same page.
- Infinite scroll: the next set loads automatically as the reader nears the end.
The research favours the button. Baymard's testing found "Load more", combined with lazy loading of images, to be generally the best performing method, and recommends loading 50 to 150 products at once on desktop (100 to 150 for visually driven products) and 15 to 30 on mobile9. Nielsen Norman Group warn that infinite scrolling suits feeds of loosely related content but not goal oriented finding, because people lose their place and the scroll bar no longer tells them how long the page is10.
Two technical details decide whether "load more" works. First, the back button. When someone opens a product and comes back, they should land where they were, not at the top of the list. Baymard found that 13% of sites send people back to the top, and that refinding a product was a direct cause of abandonment in their testing. The fix is to update the address in the browser with history.pushState() each time more products load11. Second, search engines. Googlebot does not click buttons, so each set of products also needs its own address, such as ?page=2, linked with an ordinary link. Google also asks you not to point every page's canonical tag at page 1: each page in the sequence is its own page12.
Example: Shannonside's ceramics list
Callum sets 100 products per load on desktop and 24 on mobile. Ceramics, with 212 products, loads 100, then 100 more, then the last 12 on desktop. On a phone it takes eight more taps after the first 24 (24 × 8 = 192, plus 20 in the last set).
The button is a real link to ?page=2. With JavaScript on, it fetches the next set, appends it and updates the address:
// Load the next set of products and keep the address in step
document.querySelector("[data-load-more]").addEventListener("click", async (event) => {
event.preventDefault();
const link = event.currentTarget;
const response = await fetch(link.href, { headers: { "X-Load-More": "1" } });
const html = await response.text();
const next = new DOMParser().parseFromString(html, "text/html");
document.querySelector("[data-product-grid]")
.append(...next.querySelectorAll("[data-product-grid] > li"));
history.pushState({}, "", link.href); // back button returns here
const nextLink = next.querySelector("[data-load-more]");
nextLink ? (link.href = nextLink.href) : link.remove();
});
Without JavaScript, or for Googlebot, the same link simply opens page 2. On the server, a normal request for ?page=2 shows every product up to the end of page 2, so someone coming back with the back button finds their place again. Only the button's own request, marked with a header, gets just the next set. The controller further down shows both.
Faceted navigation and search engines
Every filter click can create a new address: /lamps?colour=sage, /lamps?colour=sage&material=stoneware, and so on. That is good for people (they can bookmark and share a filtered list) and a risk for search engines, because the number of possible addresses explodes.
With multiple selection, each value of each facet is either on or off. So the number of possible filter combinations in a category is:
where is the number of possible filtered addresses, is the number of sort orders, is the number of values of facet , means multiply across all facets, and means add across all facets. The number doubles with every value you add, the same exponential growth explained in Foundations: compounding.
Google's guidance on faceted navigation is direct. If you do not need filtered pages in search results, stop them being crawled, preferably with robots.txt or by putting the filters in the part of the address after a #, which Google ignores. A canonical tag pointing to the unfiltered page or nofollow on filter links can work too, but over time they are generally less effective. If you do want some filtered pages indexed, use & to separate parameters, keep the filter order consistent, and return a 404 when a combination has no results8.
Example: how many addresses Shannonside's lamps could create
The lamps category has these filter values: 12 colours, 9 materials, 5 height bands, 5 price bands and 1 availability switch. With 4 sort orders:
With sort orders and :
So is more than 17 billion possible addresses, for a category of 186 lamps. Google would spend its whole crawl on filter pages and find the new products late.
Callum's decision: the filter parameters stay in ordinary query strings, so people can share them, and robots.txt stops crawlers from following them. The few combinations people actually search for, such as "brass floor lamps" or "stoneware mugs", get real category pages of their own, with their own address, a written introduction and a place in the menu. Those are indexed. Everything else is not.
User-agent: *
Disallow: /*?*colour=
Disallow: /*?*material=
Disallow: /*?*price=
Disallow: /*?*sort=
Pagination stays crawlable (?page=2 is not blocked), so Googlebot still reaches every product in every category.
Filters everyone can use
Filters are one of the places where shops most often fail people who use a keyboard, a screen reader or a magnifier. The rules that matter most come from the Web Content Accessibility Guidelines (WCAG) 2.1 at level AA, the standard most accessibility law in my markets points to. In Ireland, the European Accessibility Act applies through S.I. No. 636 of 2023, the European Union (Accessibility Requirements of Products and Services) Regulations 2023, which cover eCommerce services for consumers13. The accessible checkout article goes into that law. Four criteria do most of the work on a category page:
- Status messages (4.1.3). When a filter changes the list, the new number of results must be announced to screen reader users without moving their focus. A container marked
role="status"does this14. - On input (3.2.2). Ticking a box must not cause a change of context, such as a jump to a new page or a moved focus, unless people were told beforehand15. Updating the list in place is fine. Reloading the page and throwing focus to the top is not.
- Use of colour (1.4.1). Colour must not be the only way to convey information16. A colour swatch needs its name as text, for people who cannot tell sage from grey.
- Groups that open and close. A filter group that expands, like "Material", is a disclosure: a button that shows and hides a section, with
aria-expandedtelling assistive technology whether it is open17.
Example: Shannonside's colour filter in the markup
Callum builds each filter group as a fieldset of real checkboxes, with the count inside the label and a live region for the result count:
<fieldset class="filter-group">
<legend>
<button type="button" aria-expanded="true" aria-controls="filter-colour">Colour</button>
</legend>
<div id="filter-colour">
<% @colour_counts.each do |name, count| %>
<label>
<input type="checkbox" name="colour[]" value="<%= name %>"
<%= "checked" if params[:colour]&.include?(name) %>
<%= "disabled" if count.zero? %>>
<span class="swatch swatch--<%= name.parameterize %>" aria-hidden="true"></span>
<%= name.humanize %> (<%= count %>)
</label>
<% end %>
</div>
</fieldset>
<p role="status" class="result-count"><%= @products.size %> products</p>
A screen reader user tabs to "Sage (31)", presses space, and hears "51 products" a moment later, while the focus stays on the checkbox. The swatch is decoration (aria-hidden), because the name already carries the meaning.
Building it in Rails and Solidus
On Solidus, the parts of this chapter map onto models that already exist. Categories are taxons (Spree::Taxon), grouped in taxonomies. Colours and sizes that make variants are option values (Spree::OptionValue). Facts about the whole product, like material or dimmable, are product properties (Spree::ProductProperty). Solidus ships with search scopes on Spree::Product, such as in_taxon, with_option_value and price_between18.
Many Rails developers reach for the Ransack gem to turn query parameters into database queries. It works, with one condition that is easy to forget: since Ransack 4.0, every searchable attribute must be allowed explicitly, for security19. Solidus keeps that list for products very short (name and slug) on purpose. For a shop front, where the filters are a fixed, known set, plain scopes in a small query object are easier to read, test and keep safe.
Example: Shannonside's filter query object
This class takes the category and the permitted parameters and returns the filtered, sorted list. Each facet is a subquery on product ids, which keeps OR within a facet and AND across facets, as described above.
# app/queries/catalog_filter.rb
class CatalogFilter
SORTS = {
"recommended" => ->(scope) { scope.order(list_score: :desc) },
"price_low" => ->(scope) { scope.sort_by_master_default_price_amount_asc },
"price_high" => ->(scope) { scope.sort_by_master_default_price_amount_desc },
"newest" => ->(scope) { scope.order(available_on: :desc) }
}.freeze
def initialize(taxon:, params:, currency: "EUR")
@taxon = taxon
@params = params
@currency = currency
end
def products(except: nil)
scope = Spree::Product.available.where(id: in_category)
scope = with_option_values(scope, "colour", @params[:colour]) unless except == :colour
scope = with_property_values(scope, "material", @params[:material]) unless except == :material
scope = within_price(scope) unless except == :price
scope = scope.where(id: Spree::Variant.in_stock.select(:product_id)) if @params[:in_stock] == "1"
SORTS.fetch(@params[:sort], SORTS["recommended"]).call(scope)
end
# Count per colour with every other filter applied, so no count promises an empty list
def colour_counts
others = products(except: :colour).reorder(nil).select(:id)
Spree::OptionValue.joins(:option_type, :variants)
.where(spree_option_types: { name: "colour" }, spree_variants: { product_id: others })
.group("spree_option_values.name")
.distinct.count("spree_variants.product_id")
end
private
def in_category
Spree::Classification.where(taxon_id: @taxon.self_and_descendants.select(:id)).select(:product_id)
end
# OR within one facet: any of the chosen values
def with_option_values(scope, type_name, values)
return scope if values.blank?
scope.where(id: Spree::Variant.joins(option_values: :option_type)
.where(spree_option_types: { name: type_name }, spree_option_values: { name: values })
.select(:product_id))
end
def with_property_values(scope, property_name, values)
return scope if values.blank?
scope.where(id: Spree::ProductProperty.joins(:property)
.where(spree_properties: { name: property_name }, value: values)
.select(:product_id))
end
def within_price(scope)
min, max = @params[:min_price].presence&.to_d, @params[:max_price].presence&.to_d
return scope if min.nil? && max.nil?
prices = Spree::Price.where(currency: @currency, amount: min..max).select(:variant_id)
scope.where(id: Spree::Variant.where(id: prices).select(:product_id))
end
end
Three things to note for the beginner. list_score is a column Callum added himself, holding the smoothed rate from the sorting section, recalculated nightly. Spree::Variant.in_stock is a Solidus scope that returns variants with stock on hand. And min..max with one end missing becomes "at least" or "at most" in the database query, so a customer can set only a maximum price.
The controller permits exactly the parameters the filters use and nothing else:
# app/controllers/categories_controller.rb
class CategoriesController < ApplicationController
def show
@taxon = Spree::Taxon.find_by!(permalink: params[:id])
filter = CatalogFilter.new(taxon: @taxon, params: filter_params)
@products = page_of(filter.products)
@colour_counts = filter.colour_counts
empty = @products.empty? && filter_params.except(:sort).present?
render :show, status: empty ? :not_found : :ok
end
private
PER_PAGE = { "wide" => 100, "narrow" => 24 }.freeze
def filter_params
params.permit(:sort, :min_price, :max_price, :in_stock, colour: [], material: [])
end
def page_of(list)
page = [params[:page].to_i, 1].max
per = PER_PAGE.fetch(params[:layout], 24)
if request.headers["X-Load-More"]
list.offset(per * (page - 1)).limit(per) # only the next set, for the button
else
list.limit(per * page) # everything so far, so the back button lands in place
end
end
end
When the filters leave nothing, the same friendly page renders with status 404, as in the empty state example. The layout parameter is set by the page itself from the screen width, so a wide screen asks for 100 products per set and a phone for 24. Because every filter is a plain method, Callum writes a test for each one first (ticking two colours returns both, adding a material narrows the list, a count never exceeds what the list then shows), and the change goes through his test gate like any other release.
Measuring whether browsing works
You cannot improve what you do not measure, and the browsing path has its own numbers. Google Analytics 4 (GA4) has two recommended events made for it, both in Google's ecommerce documentation20. They are
view_item_listwhen a list of products is shown, withitem_list_idanditem_list_namesaying which list.select_itemwhen someone clicks a product in a list, with the same list fields and the product's position (index).
GA4 has no recommended event for filters, so you create your own. Event names must start with a letter and use only letters, numbers and underscores21. To see the parameters in reports, you register them as custom dimensions, and a standard property allows up to 50 event scoped ones22. The tracking plan chapter shows how to name and document events like these, and product and category analytics goes further into which categories earn their place.
// A click on a product card in the ceramics list
gtag("event", "select_item", {
item_list_id: "category_ceramics",
item_list_name: "Ceramics",
items: [{ item_id: "SH-MUG-014", item_name: "Stoneware mug, sage", index: 7, price: 21.0 }]
});
// A filter applied (custom event)
gtag("event", "apply_filter", {
list_id: "category_ceramics",
filter_name: "colour",
filter_value: "sage",
results_count: 31
});
Three numbers come out of these events. The list click through rate, the share of sessions that saw a list and clicked into a product:
where is the list click through rate, is the number of sessions with at least one select_item, and is the number of sessions with at least one view_item_list. The filter use rate is built the same way, with sessions that fired apply_filter on top. And the empty result rate is the share of filter events where results_count was zero. All three are rates, see Foundations: ratios and rates.
Example: Shannonside's browsing numbers, and a trap in them
From the month in the first example:
14,040 of the 63,800 category sessions applied a filter, a filter use rate of . Those sessions placed 437 orders, a conversion rate of . The other 49,760 sessions placed 813 orders, .
It is tempting to conclude that filters nearly double conversion, so everyone should be pushed into them. That does not follow. People who use filters are often further along in their decision: they know they want a stoneware mug under €25. They would convert more often with or without filters. This is correlation, not cause, and Foundations: correlation explains the difference. The only clean way to measure what a filter change is worth is an experiment with a control group, which experiments inside your own shop shows how to run.
Which fix first: put a value on each one
You now have a long list of possible improvements. Do them in order of money, not in order of how interesting they are. The first chapter of this series sets out how to rank fixes by expected value. For the browsing path, the value of raising the list click through rate can be estimated directly:
where is the extra gross profit per month, is the number of sessions that see a category list, is the rise in the list click through rate, is the share of product visits from lists that end in an order, is the average order value, and is the gross margin. Each step multiplies the one before, as in Foundations: expected value.
Example: what five points of list click through are worth to Shannonside
Callum's changes (clear cards, fewer subcategories, filters with full data) aim to lift the list click through rate from 57% to 62%, so . From the first example, .
Step by step:
So comes to about €4,793 a month, if every extra visitor behaves like the visitors before. Each line is one factor of the formula, as in Foundations: expected value.
One honest correction. The extra visitors who now click through are probably less decided than the ones who already did, so they will convert less often. If they convert at half the rate, the gain is about €2,397 a month, or about €28,800 a year. That is still a strong case for a few weeks of work, and it is a range Niamh can plan with rather than a promise.
The whole path from landing to product, with the checks this chapter adds, looks like this:
Conclusion
People find the right product among hundreds when the shop thinks the way they do. Build the category tree from a card sort with 15 customers and check it with a tree test. Keep categories for kinds of thing and turn properties into filters. Show categories first in the menu on every screen size, and give each product card the one detail that decides. Offer the four sorts people expect and a default that is fair to new products. Choose facets from what goes wrong after delivery, and do not switch one on until its data is complete. Make filters combine sensibly, count honestly and never lead into an empty list without a way back. Use a "load more" button that keeps people's place, keep filtered addresses away from crawlers, and build every control so a keyboard and a screen reader can use it. Then measure the list click through rate and put a euro figure on each fix before you start it.
I build shops like this on Ruby on Rails and Solidus, test first, and the code belongs to the shop once it is paid for. If your category pages lose more people than they should, the free workshop is a good place to find out where.