Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEO Audits] Document has a valid hreflang code #3177

Closed
rviscomi opened this issue Aug 29, 2017 · 12 comments
Closed

[SEO Audits] Document has a valid hreflang code #3177

rviscomi opened this issue Aug 29, 2017 · 12 comments

Comments

@rviscomi
Copy link
Member

Audit group: Content best practices
Description: Document has a valid hreflang
Failure description: Document does not have a valid hreflang ({value...})
Help text: Allows crawlers to discover alternate translations of the page content. Read more in the Search Console Help page.

Success condition: Query selector head > link[rel=alternate][hreflang] doesn’t exist, or the hreflang value passes aXe validation for each respective link tag.

Notes

@kdzwinel
Copy link
Collaborator

kdzwinel commented Nov 6, 2017

@rviscomi some questions:

  • we should also probably validate the URL? Docs don't mention anything about relative URLs, but I'd assume they are also valid.
  • should we check if website has a hreflang for itself? That's recommended according to the help page
  • it'd be great if we could also check if page linked in hreflang links back to current page ("Missing confirmation links") - but that'd require us to load, pottentially multiple, external pages, so I assume we will have to skip it?
  • we can probably reuse list of languages from AXE, but we will have to maintain lists of regions and scripts ourselves (thankfully, these lists aren't too big). Is that correct or have I maybe missed something here?
  • what do you mean by a[hreflang]? Help page doesn't mention <a>s 🤔

Notes to self:

  • remember about reserved (and valid) value of x-default
  • edgecase - language - script - region - e.g. zh-Hans-TW - should be valid
  • edgecase - "Do not specify a country code by itself" - e.g ES should be invalid

@rviscomi
Copy link
Member Author

rviscomi commented Nov 7, 2017

we should also probably validate the URL? Docs don't mention anything about relative URLs, but I'd assume they are also valid.

Let's skip URL validation and focus on the hreflang value.

should we check if website has a hreflang for itself? That's recommended according to the help page

Is this just the <html lang="..."> attribute? (already validated)

it'd be great if we could also check if page linked in hreflang links back to current page ("Missing confirmation links") - but that'd require us to load, pottentially multiple, external pages, so I assume we will have to skip it?

Skip it

we can probably reuse list of languages from AXE, but we will have to maintain lists of regions and scripts ourselves (thankfully, these lists aren't too big). Is that correct or have I maybe missed something here?

Let's keep this in sync with the <html lang> validation, so limit to languages if that's all it does. Of course, this audit would need to support x-default in addition.

what do you mean by a[hreflang]? Help page doesn't mention s

Anchors can also have hreflang attrs but let's leave that outside the scope of this audit for now.

@kdzwinel
Copy link
Collaborator

kdzwinel commented Nov 7, 2017

should we check if website has a hreflang for itself? That's recommended according to the help page

Is this just the <html lang="..."> attribute? (already validated)

Sorry, I meant if we should check if website links to itself via link[rel=alternate] (as it should)? But since you said we should skip URL validation, I'm guessing we won't be checking that either?

@rviscomi
Copy link
Member Author

rviscomi commented Nov 8, 2017

Oh ok. Yeah this audit should only be concerned with the language values themselves.

@fbessonnat
Copy link

fbessonnat commented Jul 12, 2018

Guys, It's not all aligned with the HrefLang Google recommendation: https://support.google.com/webmasters/answer/189077?hl=en

Eg. https://www.maxwellbaynes.com/fr/toutes-nos-proprietes shows a Light-House positive hreflang validation but this is not the case... probably it's okay because a <html lang="xx" > is found. That's a mistake and not aligned at all with what Google algorithm expects....

We should only validate if there's a (<link> tag or <a> tag) including:

  • attribute rel="alternate"
    and
  • attibute 'hreflang' with a value 'xx' or 'xx-xx' or 'x-default'

Examples of correct use:

<link rel="alternate" hreflang="en" href="http://en-gb.example.com/page.html" />
<link rel="alternate" hreflang="en-gb" href="http://en-gb.example.com/page.html" />
<link rel="alternate" hreflang="x-default" href="http://en-gb.example.com/page.html" />

Also... in case Light-House is also able to deal with HTTP headers, Hreflang infos can also be set by webmaster on it.

Here's the HTTP Header format supported by Google:
Link: <url1>; rel="alternate"; hreflang="lang_code_1", <url2>; rel="alternate"; hreflang="lang_code_2", ...

Ex.

Link: <http://example.com/file.pdf>; rel="alternate"; hreflang="en",
      <http://de-ch.example.com/file.pdf>; rel="alternate"; hreflang="de-ch",
      <http://de.example.com/file.pdf>; rel="alternate"; hreflang="de"

@rviscomi
Copy link
Member Author

@fbessonnat sorry your comment lost some of its markup so it's hard to read. Could you reformat it with code blocks?

@fbessonnat
Copy link

@rviscomi : done! (thx for the code block advice)

@rviscomi
Copy link
Member Author

rviscomi commented Jul 17, 2018

Prior to the v3.0 release, Lighthouse didn't have a concept of applicability of audits, so we chose to positively pass the audit even if there were no hreflang attributes to validate. In the case of this page, there aren't any so we pass the audit. It would be more accurate if we showed the audit in the "not applicable" category.

image

https://googlechrome.github.io/lighthouse/viewer/?gist=3b0850ab03d903417ed5a3b1059cd105

@fbessonnat would that address your concerns?

@fbessonnat
Copy link

fbessonnat commented Jul 17, 2018

@rviscomi : just to clarify, if there's a [link alternate hreflang], yes, we can a add a "Document has a valid alternate hreflang" on the "Not applicable" section (very good choice).
But, if there's no [link alternate hreflang], it's not a problem and no mention should appear in the SEO audit report.

@rviscomi
Copy link
Member Author

@fbessonnat I'm actually suggesting the opposite:

If hreflang exists on the page, it shows up normally as either pass/fail depending on its validity.
Otherwise, it shows up as "Not applicable".

I think you're looking at the "Not applicable" section as "audits that do not need my attention because they passed". We treat it as "audits that have no conclusive result because they do not apply to the current page". WDYT?

@fbessonnat
Copy link

@rviscomi : Yes, I didn't have the good "Not applicable" vision. So, yes, if no hreflang the "Not applicable" section is the right place. :)

@crmpicco
Copy link

crmpicco commented Mar 9, 2023

I have a <link rel="alternate" hreflang="en" href="https://crmpicco.co.uk/en/login"> in my markup yet PageSpeed Insights still shows me the following error:

Document doesn't have a valid hreflang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants