VitalWall

How to show sales by product on a live treemap

Post each order with its total, and every product's tile grows by the dollars it brings in. Add one more tag and your header counts the orders live.

How to show sales by product on a live treemap

A list of orders tells you something sold. A treemap tells you what's earning. In this how-to we build both halves of a live sales view: a treemap where each product's tile grows by the dollars it brings in, and a number for your page header that counts orders as they land.

Try it first on our live sales by product demo. Place an order for any of the four shoes and that product's tile grows by the order's total, while the count at the top ticks up, for everyone looking at that page.

The VitalWall sales by product demo: an example store admin page on a monitor, with a live count of 1 order in the last hour above a treemap of four products sized by sales

That's the demo before we pressed anything: 1 order in the last hour, and Canvas Sneaker the smallest tile at $177. Then we ordered one Canvas Sneaker at $59.

The same admin page after one $59 Canvas Sneaker order: the count reads 2 and the Canvas Sneaker tile has grown to $236

The count rolled to 2, and the Canvas Sneaker tile grew to $236 and moved past Classic Runner. The other tiles made room.

What you'll build

  • Source: your store. After checkout, your code posts the product as a small JSON item with the order total as its value.
  • Look: a treemap wall. One tile per product, sized by the sum of its values, with the total shown on the tile.
  • Count: a vital-count tag that shows how many items the wall got in the last hour, in your page's own font and color.

Step 1: Create a wall

Sign in to VitalWall, open My Walls and press Create Wall. Give it a name, like "Sales by product", and type your store's domain in Your website.

A wall only accepts posts from the domains you add to it, so nobody else can post orders to your treemap from their site. The treemap and the count only show on those domains too, so if your dashboard lives on a different domain from your store, add that one as well.

When you press Create Wall, we take you straight to its setup page. Step 1 there, Put It On Your Site, has your install code with your wall ID filled in, and step 3, Send Your First Event, has your wall's API key filled in. The key can sit in your page code, because it only posts to this one wall.

Step 2: Add the script once

Put this anywhere on your pages, once:

<script type="module" src="https://vitalwall.com/v1/vitalwall.js"></script>

Step 3: Post each order with its total

On your order confirmation page, once the payment has gone through, post the product as JSON with the order total as its value:

<script> VitalWall.track({ wall: 'YOUR_WALL_ID', key: 'YOUR_WALL_KEY', item: JSON.stringify({ key: order.product.name, description: order.product.name, imageUrl: order.product.imageUrl, value: order.total, prefix: '$', }), }) </script>

Here's what each field does:

  • key is the tile. Every item with the same key adds to the same tile, so use one name per product.
  • description is the label shown on the tile.
  • imageUrl is the product photo behind the tile.
  • value is what this order adds to the tile. It has to be a positive number. A string like "1,299" works too.
  • prefix goes in front of the total, like $ or €. Up to three characters.

This is the exact item our demo posts when you order a Canvas Sneaker:

{ "key": "Canvas Sneaker", "description": "Canvas Sneaker", "imageUrl": "https://…/product.jpg", "value": 59, "prefix": "$" }

track() runs in the browser, so the confirmation page has to be on one of the wall's domains.

Step 4: Show the treemap

Put the wall on your dashboard or admin page:

<vital-wall wall="YOUR_WALL_ID" layout="treemap"></vital-wall>

layout="treemap" draws the wall as a treemap whatever layout the wall has in its settings. The treemap adds up the wall's most recent items, up to its display limit, so set that limit in the wall's settings to cover the stretch of orders you want to see.

Leave value out and each tile sizes by how many orders it has instead of dollars. That's handy for a "most ordered" view where a $20 item and a $200 item count the same.

Step 5: Put a live count in your header

One more tag puts a live order count anywhere on the page:

<vital-count wall="YOUR_WALL_ID" window="hour" label="orders in the last hour"></vital-count>

It shows how many items the wall got in the last hour and rolls up digit by digit as new ones arrive. Use window="day" for the last 24 hours. Since every order posts one item, the count is your order count.

The tag takes your page's font and color, so it sits in a header or a hero like the rest of your text. To style it further, target its two parts from your own CSS:

vital-count::part(number) { font-size: 2.5rem; color: #16a34a; } vital-count::part(label) { opacity: 0.7; }

The count re-reads itself every few minutes, so orders older than the window drop off without a reload.

Good to know

  • The count and the treemap read the same wall, so you can put the count on one page and the treemap on another. Your storefront header can show the count while your team watches the treemap.
  • Custom CSS from the wall's settings doesn't apply to the treemap layout. The vital-count tag is styled from your own page instead.

See it running

The live sales by product demo is built this way, and its "How it's set up" section shows the same tags. Place a few orders and watch the tiles trade places.

Want to see your own data move? Start free on VitalWall. No credit card needed.

Related Posts