# Hreflang & Canonical Validator (`afkdigital/hreflang-canonical-validator`) Actor

Audit multilingual URL relationships with HTTP evidence and explicit coverage.

- **URL**: https://apify.com/afkdigital/hreflang-canonical-validator.md
- **Developed by:** [AFK Digital](https://apify.com/afkdigital) (community)
- **Categories:** SEO tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00 / 1,000 completed unique page audits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Hreflang & Canonical Validator

Audit a multilingual release from the HTTP responses that a client can actually retrieve. Each dataset item represents one unique, successfully inspected final URL. The top-level finding is the most severe observation. Expand `findings` for every relationship and `declarations` for source, original href, resolved URL and language. Target status is the numeric HTTP response when available. Run coverage, including failed seed requests and unattempted seeds, is available in the OUTPUT key-value record.

### Run an audit

Supply `urls` or a public `pagesFile` containing UTF-8 URLs on separate lines or a JSON string array (2 MB maximum). Both omitted runs a two-page Google Search Central example. For cross-domain locales, list every permitted hostname in `allowedDomains`. Hostnames match exactly. Defaults are the seed hosts. Enable `followAlternateLinks` for discovery. Additional completed pages incur exactly the same page event as seeds. Seed URLs are checked first. `maxPages` limits seed plus discovered URL attempts together (default 5, maximum 500). Each attempt allows five redirect hops. `maxAlternatesPerPage` limits discovery per page (default 20). HTTP deadline defaults to 12 seconds per page. Increase the platform run timeout for large jobs.

### Billing

Pricing is USD 0.003 per completed unique page (USD 3 per 1,000). The Store event is one **apify-default-dataset-item** per distinct completed final page, including pages discovered by following alternates. Rows with multiple findings, retries, redirects and repeated aliases create no additional events for that final URL in the same run. Failed requests are recorded in OUTPUT and have no page event. Set the Apify run spending limit in addition to maxPages. The Actor floors the monetary limit to a whole number of pages when PPE pricing is active. A separately started run is a new audit.

### Interpretation and boundaries

The parser reads HTML head link elements and HTTP Link response fields. HTML relative references resolve against the document's first base href or final URL. HTTP Link targets resolve against the final response URL. Relative alternate declarations are flagged because Google requests absolute URLs. The Google-oriented locale profile accepts assigned ISO 639-1 languages, optional ISO 15924 scripts and optional ISO 3166-1 alpha-2 regions. Numeric region subtags such as es-419 receive a profile warning. x-default is a fallback. Different country domains are valid. The audit identifies conflicting same-language targets, multiple canonical declarations, missing self-reference, observed return links, redirects, retrieval failures and targets declaring a different preferred URL. Return-link status describes observed URL linkage. A complete target inspection is required to report a missing return. Inspect the associated language evidence separately.

Only successful complete responses are audited. HTML parsing targets text/html, including error-tolerant HTML5 head parsing. Other media expose HTTP headers only. Anchored HTTP Link entries are omitted. No browser, authenticated session, cookies or proxy are used. JavaScript-injected tags may be invisible. Sitemap hreflang is outside v1 coverage and a non-empty optionalSitemapFiles input is rejected. Bodies over 2 MB, unsupported content encodings and excessive declaration sets are skipped. Private, reserved and local destinations are checked on every request, including redirects and file downloads. Connections use a validated IP with the original host for TLS verification.

A canonical is the publisher's declared preference. This audit cannot establish which canonical a search engine selected or predict SEO performance.

### Integrations

See examples/n8n.md and examples/make.md for a two-page request, cost caps and mapping nested findings.

### References

- Google Search Central, [localized versions](https://developers.google.com/search/docs/specialty/international/localized-versions)
- Google Search Central, [canonical URLs](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls)
- IETF, [Web Linking, RFC 8288](https://www.rfc-editor.org/rfc/rfc8288)
- Apify, [pay-per-event pricing](https://docs.apify.com/platform/actors/publishing/monetize/pay-per-event)

# Actor input Schema

## `urls` (type: `array`):

One absolute HTTP(S) URL per entry.

## `pagesFile` (type: `string`):

Public UTF-8 newline-delimited URLs or JSON array. Choose this or urls.

## `allowedDomains` (type: `array`):

Exact hosts, including redirect destinations. Defaults to seed hosts.

## `followAlternateLinks` (type: `boolean`):

Additional completed pages use the same paid page event.

## `maxPages` (type: `integer`):

Total unique seed and alternate attempts, including failures.

## `maxAlternatesPerPage` (type: `integer`):

Limits discovery on each page. Already fetched targets can still be evaluated.

## `timeoutSeconds` (type: `integer`):

Wall-clock limit per page including redirects.

## `optionalSitemapFiles` (type: `array`):

Leave empty. Sitemap ingestion is unavailable in v1.

## Actor input object example

```json
{
  "urls": [
    "https://developers.google.com/search/docs/specialty/international/localized-versions",
    "https://developers.google.com/search/docs/specialty/international/localized-versions?hl=de"
  ],
  "followAlternateLinks": false,
  "maxPages": 5,
  "maxAlternatesPerPage": 20,
  "timeoutSeconds": 12
}
```

# Actor output Schema

## `pages` (type: `string`):

No description

## `coverage` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        "https://developers.google.com/search/docs/specialty/international/localized-versions",
        "https://developers.google.com/search/docs/specialty/international/localized-versions?hl=de"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("afkdigital/hreflang-canonical-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "urls": [
        "https://developers.google.com/search/docs/specialty/international/localized-versions",
        "https://developers.google.com/search/docs/specialty/international/localized-versions?hl=de",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("afkdigital/hreflang-canonical-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    "https://developers.google.com/search/docs/specialty/international/localized-versions",
    "https://developers.google.com/search/docs/specialty/international/localized-versions?hl=de"
  ]
}' |
apify call afkdigital/hreflang-canonical-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,afkdigital/hreflang-canonical-validator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/aINIcyraOIQQK9o4a/builds/cV2N2dwOwNrjh8aH1/openapi.json
