Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 40 ยท Search and Merchandising

Merchandising and Recommendations

Learn collections, ranking rules, related and also-bought products, cross-sell and upsell, personalization basics, and how to A/B test prices and layouts without fooling yourself.

Search helps people who know what they want. Merchandising helps everyone else: it is the craft of deciding which products to show, in which order, in which place. In a physical shop, a person arranges shelves, window displays and the items next to the till. An online shop does the same with collections, category pages, ranking rules and recommendation blocks, except that the shelves can change for every visitor and every change can be measured.

This lesson covers the building blocks: collections, ranking rules, "related" and "also bought" blocks, cross-sell and upsell, a little personalization, and how to run experiments such as A/B tests. You will build a tiny co-purchase recommender and an A/B test checker. The searchable product data and facets from Product Search, Filters and Facets and the order data from The Core Domain Model are the raw material.

Collections and category pages

A category is usually a permanent place in a tree ("Men > Shoes > Boots"). A collection is a flexible group of products that exists for a reason: "Summer sale", "Gifts under $50", "New arrivals", "Back in stock". Two kinds exist:

  • Manual collections: a merchandiser picks products and puts them in order. Perfect for a campaign page.
  • Automatic (rule-based) collections: products join by a rule such as tag = "vegan" and price < 5000 and stock > 0. They stay up to date without anyone touching them.

A product can be in many collections, which is the main difference from categories and a reason to keep both concepts (see Product Catalogs and Data Modeling). Collection pages need unique intro text and stable URLs, because they attract search traffic as well as visitors.

Ranking rules: the default order of a list

Which product comes first on a category page? A pure alphabetical list wastes the best spot. Common sort orders are "featured", "best selling", "newest", "price" and "rating". A "featured" order is often a score that blends signals:

TEXT
score = 0.5 x sales rank + 0.2 x rating + 0.2 x freshness + 0.1 x margin

then adjusted by rules:

  • Pin chosen products to the top (a launch, a campaign).
  • Bury out-of-stock products, or hide them (what to do for SEO is covered in SEO for Online Shops).
  • Boost new products for a week, or those with healthy stock.
  • Diversify: avoid ten items from the same brand in a row.
  • Demote items with many returns or poor ratings.

Be careful with feedback loops. If only top-ranked products get clicks, they get more sales, rank higher, and get even more clicks, while new good products never get a chance. A bit of exploration (rotating a few slots, boosting new items) keeps the catalog healthy. Keep the rules visible in the admin so merchandisers can see why a product sits where it does.

Product pages and carts commonly show blocks such as:

  • Similar / related: products like this one, chosen by shared category, attributes or text. They help a visitor who is not sure about this item. Content-based.
  • Frequently bought together / customers also bought: products that appear in the same orders. They help a visitor who has decided and may need an accessory. Behavior-based (collaborative).
  • Recently viewed: a per-visitor list, usually stored in the browser.
  • Best sellers / trending: a fallback for new visitors or empty slots.

The simplest useful behavior-based model counts co-purchases: for each pair of products, in how many orders did they appear together? Then, for a given product, recommend the products with the highest scores. Raw counts favor popular items (everyone buys batteries with everything), so better scores divide by how popular each item is. A common choice is lift or cosine similarity: it asks "do these two sell together more than their popularity alone would predict?"

Python A co-purchase recommender with a popularity-aware score

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the last line. A new product has no history, so the recommender returns nothing. This is the cold-start problem. Fallbacks are essential: use content-based "related" items from the same category, then best sellers. The min_support parameter shows a second principle: a pair seen once is noise, not a pattern. In production you calculate these tables offline (nightly or hourly), store the top results per product, and read them from a cache, never computing pairs while a visitor waits.

Cross-sell and upsell

  • Upsell offers a better version of what the customer is looking at: the 256 GB model instead of 128 GB, the annual plan instead of monthly.
  • Cross-sell offers something that goes with it: a case with the phone, batteries with the camera.
  • Bundles and order bumps package items at a small discount, or offer a one-click add-on at the cart.

Guidelines that protect trust and conversion: recommend things that are actually compatible (check it in data, not hope), keep the offer clearly cheaper than the effort of searching elsewhere, show at most three or four items, and never push an upsell that is far above the original budget. Do not show recommended products that are out of stock. Cart-level offers should be simple to ignore and must not interrupt checkout, which is discussed in Checkout Flow and Conversion. Bundle pricing needs the rules of Building a Promotions Engine.

Personalization basics

Personalization changes what a person sees based on who they are or what they did. Levels, from simple to complex:

  1. Context: the country, language, device, time of year. No identity needed.
  2. Session behavior: recently viewed items, the category they browse now.
  3. Account history: past purchases ("buy again", size preference).
  4. Segments and models: groups such as "first-time buyer" or a machine-learning ranking per visitor.

Start with the first two; they give most of the benefit with the least risk. Personal data carries obligations: you need a lawful basis and consent where required, you must allow opt-out, and sensitive inferences deserve caution (see GDPR, Consumer Law and Accessibility). A practical technical point: personalized HTML cannot be shared in a CDN cache. Load the personal blocks with a small request after the page, as the rest of this site's design does, so the main page stays cacheable (see Architecture, Scaling and Peak Traffic).

Testing changes: A/B tests

Opinions about layouts are cheap; measured results are not. In an A/B test you randomly split visitors into groups, show each a different variant (a new ranking, a different button, a price), and compare a metric such as conversion rate or revenue per visitor.

Rules that keep tests honest:

  • Assign by visitor, consistently. A returning visitor must keep seeing the same variant. Hash a stable visitor id together with the experiment name to choose the group.
  • Decide the metric and sample size first. Stopping a test the moment it looks good ("peeking") produces false winners.
  • Run whole weeks to cover weekday and weekend behavior.
  • Test one change at a time, and watch guardrail metrics (returns, support tickets, refund rate), not only conversion.
  • Be careful with prices. Showing different prices to different people for the same product can upset customers, may break consumer-protection or price-transparency rules in some places, and breaks trust when it is discovered. Test price points with care, preferably across separate markets or periods, and check the legal rules.
  • Check significance. A 1% difference in a tiny sample is noise.
Python Stable A/B assignment and a significance check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The small test shows B ahead (2.6% against 2.0%), but with only 1,000 visitors per group the difference could easily be luck. The large test has a smaller relative gain, yet the evidence is strong. Hashing the visitor id with the experiment name makes assignment deterministic without storing anything, and different experiments split the visitors independently.

Measure what matters

Track, per placement: impressions, clicks, add-to-carts, and revenue attributed to the block. Compare against a baseline with no recommendations, because many clicks would have happened anyway. Funnels and metrics are explored in Analytics, Funnels and Metrics. Merchandisers need tools more than developers do: a way to preview a collection, schedule a campaign, pin products and see the effect, without a code release.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main difference between a category and a collection?

    Categories form the stable navigation tree; collections are curated or rule-driven groups for campaigns, themes and dynamic lists, and one product may appear in several.
  2. 2. Why use cosine or lift instead of raw co-purchase counts for 'also bought'?

    A very popular item appears with almost anything. Normalizing by how often each item sells shows which pairs truly sell together more than chance would suggest.
  3. 3. A brand-new product has no order history. What should the 'also bought' block show?

    This is the cold-start problem. Content-based related items and best sellers fill the gap until behavior data exists.
  4. 4. How should a returning visitor be assigned to an A/B test variant?

    Consistent assignment prevents a visitor seeing both versions, which would pollute the results and confuse customers.
  5. 5. Which is the biggest risk of ending an A/B test as soon as it looks like B is winning?

    Early results fluctuate a lot. Decide the sample size and duration beforehand and judge the result only at the end.

Summary

  • Collections (manual or rule-based) group products flexibly; categories form the stable tree.
  • Default sort orders are scores plus rules (pin, bury, boost, diversify); avoid feedback loops that starve new products.
  • "Related" is content-based; "also bought" is behavior-based and should use popularity-aware scores, a minimum support, and fallbacks for cold start.
  • Cross-sell suggests companions, upsell a better version; keep offers compatible, few and easy to ignore.
  • Personalize first by context and session; handle consent, and keep personal blocks out of shared caches.
  • A/B test with stable assignment, a preset metric and sample size, whole weeks, guardrail metrics, and care around prices.

Next: SEO for Online Shops looks at how search engines find your products and collections.