Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Canonical set by JavaScript differs from HTML: how to fix it

SEO-048Medium impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

A canonical tag is a line in the <head> that tells search engines which URL is the main version of a page. Google reads it twice: once in the raw HTML the server sends, and again in the rendered HTML after JavaScript has run.

This issue appears when those two versions disagree. For example, the raw HTML says https://example.com/shoes/ while a script rewrites it to https://example.com/shoes/?color=red, or to the home page. Common sources are Google Tag Manager custom HTML tags, single-page app frameworks, A/B testing tools and SEO plugins that run alongside theme code.

How the conflict happens
  1. Server sends HTMLCanonical points to /shoes/
  2. JavaScript runsScript rewrites canonical to /shoes/?color=red
  3. Google renders pageSees two different canonicals
  4. IndexingWrong URL may be chosen or both ignored

The server and the script each declare a different canonical.

Why it costs you leads or sales

Google says that if canonical signals conflict, it may pick one or ignore them. That means the page you want to rank can be treated as a duplicate of another URL. Ranking signals may then split across versions, or the wrong version (a filtered, parameter or tracking URL) shows in results.

For landing pages and product pages this hurts twice. Traffic lands on a URL you did not plan for, and your reporting then shows organic visits against the wrong pages. Impact is usually medium: it rarely removes a page overnight, but it quietly weakens rankings.

How it usually unfolds (example)
  1. Day 0

    A tag manager tag is added that sets the canonical from the current URL.

  2. Week 1

    Google crawls and renders pages. Raw and rendered canonicals differ.

  3. Week 3

    Parameter URLs start appearing in the index instead of clean URLs.

  4. Week 4

    Script is removed, both canonicals match, and Google reprocesses over time.

How to check if your site has it

Compare raw and rendered canonicals
  1. View the raw HTML

    Open the page in Chrome, press Ctrl+U (Cmd+Option+U on Mac) to open view-source, and search for canonical. Note the URL.

  2. View the rendered HTML

    Right-click the page, choose Inspect, and in the Elements panel search for rel="canonical". This shows the DOM after scripts ran. Note the URL.

  3. Compare with Google's view

    In Google Search Console, use URL Inspection, then View crawled page (HTML) and Test live URL. Compare the canonical there with the raw source. Also check which canonical Google selected under Page indexing.

  4. Check in bulk

    A crawler such as Screaming Frog can crawl with JavaScript rendering on and list pages where the raw and rendered canonicals differ. Run it on key templates first: home, category, product, landing pages.

Console check: print the live canonicaljavascript
document.querySelectorAll('link[rel="canonical"]').forEach(function (l) { console.log(l.href); });

Paste the snippet into the browser console on a page. Then compare the output with the canonical in view-source. If they differ, a script is changing it.

How to fix it

The safest rule: output the canonical once, on the server, in the <head>. Then make sure nothing in the browser edits it. Find which script does the change first, using the Elements panel (right-click the tag, Break on, attribute modifications) or by pausing tags in Tag Manager preview mode.

Fix by platform
  1. Run one canonical source

    Yoast, Rank Math, All in One SEO and some themes can each print a canonical. Keep one and disable the canonical output in the others.

  2. Check for scripts

    Look in your theme's header and any header or footer script plugin for code that sets link[rel=canonical]. Remove it.

One canonical in the server HTML headhtml
<head>
  <link rel="canonical" href="https://example.com/shoes/">
</head>
Canonical signals before and after

Before

  • Raw HTML canonical: /shoes/
  • Rendered canonical: /shoes/?color=red
  • Google may choose either URL

After

  • Raw HTML canonical: /shoes/
  • Rendered canonical: /shoes/
  • One clear signal for Google

How to confirm it's fixed

Confirmation checklist
  • View-source and the Elements panel show the same canonical URL.
  • Only one canonical tag exists in the rendered page.
  • The canonical is absolute, uses https and has no tracking parameters.
  • URL Inspection in Search Console shows the same canonical in the crawled HTML.
  • A JavaScript-rendered crawl shows no canonical mismatches on your key templates.

Then request indexing for important URLs in Search Console. Google re-evaluates canonicals as it recrawls, so changes in the index can take days to weeks.

How to prevent it happening again

Prevention habits
  • Name one owner for canonicals: the CMS, theme or SEO plugin, never several.
  • Ban canonical edits in Tag Manager unless an SEO reviews them.
  • Add a raw versus rendered canonical check to your release checklist.
  • Re-run a JavaScript-rendered crawl after theme, plugin or framework updates.
  • Review Page indexing in Search Console for new 'Duplicate' or 'Alternate page with proper canonical tag' groups.

How FunnelGuard handles this

FunnelGuard does not check this yet. Comparing raw and rendered canonicals is a possible future check, but today it is not part of what FunnelGuard monitors.

What FunnelGuard does cover is nearby: a robot visitor runs your real journeys (lead forms, checkouts, booking and chat buttons) on a schedule and checks each step and the tracking hits sent to platforms such as GA4, Google Ads and Meta. If a tag change breaks a step or a tracking hit, you get one alert with a screenshot and a likely cause. It will not tell you that your canonical differs.

To watch for this yourself, schedule a monthly JavaScript-rendered crawl (for example in Screaming Frog) and compare raw and rendered canonicals, and check Search Console's Page indexing report after each release. You can also start with the free read-only website audit, or the Free plan (1 site, 2 journeys, daily checks, no card), to monitor your funnels in the meantime.

Questions people ask

Why is my canonical tag different in view-source and Inspect?

View-source shows the HTML the server sent, while Inspect shows the page after JavaScript ran. If they differ, a script such as a tag manager tag, framework or plugin is changing the canonical after load.

Does Google read a canonical set by JavaScript?

Yes. Google renders pages and can read canonicals in the rendered HTML. But it advises that the raw and rendered canonicals should match, and that a canonical set only by JavaScript is less reliable than one in the server HTML.

What happens if the raw and JavaScript canonicals conflict?

Google may use either one or ignore both and choose its own canonical. This can split ranking signals or put the wrong URL, such as a parameter version, in search results.

How do I find which script changes my canonical tag?

In Chrome DevTools, right-click the canonical link in the Elements panel and choose Break on, then attribute modifications. Reload the page and the debugger stops on the script. You can also pause tags in Google Tag Manager preview mode.

Can I set a canonical tag with Google Tag Manager?

You can, but it is risky. The tag runs after the page loads, so it can conflict with a canonical already in the HTML. Prefer setting it in the CMS or theme so it appears in the server response.

How do I check rendered canonicals across a whole site?

Use a crawler with JavaScript rendering enabled, such as Screaming Frog, and compare the raw and rendered canonical columns. Check a sample of each template if the site is large.

Does FunnelGuard detect canonical mismatches?

No. FunnelGuard does not check canonical tags yet. It monitors journeys, tracking hits and lead delivery, so use a rendered crawl and Search Console to watch for this issue.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.