Case study · Shopify app

Shopify Social Image Automation Case Study: Branded OG Images From Every Product Save

This Shopify social image automation case study explains how I built an app that creates a branded 1200 × 628 Open Graph image every time a merchant creates or updates a product. When someone shares a product link on WhatsApp or Facebook, the preview shows the deal: the price, the old price, a discount badge and the store's logo, instead of a plain product photo.

I first built it for a Shopify deals store whose products are shared as WhatsApp links. The hard part wasn't drawing the image. It was making WhatsApp and Facebook show the new image after a price change, without calling any scraper API.

Shopify social image automation app dashboard next to generated deal images with sale prices and discount badges
The app's onboarding screen and the deal images it generates.

The challenge: link previews that sell the deal

A deals store lives on shared links. When a product link lands in a WhatsApp group, the preview card is the first thing people see. By default, Shopify shows the product photo and title. That hides the one thing a deal shopper cares about: the price and how much they save.

Making a custom image for every product by hand takes time, and it goes out of date the moment a price changes. Even worse, WhatsApp and Facebook cache link previews. Upload a new image, share the link again, and people often still see the old one.

Constraints that shaped the build

  • Zero manual steps per product. Saving a product in Shopify had to be the only action. No design tool, no upload, no copy and paste.
  • Merchant-owned files. Images had to live in the merchant's own Shopify Files, not in a bucket I control.
  • No scraper APIs. I didn't want to depend on Facebook's sharing debugger API to refresh old previews.
  • No theme code edits. Merchants shouldn't need a developer to paste code into their theme.
  • Many stores, one app. Each store installs it on its own, with its own token, logo and settings.

What I built

Save a product, get a shareable deal image

Shopify tells the app when a product changes. The app draws the image, stores it in the merchant's store and tells the storefront which version to share.

Automatic deal images

Sharp builds a 1200 × 628 image with the product photo, sale price, regular price, discount badge and store logo.

Roundup images

For deal pages, a four-card roundup image shows several selected products in one preview.

Per-product overrides

Product metafields let the merchant change the badge text, sale price, regular price or headline, or turn the image off for one product.

Merchant-owned storage

Each image is uploaded to the store's own Shopify Files and served from the Shopify CDN, then written back to the product.

Preview cache busting

A theme app embed adds a short sharing version to the product URL, so WhatsApp and Facebook treat a changed deal as a new link.

Secure multi-store install

App Bridge ID-token auth, encrypted offline tokens per shop, HMAC-verified webhooks and Shopify's mandatory privacy webhooks.

How the automation works

From product save to image

When a merchant saves a product, Shopify sends a signed products/update webhook. The app checks the signature first. It computes an HMAC of the raw request body with the app secret and compares it with Shopify's header using a constant-time comparison. Anything that doesn't match is rejected before it touches a store.

Then the app finds the store's encrypted token, reads the product and its deal overrides, and builds the image with Sharp. It uploads the file to Shopify Files and writes the image URL, the image version and the sharing version back to the product in one GraphQL mutation.

Skip work that changes nothing

Shopify sends a product webhook for many small edits, like stock changes, and it can send the same event more than once. So the app hashes everything that affects the image: title, prices, overrides, photo and logo. If the hash matches the last one stored on the product, it skips the job. If the hash matches but the stored image is missing, it rebuilds it instead of trusting the hash.

Generated 1200x628 Open Graph deal image with a 46% off badge, sale price, crossed-out regular price and store logo
An image generated by the app from a test product: discount badge, sale price, regular price and logo.

Making WhatsApp show the new image

Social apps cache previews by URL. If the URL never changes, the old preview can stay for a long time. My fix was to make the URL change only when the deal changes. The app stores a short sharing version on the product. A theme app embed prints it in the page head, and a tiny script adds it to the address bar as ?pv=. When a shopper copies the link, they copy the current version.

This is the real script from the theme app embed:

(() => {
  const version = document.querySelector('meta[name="social-image-version"]')?.content;
  if (!version) return;
  const url = new URL(window.location.href);
  if (url.searchParams.get('pv') === version) return;
  url.searchParams.set('pv', version);
  window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
})();

It uses replaceState, so the page doesn't reload and the back button still works. Because it ships as a theme app embed, the merchant turns it on in the theme editor. Nobody edits theme code.

Merchants control the deal text

During install, the app creates the product metafield definitions it needs. The merchant fills them in on the normal product page: a custom badge, a different sale or regular price, a headline, or hide to remove a badge or the prices. Leave them empty and the app uses the product's own price and compare-at price.

Shopify product page showing the deal_enabled, deal_title, deal_reg_price, deal_sale_price and deal_badge_text metafields created by the app
The deal override fields the app adds to every product in Shopify admin.

Trade-offs and lessons

  • Webhooks repeat, so design for it. Content hashes make repeated deliveries harmless. A table of processed webhook IDs would be stricter, and it's the next step I'd add for a larger store.
  • Some themes already print OG tags. Duplicate tags behave differently per theme, so every target theme has to be tested before release.
  • Theme app embeds start switched off. The merchant has to turn the embed on and save the theme once, so onboarding links straight to that screen.
  • Serverless needs a real database. Vercel's file system doesn't keep files, so installation records go to PostgreSQL. Local development can use an encrypted JSON file instead.
  • Public distribution is a separate step. Installing on unrelated stores needs Shopify App Review. Custom distribution only covers one store or one organization.

Outcome

The merchant saves a product and the shareable deal image is ready, with no design work and no manual upload. A price change produces a new image and a new sharing version, so the next shared link shows the new deal.

  • Every product gets a branded 1200 × 628 preview with the deal on it.
  • Images live in the merchant's own Shopify Files, not on a third-party server.
  • Old previews refresh through the URL version, with no scraper API calls.
  • Any store can install it with its own logo, token and settings.
  • An automated test suite covers cache busting, deal overrides, roundups, webhook security and the install flow.

Tech stack

  • Node.js
  • Express
  • Shopify GraphQL Admin API
  • Shopify App Bridge
  • Theme App Extensions
  • Webhooks
  • Metafields
  • Sharp
  • PostgreSQL
  • Vercel

Need a custom Shopify app or automation?

Tell me what your team still does by hand in Shopify. I'll tell you whether an app, a webhook or a simple script is the right fix. See my AI SaaS development services for how I work.