Sub topic 13
Keeping Product Feeds Aligned with the Site
This chapter covers how to keep a product feed in step with the product pages it describes. It assumes you have read the earlier chapters on a single source of truth, Product and Offer markup, and keeping markup and visible text in agreement. You should also be comfortable with JSON, basic HTML, and reading a CSV or XML file.
What a product feed is and why it drifts
A product feed is a file or API response that lists your products and their current facts in a fixed format. Merchant platforms such as Google Merchant Center read it on a schedule. They use it to show your products in shopping results, product listings, and other surfaces that can feed AI-generated answers.
The platform also crawls your product pages. It compares what the feed says with what the page says and with the page's structured data. If the price in the feed is 89.00 EUR and the page shows 99.00 EUR, the platform sees a mismatch. The usual result is that the item is disapproved or suppressed until the two agree.
Feeds drift because they are often built by a separate process from the pages. A common setup looks like this:
- The shop database holds the price.
- The page template reads the database live.
- A nightly export job writes the feed once a day.
If a price changes at 09:00, the page is correct at 09:00 and the feed is wrong until the next export. That gap is where mismatches come from.
One record, three outputs
The fix follows the same principle as the rest of this tutorial. Each fact lives in one place, and every output is generated from it. The feed becomes a third rendering of the product record, next to the visible price and the JSON-LD.
The next sections show how to build the feed from the same record and how to handle the places where feed and page legitimately differ.
Fields that must match
Not every feed field has to equal something on the page, but some must. The table lists the usual ones. Field names follow the Google Merchant Center feed specification. Other platforms use similar names, so check the specification of each platform you feed.
| Feed field | Must match | Typical mismatch |
|---|---|---|
| `id` | Stable product or variant identifier, such as the SKU | A new ID after a re-import, which resets the product's history |
| `link` | The canonical product page URL | A tracking URL or a redirected URL |
| `price` | The visible price and the Offer `price` | Feed export runs once a day |
| `availability` | Visible stock status and Offer `availability` | Item sold out on site, still `in_stock` in feed |
| `title` | The page's product name | Feed title rewritten by a different team |
| `image_link` | An image that exists and shows the product | Image deleted after a redesign |
| `sale_price` and its dates | A visible sale price during the sale | Sale ended on site, still active in feed |
Note the id row. The identifier ties together the feed row, the page, and the markup. It should be the same value as the sku in the JSON-LD from the earlier chapter.
Generating the feed from the same record
The Python below builds one feed row in the same style as the earlier product_jsonld function. It uses the same price and in_stock values, so the three outputs cannot disagree. The feed uses the format 89.00 EUR, with a space and the currency code after the number. The JSON-LD format keeps the number and the currency in separate properties.
from decimal import Decimal
import csv
import io
def feed_row(p, base_url):
availability = 'in_stock' if p['in_stock'] else 'out_of_stock'
return {
'id': p['sku'],
'title': p['name'],
'link': base_url + '/p/' + p['slug'],
'price': '{} {}'.format(p['price'], p['currency']),
'availability': availability,
}
def feed_csv(products, base_url):
fields = ['id', 'title', 'link', 'price', 'availability']
out = io.StringIO()
writer = csv.DictWriter(out, fieldnames=fields, lineterminator='\n')
writer.writeheader()
for p in products:
writer.writerow(feed_row(p, base_url))
return out.getvalue()
products = [
{'name': 'Trail Runner 2', 'sku': 'TR2-BLK-42', 'slug': 'trail-runner-2',
'price': Decimal('89.00'), 'currency': 'EUR', 'in_stock': True},
{'name': 'Trail Runner 1', 'sku': 'TR1-BLK-42', 'slug': 'trail-runner-1',
'price': Decimal('69.00'), 'currency': 'EUR', 'in_stock': False},
]
print(feed_csv(products, 'https://example.com'))Running it prints a header line and one row per product. The out-of-stock item is still listed, with out_of_stock. Dropping it silently would make the platform report the product as missing, while keeping it with the right status tells the platform the truth.
Choosing a refresh strategy
How often the feed updates matters most for prices and stock, the two fastest-decaying facts. You have three common options.
- Scheduled export. A job rewrites the whole file every few hours. This is simple but leaves a window of mismatch after every change.
- Event-driven export. A price or stock change in the record triggers a regeneration, or an update to the affected rows only. The window shrinks to the time the job takes.
- API push. You send changes directly to the platform's API, for example the Google Merchant API, as soon as they happen. This gives the smallest window but needs error handling and retry logic.
Many platforms also check prices on the product page itself and may use the page's structured data to correct the feed automatically. Do not rely on this. Treat it as a safety net, because behavior and eligibility rules differ per platform and change over time.
Pick the strategy by how fast your facts change. A store with a few price changes per month can run a scheduled export every few hours. A store with flash sales or limited stock needs event-driven updates or an API push.
Caching can break the comparison
The platform fetches the product page to compare it with the feed. If a CDN or cache still serves the old page, the page shows the old price while the feed shows the new one. The platform then sees a mismatch that you caused with caching, not with data.
Whenever the record changes, do both of these:
- regenerate the feed row (or the whole feed), and
- purge or revalidate the cached product page, as described in the previous chapter on cache invalidation.
Feed files themselves can also be cached. Serve them with short freshness times and a Last-Modified or ETag header, so the platform can fetch them cheaply and still get new content. If the platform fetches the feed from a URL, that URL should never return an old file after a successful export. Write the new file to a temporary name and rename it only when it is complete, so a fetch never reads a half-written feed.
Variants, sale prices, and currencies
Three details cause many mismatches.
Variants. A shoe in three sizes may be three feed rows with the same item_group_id but different id values. Each row needs its own price and stock status. If your page shows one price for all sizes, but one size is sold out, that row must say out_of_stock while the others stay in_stock. Your JSON-LD should then describe the same variant as the visible page selection.
Sale prices. A sale price in the feed needs a start and end date, and the page must show the sale price during that period. When the sale ends, the record should revert to the regular price, and all three outputs should change together. A sale that ends in the page template but not in the feed is a very common error.
Currency and formatting. Keep the amount as a decimal, not a float. Use one currency per market and format each output as its specification requires. The feed uses 89.00 EUR. The JSON-LD uses "price": "89.00" and "priceCurrency": "EUR". Taxes are a separate issue. Some markets require the displayed price to include tax, and the feed must follow the same rule as the page.
Discontinued and changed products
When a product is retired, handle the feed and the page together. Remove the row from the feed on the next export, or mark it out_of_stock for a short period if the page still exists and explains the situation. Then apply the page treatment you chose in the earlier chapter, such as a redirect to a successor or a clear discontinued notice. A feed row that points at a page returning 404 triggers a landing page error and removes the product from listings.
If a product changes in a meaningful way, such as a new model number, a different size, or a changed material, update the title, description, and attributes in the feed with the page. Keep the id stable when the product is the same item. Create a new id when it is a different product.
Checking the feed
A feed audit compares the generated feed with the live pages. The check below fetches each feed row's page, reads the Offer from its JSON-LD, and reports differences in price and availability. It uses only the Python standard library.
import json
import re
import urllib.request
LD_PATTERN = re.compile(
r'<script type="application/ld\+json">(.*?)</script>', re.S)
def page_offer(url):
with urllib.request.urlopen(url, timeout=10) as resp:
html = resp.read().decode('utf-8')
for block in LD_PATTERN.findall(html):
data = json.loads(block)
if data.get('@type') == 'Product':
return data['offers']
return None
def compare(row):
offer = page_offer(row['link'])
if offer is None:
return ['no Product JSON-LD found']
problems = []
feed_price, feed_currency = row['price'].split(' ')
if feed_price != offer['price'] or feed_currency != offer['priceCurrency']:
problems.append('price differs')
feed_stock = row['availability'] == 'in_stock'
page_stock = offer['availability'].endswith('InStock')
if feed_stock != page_stock:
problems.append('availability differs')
return problems
# Example call, with a row read from your own feed:
# print(compare({'link': 'https://example.com/p/trail-runner-2',
# 'price': '89.00 EUR', 'availability': 'in_stock'}))Run a check like this after every export and on a daily schedule. It catches both feed bugs and caching bugs, because it reads the page the same way a platform would. A later chapter covers wiring checks like this into alerts.
Common errors
- Separate data sources. The feed is built from a spreadsheet or an old export while the page reads the live database. Build both from the same record.
- Unstable IDs. Re-importing products creates new IDs, and the platform treats them as new items with no history. Use the SKU or another permanent key.
- Stale cache on the page. The feed is right and the page is old. Purge the page when the record changes.
- Forgotten end dates. Sale prices stay in the feed after the sale. Store sale dates in the record and generate all outputs from them.
- Silent export failures. A job fails and the old file keeps being served. Alert when the feed is older than your allowed age, for example by checking its
Last-Modifiedheader. - Rows for pages that no longer exist. Remove discontinued rows or point them at a working page.
Exercise
A product's price changes from 89.00 EUR to 79.00 EUR at 09:00. The page and the JSON-LD show 79.00 EUR straight away, but the merchant platform reports a price mismatch for several hours. Name two likely causes and one fix for each.
Show answer
Cause 1: the feed is built by a scheduled export that has not run again, so it still says 89.00 EUR. Fix: trigger a feed update when the product record changes, or use an API push. Cause 2: the platform fetched a cached copy of the page that still shows the old price, or the feed was refreshed but the page cache was not purged. Fix: purge or revalidate the product page whenever the record changes, and keep cache freshness times short.
Exercise
Your feed lists a sale price for a product, and the sale ended last night. The page shows the regular price. Which part of the design failed, and how should it be changed?
Show answer
The sale price and its end date were not stored in, and generated from, the single product record, so the feed kept its own sale data. Store the sale price and dates in the record, make the page, JSON-LD, and feed all read from it, and generate the regular price in every output once the sale ends.