Sub topic 12
Keeping the feed and landing pages consistent
This chapter assumes you can read a product feed item and a schema.org Product JSON-LD block, as shown in the earlier chapters, and that you can run a short Python script. It covers which values must agree across the feed, the page markup, and the visible page, why they drift apart, and how to catch drift automatically.
What consistency means
A shopping system usually sees one product from three places:
- The feed item you submitted (the
g:attributes). - The structured data on the landing page (JSON-LD
ProductandOffer). - The visible page a shopper sees after clicking.
Consistency means these three describe the same offer. The values do not need identical wording. The facts must match: price, currency, availability, identifiers, and which variant is on the page.
Systems cross-check these sources. When they disagree, the usual outcomes are a disapproved item, a warning in diagnostics, or an item that is quietly shown with less prominence. A wrong price can also reach a shopper, because an answer may quote a value that was correct hours ago.
Fields that must agree
| Feed attribute | Page structured data | Visible page | Rule |
|---|---|---|---|
| `g:price` / `g:sale_price` | `offers.price`, `offers.priceCurrency` | Price shown near the buy button | Same amount and currency. If a sale price is active, the page's current price is the sale price. |
| `g:availability` | `offers.availability` | Stock message, enabled or disabled buy button | Map `in_stock` to `InStock`, `out_of_stock` to `OutOfStock`, and so on. |
| `g:gtin`, `g:mpn` | `gtin14` (or `gtin13`, `gtin12`, `gtin8`), `mpn` | Often in a specs table | Same identifier. Leading zeros may differ in length, but the digits must be the same. |
| `g:brand` | `brand.name` | Brand name | Same brand. |
| `g:link` | `offers.url` | The address the shopper lands on | Must open the same variant the feed item describes. |
| `g:title`, `g:description` | `name`, `description` | Heading, product copy | Same product and variant. Wording can differ slightly. |
| `g:condition` | `offers.itemCondition` | Condition label | `new` maps to `NewCondition`. |
The two example blocks from the data-model chapter, the RSS item and the JSON-LD for the Acme jacket, follow this table. The price is 89.00 USD in the feed and "price": "89.00" with "priceCurrency": "USD" in the markup. Availability is in_stock and https://schema.org/InStock.
Use one source of truth
Drift happens when each output is built by a different process. The feed comes from a nightly export, the JSON-LD comes from a theme template, and the visible price comes from a JavaScript widget that calls a pricing service. Three code paths means three chances to disagree.
The fix is to generate all three from the same record.
Where a single record is not possible, for example because the page price depends on a promotions service, make the feed export call the same pricing function the page uses. Do not copy its rules into a second implementation.
Common causes of drift
- Timing. A price changes in the database at 10:00, but the feed is fetched at 06:00 and refreshes only once a day. Chapter on freshness covers schedules. Here, note that a short mismatch window is normal and a long one is a defect.
- Sale prices. The feed has
sale_pricebut the page markup still shows the regular price, or the reverse. Decide thatoffers.priceis always the price a shopper pays now. - Currency and tax. The feed price includes tax for one country, while the page shows the pre-tax figure. Follow the account's rules for the target country and apply them in both places.
- Variants. The feed
linkhas no variant parameters, so the page opens its default color and size. The shopper sees a different price or an out-of-stock message. - Client-side rendering. JSON-LD or the price is injected by JavaScript. A crawler that reads only the raw HTML may find no price, or an old placeholder.
- Redirects and geography. The page redirects by country or shows a cookie wall, so the crawler cannot see the product.
- Out-of-stock handling. The page is removed or redirected when stock is zero, while the feed still says
in_stock.
Automating the comparison
A checker that reads the feed, fetches each landing page, extracts the JSON-LD, and compares the key fields catches most of these problems. The script below uses only the standard library. It reads the raw HTML, which is what a simple crawler sees, so it also reveals JSON-LD that only exists after JavaScript runs.
import json
import sys
import urllib.request
import xml.etree.ElementTree as ET
from decimal import Decimal, InvalidOperation
from html.parser import HTMLParser
NS = {"g": "http://base.google.com/ns/1.0"}
AVAILABILITY = {
"in_stock": "https://schema.org/InStock",
"out_of_stock": "https://schema.org/OutOfStock",
"preorder": "https://schema.org/PreOrder",
"backorder": "https://schema.org/BackOrder",
}
class JsonLdParser(HTMLParser):
def __init__(self):
super().__init__()
self.in_ld = False
self.buffer = []
self.blocks = []
def handle_starttag(self, tag, attrs):
if tag == "script" and ("type", "application/ld+json") in attrs:
self.in_ld = True
self.buffer = []
def handle_data(self, data):
if self.in_ld:
self.buffer.append(data)
def handle_endtag(self, tag):
if tag == "script" and self.in_ld:
self.in_ld = False
self.blocks.append("".join(self.buffer))
def find_product(html):
parser = JsonLdParser()
parser.feed(html)
for block in parser.blocks:
try:
data = json.loads(block)
except ValueError:
continue
nodes = data if isinstance(data, list) else data.get("@graph", [data])
for node in nodes:
if isinstance(node, dict) and node.get("@type") == "Product":
return node
return None
def feed_value(item, tag):
node = item.find("g:" + tag, NS)
return node.text.strip() if node is not None and node.text else ""
def split_price(text):
amount, _, currency = text.partition(" ")
try:
return Decimal(amount), currency
except InvalidOperation:
return None, currency
def compare(item, product):
problems = []
offer = product.get("offers", {})
if isinstance(offer, list):
offer = offer[0] if offer else {}
current = feed_value(item, "sale_price") or feed_value(item, "price")
amount, currency = split_price(current)
try:
page_amount = Decimal(str(offer.get("price", "")))
except InvalidOperation:
page_amount = None
if amount != page_amount:
problems.append("price: feed %s, page %s" % (amount, page_amount))
if currency != offer.get("priceCurrency"):
problems.append("currency: feed %s, page %s" % (currency, offer.get("priceCurrency")))
expected = AVAILABILITY.get(feed_value(item, "availability"))
if expected != offer.get("availability"):
problems.append("availability: feed %s, page %s" % (expected, offer.get("availability")))
feed_gtin = feed_value(item, "gtin").lstrip("0")
page_gtin = next((str(v).lstrip("0") for k, v in product.items() if k.startswith("gtin")), "")
if feed_gtin and feed_gtin != page_gtin:
problems.append("gtin: feed %s, page %s" % (feed_gtin, page_gtin))
brand = product.get("brand", {})
page_brand = brand.get("name") if isinstance(brand, dict) else brand
if feed_value(item, "brand") != page_brand:
problems.append("brand: feed %s, page %s" % (feed_value(item, "brand"), page_brand))
return problems
def main(path):
failed = 0
for item in ET.parse(path).getroot().iter("item"):
item_id = feed_value(item, "id") or "(no id)"
request = urllib.request.Request(
feed_value(item, "link"), headers={"User-Agent": "feed-consistency-check"}
)
try:
with urllib.request.urlopen(request, timeout=10) as response:
html = response.read().decode("utf-8", errors="replace")
except OSError as error:
failed += 1
print(item_id + ": page not reachable (" + str(error) + ")")
continue
product = find_product(html)
if product is None:
failed += 1
print(item_id + ": no Product JSON-LD in the raw HTML")
continue
for problem in compare(item, product):
failed += 1
print(item_id + ": " + problem)
print("mismatches found: " + str(failed))
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1]))Run it as python check_consistency.py feed.xml. It exits with status 1 when it finds a mismatch, so you can run it in a scheduled job or before each feed upload.
Edge cases to handle
- Price ranges. A parent page may show "from 79.00" while each feed item has a single variant price. Mark up the offer for the selected variant, not the range.
- Rounding. Compare prices as decimals, not floats or strings.
89and89.00are the same price, and89.0should not trigger an alert. - Multiple offers. Marketplace pages can list several sellers. The offer matching your feed item must be the one that appears in your markup.
- Sampling. Fetching every page each hour may overload your site. Check all items nightly, and check high-traffic or recently changed items more often.
Fixing mismatches in order
- Group failures by field. A hundred price mismatches with the same cause, such as sale prices missing from the template, are one fix.
- Check whether the feed or the page holds the correct value, and trace both back to the record.
- Fix the generator, not the individual output.
- Re-run the checker, then resubmit or fetch the feed so the account sees the corrected data.
Exercise
A feed item has <g:price>120.00 USD</g:price> and <g:sale_price>99.00 USD</g:sale_price>. The page's JSON-LD has "price": "120.00", and the checker above reports a price mismatch. What is wrong, and where should the fix be made?
Show answer
The checker treats the sale price as the current price, so it expects the page to show 99.00. The JSON-LD still shows the regular price, which means the page template ignores the active sale price. Fix the template, or better, the shared pricing function it uses, so that offers.price is the price the shopper pays now. Then regenerate the markup and the visible price together and re-run the checker.