Sub topic 16
Auditing and monitoring your metadata
This chapter assumes you can write the title, meta description, and canonical elements covered earlier. It also assumes you know what a Google-style results page looks like, what HTTP status codes mean, and how to read a short Python script. Here you will turn that knowledge into a repeatable check that finds problems on a live site and catches new ones after each release.
What an audit looks for
Metadata breaks quietly. A template change can remove every canonical on the site, and nothing looks wrong in the browser. An audit compares what each URL actually serves against a short list of rules.
| Element | Problem to detect | Why it matters |
|---|---|---|
| Title | Missing, empty, or multiple `<title>` elements | The engine has to invent a title |
| Title | Same text on many URLs | Pages are hard to tell apart in results |
| Title | Very long (over roughly 60 characters) | Likely truncated in results |
| Description | Missing, duplicated, or very long | The snippet is generated from page text instead, or cut off |
| Canonical | Missing | The engine picks a canonical on its own |
| Canonical | Relative URL, or more than one canonical | May be ignored |
| Canonical | Target redirects, returns 404, or is noindexed | Conflicting signals, hint likely discarded |
| Canonical | Every page points to the home page | Pages can drop out of the index |
The length limits are heuristics. Results truncate by pixel width, not character count, so treat 60 and 160 as flags for a human to review, not as hard errors.
The audit workflow
The workflow has four steps. You get a list of URLs, fetch each one, extract the metadata, and apply rules. Then you compare the result against what the search engine reports.
Start the URL list from your sitemap. Then add URLs found by a crawl, because the sitemap often omits the parameter and pagination URLs where canonical problems appear. If a URL lists itself in the sitemap but canonicalizes elsewhere, that conflict is itself a finding.
A small audit script
Crawlers such as Screaming Frog or Sitebulb do this at scale. A short script is still useful for one site section, for a CI job, or when you want to see exactly what rule was applied. This one uses only the Python standard library. It reads one URL per line from a file, reports problems for each URL, and reports duplicate titles across the whole list.
import sys
from collections import defaultdict
from html.parser import HTMLParser
from urllib.parse import urljoin, urlparse
from urllib.request import Request, urlopen
class HeadParser(HTMLParser):
def __init__(self):
super().__init__()
self.titles = []
self.descriptions = []
self.canonicals = []
self.robots = []
self._in_title = False
self._in_body = False
self._buf = []
def handle_starttag(self, tag, attrs):
a = dict(attrs)
if tag == "body":
self._in_body = True
elif tag == "title" and not self._in_body:
self._in_title = True
self._buf = []
elif tag == "meta":
name = (a.get("name") or "").lower()
if name == "description":
self.descriptions.append((a.get("content") or "").strip())
elif name == "robots":
self.robots.append((a.get("content") or "").lower())
elif tag == "link":
rel = (a.get("rel") or "").lower().split()
if "canonical" in rel:
self.canonicals.append((a.get("href") or "").strip())
def handle_endtag(self, tag):
if tag == "title" and self._in_title:
self._in_title = False
self.titles.append("".join(self._buf).strip())
def handle_data(self, data):
if self._in_title:
self._buf.append(data)
def fetch(url):
req = Request(url, headers={"User-Agent": "metadata-audit/1.0"})
with urlopen(req, timeout=15) as resp:
charset = resp.headers.get_content_charset() or "utf-8"
body = resp.read(2_000_000).decode(charset, errors="replace")
return resp.status, resp.geturl(), body
def audit(url, titles_seen):
problems = []
status, final_url, body = fetch(url)
if final_url != url:
problems.append(f"redirects to {final_url}")
p = HeadParser()
p.feed(body)
if len(p.titles) != 1 or not p.titles[0]:
problems.append(f"expected one non-empty title, found {p.titles}")
else:
titles_seen[p.titles[0]].append(url)
if len(p.titles[0]) > 60:
problems.append(f"title is {len(p.titles[0])} characters")
if len(p.descriptions) != 1 or not p.descriptions[0]:
problems.append("missing or repeated meta description")
elif len(p.descriptions[0]) > 160:
problems.append(f"description is {len(p.descriptions[0])} characters")
if len(p.canonicals) != 1:
problems.append(f"expected one canonical, found {len(p.canonicals)}")
else:
href = p.canonicals[0]
if not urlparse(href).scheme:
problems.append(f"canonical is not absolute: {href}")
target = urljoin(final_url, href)
if target != final_url:
try:
t_status, t_final, _ = fetch(target)
if t_final != target:
problems.append(f"canonical target redirects to {t_final}")
except Exception as exc:
problems.append(f"canonical target failed: {exc}")
if any("noindex" in r for r in p.robots) and p.canonicals:
problems.append("noindex combined with a canonical")
return problems
def main(path):
titles_seen = defaultdict(list)
with open(path, encoding="utf-8") as f:
urls = [line.strip() for line in f if line.strip()]
for url in urls:
try:
problems = audit(url, titles_seen)
except Exception as exc:
problems = [f"fetch failed: {exc}"]
for problem in problems:
print(f"{url}: {problem}")
for title, group in titles_seen.items():
if len(group) > 1:
print(f"Duplicate title {title!r} on {len(group)} URLs: {group}")
if __name__ == "__main__":
main(sys.argv[1])Run it with python audit.py urls.txt. It does not read the Link header, so PDFs and other non-HTML files need a separate check of the response headers. It also reads the HTML as served. Pages that inject tags with JavaScript need a rendering crawler, because a search engine may see something different from this script.
Compare with what the search engine reports
A clean audit shows what you declared. The search engine's reports show what it decided.
- Page indexing report (Google Search Console): The statuses "Duplicate without user-selected canonical" and "Duplicate, Google chose different canonical than user" mean your hint was missing or overruled. Inspect an affected URL and compare the user-declared canonical with the Google-selected one.
- Performance report: Filter by page and look for a click-through rate far below pages of similar rank. Weak titles and descriptions often explain this.
- Live results: Search for the exact title in quotes, or use the
site:operator for a section. A displayed title that differs from your<title>is a rewrite. Compare it with the cases from the earlier chapter on why engines rewrite titles.
When the reports disagree with your crawl, trust the crawl for what you serve and the report for what the engine did. Then look for the cause between them: a redirect, a robots.txt block, a conflicting sitemap entry, or JavaScript that changes the tags.
Triage and monitoring
Fix problems in order of how many pages they affect and how much traffic those pages get.
- Template-wide faults first: a missing canonical, a canonical pointing at the home page, or a title that is identical on every page.
- Conflicting signals next: canonicals to redirected or noindexed URLs.
- Duplicate titles and descriptions on important pages.
- Length and wording improvements, starting with high-impression, low-click pages.
Audits are only useful if they repeat. Three habits keep metadata from regressing.
- Test in CI. Run the script (or a few template unit tests) against a staging build. Fail the build if a page has no canonical or has two titles.
- Crawl on a schedule. A weekly crawl of the sitemap and key templates, with results saved, lets you diff this week against last week. A sudden jump in "missing description" points to a specific deploy.
- Watch after migrations. URL changes, CMS upgrades, and framework changes are when canonicals break. Crawl before launch and again within a day after it.
Exercise
Your audit shows 4,000 product URLs with a single canonical each, no errors, and no duplicate titles. Search Console still reports many of them as "Duplicate, Google chose different canonical than user." Name two checks to run next.
Show answer
First, use URL Inspection on a few affected URLs and compare the user-declared canonical with the Google-selected one, to see which URL Google prefers. Second, check for conflicting signals the script may miss: the declared canonical redirecting or returning a non-200 status, sitemap entries listing a different variant, internal links pointing mostly at another variant, or JavaScript changing the canonical after render. Also confirm the pages are not near-identical in content, since Google may treat canonical as a hint and override it for duplicates.