Funnels and conversion rates
A funnel follows visitors through the steps towards a sale and shows where they drop out.
Brightwell's web_sessions table records how far each visit got:
SELECT COUNT(*) AS visits,
COUNT(*) FILTER (WHERE viewed_product) AS viewed_product,
COUNT(*) FILTER (WHERE added_to_basket) AS added_to_basket,
COUNT(*) FILTER (WHERE reached_checkout) AS reached_checkout,
COUNT(order_id) AS ordered
FROM web_sessionsCOUNT(*) FILTER (WHERE …) counts only the rows that match. COUNT(CASE WHEN … THEN 1 END) does
the same and works everywhere.
The numbers that matter are the conversion rates: ordered ÷ visits overall, and each step ÷
the step before. A drop between basket and checkout points at the checkout page; a drop between
visit and product view points at the landing pages. Group by device or source to see which
visitors struggle.
SELECT COUNT(*) FILTER (WHERE added_to_basket) FROM web_sessionsSELECT COUNT(CASE WHEN added_to_basket = 1 THEN 1 END) FROM web_sessionsNo FILTER, and yes/no columns are BIT, so compare with 1.
SELECT COUNT(CASE WHEN added_to_basket THEN 1 END) FROM web_sessionsSUM(added_to_basket) works too, as true is stored as 1.
SELECT COUNT(*) FILTER (WHERE added_to_basket) FROM web_sessionsSELECT COUNTIF(added_to_basket) FROM web_sessions