Benjamin Edwards

Scheduling a Shopify Black Friday sale for midnight

Shopify can schedule a discount but not your theme. How I set up a Black Friday page and homepage switch that runs itself, and the two traps on the way.

Audio Trader's Black Friday sale page before the sale, with a countdown to midnight on 27 November

Black Friday starts at midnight. Somebody has to change the homepage at midnight. At most small retailers that somebody is the owner, on a laptop, in bed.

This year Audio Trader’s sale page and homepage switch on and off by themselves, and if anything goes wrong someone is told before a customer notices. Here is how it is set up, and the two things that broke on the way.

What Shopify will and will not schedule

Shopify can start a discount at a set time and publish a product at a set time. What it cannot do, unless you are on Shopify Plus with Launchpad, is change your theme at a set time. The homepage banner, the sale page’s content and the menu link are theme work, and theme work happens when someone presses the button.

Two keys, not one

The homepage masthead shows the Black Friday version only when two things are both true:

  • The date. The theme checks the date itself, so the sale cannot show early or run late, whatever else happens.
  • A switch. A yes or no setting on the store, a metafield, that a small scheduled job turns on at midnight on Friday and off at 11:59pm on Monday.

If the job fails, the switch stays off and the normal homepage stays up. A missed launch is a nuisance. A Black Friday banner still on the homepage in the middle of December makes a shop look closed. Two keys means the failure you get is the harmless one.

The job runs on Cloudflare, outside Shopify, every two minutes.

Put the sale page up early

The sale page went live at the start of November, linked from nowhere on the site but open to Google. Before Black Friday it says the sale is coming and shows no products. After Cyber Monday it points to the year-round sale.

People search “[shop name] Black Friday” in the weeks before. A page Google has already found can answer them. A page that appears at midnight on the day cannot.

Trap one: Shopify’s page cache

The first test switched the flag on and the homepage did not change. Shopify caches pages, and neither changing a metafield nor changing a theme file clears that cache. The change took between five and fifteen minutes to reach each page, sometimes longer.

So the switch does not happen at exactly midnight on every page, and nothing in the copy promises that it will. The monitoring allows for it: it waits 45 minutes before it calls a missing banner a failure.

Trap two: where you check from

The monitor first ran on Cloudflare too, fetching the live pages to confirm the right version was showing. For three mornings running it reported failures and on the third it sent an urgent alert. Nothing was wrong with the shop.

Shopify was refusing page requests that came from Cloudflare Workers, at any minute and from every Cloudflare location tried. The same request from GitHub’s servers got a normal answer every time. The checks now run on GitHub, the switch still runs on Cloudflare, and each watches the other: if either one stops reporting, the other says so. Alerts go to a Slack channel and by email.

A monitor that cries wolf gets muted, and then it is worse than no monitor. Before you trust one, make it fail on purpose and make sure the alert means what it says.

Two smaller things worth checking

  • Look at the page source, not just the page. Shopify’s own analytics data on a collection page lists the products in it. A “coming soon” page built on the sale collection can name every product in the sale before the day. Build it on an empty collection, or check the source.
  • Say what is actually happening to prices. Audio Trader’s sale is the items already reduced. Nothing drops at midnight, so the copy never says it does. If your prices really do change at midnight, schedule the discount in Shopify and let the page follow it.

Reuse it

Most of the effort went on the monitoring, not the switch. The whole setup is written up as a runbook, so Christmas and the January sale reuse it rather than start again.

The sale runs for the first time on Friday 27 November. I will add what happened here.

If this sounds like your shop, a twenty minute call will tell us both whether it is worth fixing.

More like this in the articles, or see what shopify development involves.