# Seo Canonical Tag Checker (`eichan/seo-canonical-tag-checker`) Actor

- **URL**: https://apify.com/eichan/seo-canonical-tag-checker.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.01 / actor start

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

## SEO Canonical Tag Checker

**One job:** read canonical `<link rel="canonical">` declarations from the HTML **`<head>` of one page**. Ideal for site owners, SEOs, and developers who need a quick report of what a page itself declares.

The Actor does **not** decide whether a canonical is an appropriate SEO choice, nor does it validate the target URL with a network request.

### Input

Just one input property, `url` (string): an HTTP(S) URL to a public HTML page.

```json
{"url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link"}
```

This is also the prefilled example in `input_schema.json`. The URL was observed accessible without a redirect when checked on **2026-11-01**. Public sites may change at any time. The sample is not a login-protected page.

### Output

Output is written to the **Apify default dataset** (one JSON object per item), or to local `storage/datasets/default/000000001.json`, etc., when no Apify dataset ID is present.

```json
{
  "sourceUrl": "http://127.0.0.1:39085/canonical",
  "pageUrl": "http://127.0.0.1:39085/canonical",
  "canonicalUrl": "http://127.0.0.1:39085/canonical",
  "canonicalCount": 1,
  "isSelfReferencing": true,
  "status": "ok",
  "error": null,
  "note": "This page declares itself as its own canonical."
}
```

This item comes from the included **local fixture**. An absent canonical produces `canonicalUrl: null`, `canonicalCount: 0`, `isSelfReferencing: false`, and `status: "absent"`. Multiple canonical tags produce `status: "multiple"`; only the first canonical URL is displayed.

### How to run

1. Use Python 3.12+; no packages need installing. From this folder, set `ACTOR_INPUT_JSON` to the input JSON above and run `python src/main.py`.
2. Alternatively, put the JSON in `storage/key_value_stores/default/INPUT.json` and run the same command.
3. On Apify, the Actor reads `INPUT` from the default key-value store using its provided ID and `APIFY_TOKEN`, then POSTs the items to the default dataset; no Apify SDK is required.
4. For verification, run `python tests/test_actor.py` and `python tests/run_smoke.py`. The latter launches a temporary local HTTP test server and captures the **real script subprocess** output and JSON under `tests/evidence/`.

Input priority: `ACTOR_INPUT_JSON` → `APIFY_DEFAULT_KEY_VALUE_STORE_ID` with authenticated Apify GET → local INPUT.json. There is no exact-match check against an `APIFY_API_BASE_URL` environment value; the standard `https://api.apify.com` endpoint is used directly.

### Limits and safeguards

- One public HTML page; examines only canonical `<link>` elements inside `<head>`. Does not use HTTP Link response headers or JavaScript-generated tags.
- Relative canonical URLs are resolved using the document's first `<base href>` if present, otherwise the fetched URL; fragments are stripped.
- Self-reference compares the normalized page and canonical URL (case-folding the hostname, removing default ports and fragments); query strings remain significant.
- Multiple declarations are counted, but only the first URL is output. An empty first canonical is reported as `null`.
- Does not execute JavaScript, log into sites, use search-engine results, or fetch third-party website pages. No keys except Apify's own platform storage token.
- Honors robots.txt for the requested page and checked same-host redirects. A missing robots.txt (HTTP 404/410) is treated as no explicit restriction; other verification failures are returned as plain-language errors.
- Enforces HTTPS/HTTP, publicly routable DNS addresses, a 12-second timeout per request, up to 3 same-host redirects, and a 1.5 MB maximum HTML response. The server may impose its own rate limits.
- Script-mode tests use a temporary loopback-only test flag (`SEO_ACTOR_ALLOW_LOOPBACK=1`) and local fixtures; production use should leave this flag unset. Live Apify deployment and Docker builds were **not performed**.
- Errors are emitted as dataset items with stable null values and `status: "error"`, rather than Python tracebacks. If the dataset service is unavailable, a plain-language terminal error is printed.

### Store suggestions (not configured)

Categories: SEO tools, Marketing, Developer tools. Suggested price: **$0.01 per run**. Store details are recorded in `store_metadata.json`. Nothing is published or billed automatically.

# Actor input Schema

## `url` (type: `string`):

One fully qualified public HTTP(S) HTML page URL to inspect.

## Actor input object example

```json
{
  "url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link"
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# 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 = {
    "url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/seo-canonical-tag-checker").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 = { "url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/seo-canonical-tag-checker").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 '{
  "url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link"
}' |
apify call eichan/seo-canonical-tag-checker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/seo-canonical-tag-checker"
        }
    }
}
```

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/kRwpaUIvJOpbxTd0Q/builds/cPLihF3Vz03YPwTjY/openapi.json
