# Website On-Page SEO Regression Watch (`practical_ai_lab_jp/pal-website-onpage-seo-regression-watch`) Actor

Scheduled, robots-aware sitemap monitor that stores a text-only baseline per domain and reports URL-precise changes to title, meta description, first H1 and meta robots directives.

- **URL**: https://apify.com/practical_ai_lab_jp/pal-website-onpage-seo-regression-watch.md
- **Developed by:** [Practical AI Lab](https://apify.com/practical_ai_lab_jp) (community)
- **Categories:** E-commerce, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 85.7% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 seo delta reports

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Website On-Page SEO Regression Watch

Scheduled change detection for four on-page signals across a bounded sample of your sitemap pages:

- `<title>` text
- meta description text
- the first `<h1>` text
- meta robots directives (`robots` and `googlebot` meta tags, e.g. `noindex`, `nofollow`)

Run it once to store a text-only baseline for a domain. Run it again on a schedule and every difference is reported with the exact page URL, the previous and current value, the sitemap that listed the page, and UTC timestamps for both captures. Results are available as a dataset (JSON/CSV/Excel via the Apify export options) and as ready-made `REPORT.json`, `CHANGES.csv` and `SNAPSHOT.csv` records.

The Actor reports factual differences between two captures. It does **not** measure, predict or improve search rankings, traffic or indexing.

### Who it is for

Teams that publish through templates, plugins, CMS releases or several editors and want a cheap safety net: "did a deployment blank our titles, rewrite descriptions or add `noindex` to pages that should be indexed?" It is a regression alarm for a sample of pages, not a full site audit.

### Quick start

1. Set `startUrl` to the root of a site you own or are allowed to monitor (the prefilled `https://docs.apify.com/` is only a placeholder; replace it).
2. Run the Actor. The first run stores the baseline and returns `BASELINE_CREATED` with a snapshot of what was captured.
3. Schedule the same input (see below). Later runs return `CHANGES_DETECTED` or `NO_CHANGES`.

Copyable first-run input:

```json
{
    "startUrl": "https://docs.apify.com/",
    "maxPages": 10,
    "maxSitemapFiles": 3,
    "requestDelayMs": 1000,
    "baselineStoreName": "pal-seo-watch-baselines"
}
```

Only `startUrl` is required. Everything else has a default.

### Input

| Field | Default | Meaning |
| --- | --- | --- |
| `startUrl` | required | Public HTTPS site root. No path, query, credentials or custom port. IP addresses, `localhost` and private/reserved names are rejected. |
| `maxPages` | 20 (max 200) | Pages fetched per run. |
| `maxSitemapFiles` | 5 (max 10) | Sitemap or sitemap-index files fetched per run. Index nesting is limited to two levels. |
| `maxReportedChanges` | 200 (max 1000) | Change rows written per run, most severe first. The total is still counted. |
| `requestDelayMs` | 1000 (500-10000) | Pause between requests. A longer `Crawl-delay` in robots.txt (capped at 10 s) wins. |
| `pageMaxKb` | 512 (64-1024) | Larger pages are skipped, never partially analysed. |
| `updateBaseline` | true | On: compare with the previous run, then replace the baseline. Off: always compare with the pinned first baseline. |
| `resetBaseline` | false | Ignore the stored baseline and create a new one now. |
| `baselineStoreName` | `pal-seo-watch-baselines` | Named key-value store holding one baseline per domain. Empty string = the run's default store through `Actor.get_value/set_value`. |

Numeric values outside the allowed range are clamped to the nearest limit.

### Output

#### Dataset

- On `CHANGES_DETECTED`: one `CHANGE` row per difference.
- On every other outcome (`BASELINE_CREATED`, `NO_CHANGES` or a failure status): a single `RUN_STATUS` row.

Illustrative shape of a `CHANGE` row (values are placeholders, not real results):

```json
{
    "recordType": "CHANGE",
    "severity": "HIGH",
    "changeType": "FIELD_CHANGED",
    "domain": "www.example.org",
    "url": "https://www.example.org/pricing",
    "field": "robotsMeta",
    "previousValue": "",
    "currentValue": "nofollow, noindex",
    "previousCapturedAt": "2026-01-01T06:00:12Z",
    "checkedAt": "2026-01-02T06:00:09Z",
    "sourceSitemap": "https://www.example.org/sitemap.xml",
    "note": "Meta robots directives differ from the previous capture."
}
```

Change types: `FIELD_CHANGED` (title, metaDescription, h1, robotsMeta), `URL_ADDED` and `URL_REMOVED` (sitemap membership, `field` = `sitemapEntry`).

`severity` is a triage label only: `HIGH` when a `noindex`/`none` directive appears or a title/H1 becomes empty; `MEDIUM` for other field changes and removals; `LOW` for added URLs. It is not a prediction of any ranking effect.

#### Key-value store (run default store)

- `REPORT.json`: status, message, statistics and limits, billing outcome, caveats, changes, snapshot of captured pages, and skipped pages with reasons.
- `CHANGES.csv`: the change rows as CSV (header only when there are none). Cells that start with `=`, `+`, `-` or `@` are prefixed with `'` so spreadsheets do not execute page-controlled text.
- `SNAPSHOT.csv`: the pages captured in this run (URL, the four fields, capture time, source sitemap).

#### Run statuses

Successful: `BASELINE_CREATED`, `NO_CHANGES`, `CHANGES_DETECTED`.

Failed (the run is marked failed and nothing is charged): `UNSAFE_URL`, `INVALID_INPUT`, `ROBOTS_BLOCKED`, `NO_SITEMAP`, `SITEMAP_ERROR`, `NO_PAGES_FETCHED`, `BASELINE_UNAVAILABLE`, `BASELINE_SAVE_FAILED`, `INTERNAL_ERROR`.

### How baselines work

- One baseline document per domain (`BASELINE-<host>`) is kept in the named key-value store from `baselineStoreName`. Apify gives every run a new default store, so a named store is what allows a later run to see an earlier one. Use the same name (and the same account) for every run you want compared.
- The baseline holds only the four normalized text fields, the capture time and the source sitemap per URL. No HTML, cookies, headers or images are stored. It is capped at 1000 pages.
- Pages that could not be fetched in a run keep their previous baseline entry; a fetch failure is never reported as a change.
- `www.example.org` and `example.org` are different origins with separate baselines.

### Scheduling

1. Create an Apify Task for each site with the input above.
2. Add a Schedule to the Task: daily is typical; weekly suits slow-moving sites. Avoid hourly runs, since they mostly re-fetch unchanged pages.
3. Keep `maxPages` and `baselineStoreName` constant for a Task. Changing `maxPages` changes which pages are sampled.
4. Connect a webhook or integration to runs that finish with `CHANGES_DETECTED` if you want an alert. Use `resetBaseline` after an intentional redesign so the new state becomes the reference.

### Safety and politeness

- Public HTTPS only. Every request, including redirects, must stay on the exact origin of `startUrl`; HTTP, cross-origin and non-default-port redirects are refused.
- `robots.txt` is fetched first and obeyed (longest-match rules, wildcards, `Crawl-delay`). If it cannot be retrieved reliably (network error, HTTP 401/403/429/5xx) the run stops without requesting anything else. A missing robots.txt (404) is treated as unrestricted.
- Hostnames are resolved before the first request and refused if any address is private, loopback, link-local or otherwise non-public. IP-literal hosts are never accepted.
- Sitemap files are parsed with DTDs and entities refused, and size, entry, depth and file-count limits apply. Gzip sitemaps are inflated within a size bound.
- Requests are sequential, GET-only, without cookies, login, proxies or custom credentials. Page bodies are size-limited and never stored.
- E-mail addresses found in captured text are replaced by `[redacted-email]`. Contact details are never collected on purpose.

### Pricing event

The code emits a single pay-per-event event named `seo-delta-report`, once per run, and only when the run succeeded, the baseline update (if enabled) was saved, and at least one change row was reported. Baseline runs, no-change runs and all failed runs are never charged. No price or payable plan is configured in this repository; that is set up separately on the platform.

### Limitations and sample-size caveats

- **Sample, not census.** Only up to `maxPages` URLs, taken in sitemap order, are fetched per run. If the sitemap lists more pages than the limit, the rest are not checked, and `REPORT.json` shows `sitemapComplete: false`. "No changes" then means "no changes among the pages captured", not "no changes on the site".
- **Added/removed URLs** are only reported when the sitemap was fully enumerated in the current run and the previous baseline was also complete. A bounded sample cannot prove that a URL appeared or vanished, so those events are suppressed otherwise.
- **No JavaScript rendering.** Titles and headings injected by client-side code are not seen. Pages are fetched exactly as a plain HTTP request receives them.
- **Sitemap dependency.** Pages missing from the sitemap are invisible to the Actor. Sites without a sitemap return `NO_SITEMAP`.
- **Text normalization.** Whitespace is collapsed, HTML entities are decoded, long values are cut (title and H1 300 characters, description 500). Differences hidden by truncation or normalization are not reported.
- **Robots meta only.** The `X-Robots-Tag` response header, canonical tags, hreflang, structured data, status-code history and page body text are not monitored.
- **Dynamic content.** Pages that show rotating titles or descriptions (A/B tests, geo or time based text) can produce repeated changes.
- **Pinned vs rolling baseline.** In rolling mode a change is reported once and then becomes the new reference; use the dataset history or `updateBaseline: false` if you need a fixed reference.
- **DNS rebinding.** Addresses are validated before connecting and the connected peer is checked when the transport exposes it, but a hostile DNS server could still change answers between validation and connection.
- **robots.txt parsing** follows common longest-match behaviour; unusual or malformed files may be interpreted differently from a given search engine.
- Only e-mail addresses are redacted from captured text. Do not monitor pages that place other personal data into titles, headings or descriptions.
- Use the Actor only on sites you own or have permission to monitor, and respect each site's terms.

### Local development

```bash
pip install -r requirements.txt
python -m unittest discover -s tests -t .
apify run   # needs the Apify CLI and an input in storage/key_value_stores/default/INPUT.json
```

The unit tests run fully offline against mocked HTTP responses and an in-memory key-value store.

Source layout: `src/urlsafety.py` (URL and address validation), `src/fetcher.py` (bounded same-origin client), `src/robots.py`, `src/sitemap.py`, `src/extract.py` (text extraction), `src/diff.py`, `src/baseline.py`, `src/crawler.py` (run orchestration), `src/runner.py` (Apify storage, dataset and pricing event), `src/main.py` (entry point).

# Actor input Schema

## `startUrl` (type: `string`):

Public HTTPS site root, e.g. https://practical-ai-lab.pages.dev/ . Only monitor sites you own or are permitted to audit. robots.txt is respected; do not use private addresses, credentials or unsafe URLs.

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

Upper bound of sitemap pages fetched per run (1-200). Pages beyond the limit are not checked in that run; see the README sample-size notes.

## `maxSitemapFiles` (type: `integer`):

Maximum number of sitemap or sitemap-index files fetched per run (1-10). Index recursion is limited to two levels.

## `maxReportedChanges` (type: `integer`):

Upper bound of change rows written to the dataset per run (1-1000). The most severe changes are listed first.

## `requestDelayMs` (type: `integer`):

Minimum pause between requests (500-10000). A larger Crawl-delay from robots.txt (capped at 10 seconds) takes precedence.

## `pageMaxKb` (type: `integer`):

Pages larger than this are skipped, not partially analysed (64-1024 KB).

## `updateBaseline` (type: `boolean`):

On (default): each run compares with the previous run, then becomes the new baseline. Off: every run compares with the pinned baseline from the first run.

## `resetBaseline` (type: `boolean`):

Ignore any stored baseline for this domain and create a new one in this run.

## `baselineStoreName` (type: `string`):

Named key-value store that keeps per-domain baselines between runs (3-63 lowercase letters, digits and hyphens). Leave empty to use the run's default store through Actor.get_value/set_value (useful for local runs only; on the platform every run gets a fresh default store).

## Actor input object example

```json
{
  "startUrl": "https://practical-ai-lab.pages.dev/",
  "maxPages": 5,
  "maxSitemapFiles": 1,
  "maxReportedChanges": 200,
  "requestDelayMs": 700,
  "pageMaxKb": 512,
  "updateBaseline": true,
  "resetBaseline": false,
  "baselineStoreName": "pal-seo-watch-baselines"
}
```

# Actor output Schema

## `results` (type: `string`):

Download rows from the latest run in JSON/CSV.

# 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 = {
    "startUrl": "https://practical-ai-lab.pages.dev/",
    "maxPages": 5,
    "maxSitemapFiles": 1,
    "requestDelayMs": 700
};

// Run the Actor and wait for it to finish
const run = await client.actor("practical_ai_lab_jp/pal-website-onpage-seo-regression-watch").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 = {
    "startUrl": "https://practical-ai-lab.pages.dev/",
    "maxPages": 5,
    "maxSitemapFiles": 1,
    "requestDelayMs": 700,
}

# Run the Actor and wait for it to finish
run = client.actor("practical_ai_lab_jp/pal-website-onpage-seo-regression-watch").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 '{
  "startUrl": "https://practical-ai-lab.pages.dev/",
  "maxPages": 5,
  "maxSitemapFiles": 1,
  "requestDelayMs": 700
}' |
apify call practical_ai_lab_jp/pal-website-onpage-seo-regression-watch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,practical_ai_lab_jp/pal-website-onpage-seo-regression-watch"
        }
    }
}
```

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/2yKDU5eaGCOWsY35Z/builds/ueFJZgZuMtumbZ9td/openapi.json
