seo-supervisor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Whether pages changed on a date gained or lost Search clicks and impressions, against similar unchanged pages.
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, resolve } from "node:path";
|
|
6
|
+
import { isMain } from "./lib/is-main.mjs";
|
|
7
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
8
|
+
import { runMain, warnProxy } from "./lib/cli.mjs";
|
|
9
|
+
import {
|
|
10
|
+
Fail,
|
|
11
|
+
refused,
|
|
12
|
+
anomaliesIn,
|
|
13
|
+
anomalyNote,
|
|
14
|
+
pagePath,
|
|
15
|
+
slashKey,
|
|
16
|
+
searchConsole,
|
|
17
|
+
daysAgo,
|
|
18
|
+
lastFinal,
|
|
19
|
+
daysOf,
|
|
20
|
+
readRows,
|
|
21
|
+
} from "./google/search-console.mjs";
|
|
22
|
+
import { changedPages } from "./seo-diff.mjs";
|
|
23
|
+
|
|
24
|
+
// Local thresholds, not Google's. MIN_DAYS keeps every weekday in each window; MIN_TRAFFIC is the changed pages' clicks
|
|
25
|
+
// (or impressions) over both windows. MAX_ROWS is Search Console's per-request row limit.
|
|
26
|
+
const DAYS = 28,
|
|
27
|
+
MIN_DAYS = 7,
|
|
28
|
+
MIN_CONTROLS = 10,
|
|
29
|
+
MIN_TRAFFIC = 30,
|
|
30
|
+
ROUNDS = 2000,
|
|
31
|
+
MAX_ROWS = 25000;
|
|
32
|
+
const METHOD =
|
|
33
|
+
"Each page's change is log((after + 1) / (before + 1)). The result is the changed pages' average change minus the similar unchanged pages' average, shown as a percentage. The likely range is a 90% range: the spread of single pages around their group's average is resampled 2,000 times with a fixed seed, so the same numbers always give the same answer. These are our own rules.";
|
|
34
|
+
const fail = msg => {
|
|
35
|
+
throw new Fail(`change-check: ${msg}`);
|
|
36
|
+
};
|
|
37
|
+
const shift = (d, n) => new Date(Date.parse(d) + n * 864e5).toISOString().slice(0, 10);
|
|
38
|
+
const s = n => (n === 1 ? "" : "s");
|
|
39
|
+
|
|
40
|
+
// pages are URLs or paths; pageSize is smaller only in tests.
|
|
41
|
+
/** @param {{ site?: string, date?: string, pages?: string[], days?: number | string, home?: string, endpoints?: any, pageSize?: number }} [opts] */
|
|
42
|
+
export async function changeCheck({ site, date, pages = [], days = DAYS, home, endpoints, pageSize = MAX_ROWS } = {}) {
|
|
43
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date || "") || isNaN(Date.parse(date)) || shift(date, 0) !== date)
|
|
44
|
+
fail(`--date must be the day the pages changed, like 2026-10-01 (got ${date}).`);
|
|
45
|
+
days = daysOf(
|
|
46
|
+
days,
|
|
47
|
+
"change-check",
|
|
48
|
+
MIN_DAYS,
|
|
49
|
+
480,
|
|
50
|
+
`${MIN_DAYS} is our own minimum, so each window holds every day of the week`,
|
|
51
|
+
);
|
|
52
|
+
// The change day itself is in neither window.
|
|
53
|
+
const before = { from: shift(date, -days), to: shift(date, -1) },
|
|
54
|
+
after = { from: shift(date, 1), to: shift(date, days) };
|
|
55
|
+
// Search Console's last 2-3 days are provisional, so the after window must end at least 3 days ago.
|
|
56
|
+
const wait = Math.round((Date.parse(after.to) - Date.parse(lastFinal())) / 864e5);
|
|
57
|
+
if (wait > 0)
|
|
58
|
+
fail(
|
|
59
|
+
`the ${days} days after the change end on ${after.to}, and Search Console's numbers for the last 3 days aren't final yet. Wait ${wait} more day${s(wait)} and run it again (on ${daysAgo(-wait)} or later), or pass a smaller --days. Nothing was read from Google.`,
|
|
60
|
+
);
|
|
61
|
+
if (before.from < daysAgo(482))
|
|
62
|
+
fail(
|
|
63
|
+
`Search Console keeps 16 months of data, so the ${days} days before ${date} aren't all there any more. Pass a smaller --days. Nothing was read from Google.`,
|
|
64
|
+
);
|
|
65
|
+
const listed = [...new Set(pages.map(p => String(p).trim()).filter(p => p && !p.startsWith("#")))];
|
|
66
|
+
if (!listed.length)
|
|
67
|
+
fail(
|
|
68
|
+
"no changed pages were given. Pass --pages <file> (one URL or path per line) or --from-diff seo-audit/seo-diff.json.",
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const sc = await searchConsole({ site, home, endpoints }),
|
|
72
|
+
host = sc.origin.hostname,
|
|
73
|
+
notes = [];
|
|
74
|
+
// Keyed by pagePath, like the Search Console rows: www and the bare domain are one page.
|
|
75
|
+
const asked = new Set(),
|
|
76
|
+
off = [];
|
|
77
|
+
for (const u of listed) {
|
|
78
|
+
let p = null;
|
|
79
|
+
try {
|
|
80
|
+
const x = new URL(u, sc.origin);
|
|
81
|
+
if (/^https?:$/.test(x.protocol)) p = pagePath(x.href, host);
|
|
82
|
+
} catch {}
|
|
83
|
+
if (p) asked.add(p);
|
|
84
|
+
else off.push(u);
|
|
85
|
+
}
|
|
86
|
+
if (!asked.size)
|
|
87
|
+
fail(
|
|
88
|
+
`none of the pages listed are on ${host} (www and the bare domain count as one), so there's nothing to compare. Check --site and the list.`,
|
|
89
|
+
);
|
|
90
|
+
if (off.length)
|
|
91
|
+
notes.push(
|
|
92
|
+
`${off.length} of the pages listed ${off.length === 1 ? "isn't" : "aren't"} on ${host} (www and the bare domain count as one), so ${off.length === 1 ? "it was" : "they were"} left out: ${off.slice(0, 10).join(", ")}${off.length > 10 ? ` and ${off.length - 10} more` : ""}.`,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Web search totals by path for one window, the top 25,000 pages at most.
|
|
96
|
+
const read = async ({ from, to }) => {
|
|
97
|
+
const out = {};
|
|
98
|
+
let rows;
|
|
99
|
+
try {
|
|
100
|
+
rows = await readRows(
|
|
101
|
+
body => sc.query({ type: "web", ...body }),
|
|
102
|
+
["page"],
|
|
103
|
+
{ startDate: from, endDate: to },
|
|
104
|
+
pageSize,
|
|
105
|
+
notes,
|
|
106
|
+
`${from} to ${to}`,
|
|
107
|
+
);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
throw refused(e, sc.explain(e));
|
|
110
|
+
}
|
|
111
|
+
for (const r of rows) {
|
|
112
|
+
const p = pagePath(r.keys?.[0], host);
|
|
113
|
+
if (p) {
|
|
114
|
+
const t = (out[p] ||= { clicks: 0, impressions: 0 });
|
|
115
|
+
t.clicks += Number(r.clicks) || 0;
|
|
116
|
+
t.impressions += Number(r.impressions) || 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
};
|
|
121
|
+
const b = await read(before),
|
|
122
|
+
a = await read(after),
|
|
123
|
+
none = { clicks: 0, impressions: 0 };
|
|
124
|
+
// A listed page and Search Console's row for it may differ by the trailing slash (/a and /a/): the row's path is
|
|
125
|
+
// used.
|
|
126
|
+
const rowPath = new Map([...Object.keys(a), ...Object.keys(b)].map(p => [slashKey(p), p]));
|
|
127
|
+
const changed = new Set([...asked].map(p => (b[p] || a[p] ? p : (rowPath.get(slashKey(p)) ?? p))));
|
|
128
|
+
const rec = p => ({ path: p, before: b[p], after: a[p] || none });
|
|
129
|
+
// A page Search Console didn't show before the change (new, or not in Google's results) has no past to compare with.
|
|
130
|
+
const noPast = [...changed].filter(p => !b[p]).sort(),
|
|
131
|
+
c = [...changed]
|
|
132
|
+
.filter(p => b[p])
|
|
133
|
+
.sort()
|
|
134
|
+
.map(rec);
|
|
135
|
+
if (noPast.length)
|
|
136
|
+
notes.push(
|
|
137
|
+
`${noPast.length} changed page${s(noPast.length)} had no Google Search data in the ${days} days before the change (new pages, or pages Google didn't show), so ${noPast.length === 1 ? "it was" : "they were"} left out: ${noPast.slice(0, 10).join(", ")}${noPast.length > 10 ? ` and ${noPast.length - 10} more` : ""}.`,
|
|
138
|
+
);
|
|
139
|
+
// Google doesn't announce its smaller core updates, so a site-wide move could pass for the change's effect; unchanged
|
|
140
|
+
// pages over the same dates cancel it out. https://developers.google.com/search/docs/appearance/core-updates
|
|
141
|
+
// Control group (a local rule): unlisted pages with half the changed pages' fewest to twice their most clicks before.
|
|
142
|
+
const lo = Math.ceil(Math.min(...c.map(x => x.before.clicks)) / 2),
|
|
143
|
+
hi = Math.max(...c.map(x => x.before.clicks)) * 2;
|
|
144
|
+
const k = c.length
|
|
145
|
+
? Object.keys(b)
|
|
146
|
+
.filter(p => !changed.has(p) && b[p].clicks >= lo && b[p].clicks <= hi)
|
|
147
|
+
.sort()
|
|
148
|
+
.map(rec)
|
|
149
|
+
: [];
|
|
150
|
+
const sum = (list, w, key) => list.reduce((t, x) => t + x[w][key], 0);
|
|
151
|
+
const totals = list =>
|
|
152
|
+
Object.fromEntries(
|
|
153
|
+
["clicks", "impressions"].map(key => [key, { before: sum(list, "before", key), after: sum(list, "after", key) }]),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const estimate = key => {
|
|
157
|
+
const traffic = sum(c, "before", key) + sum(c, "after", key);
|
|
158
|
+
const reason = !c.length
|
|
159
|
+
? `none of the changed pages had Google Search data in the ${days} days before the change`
|
|
160
|
+
: k.length < MIN_CONTROLS
|
|
161
|
+
? `too few comparable pages: ${k.length} unchanged page${s(k.length)} had similar clicks before the change, and the check needs at least ${MIN_CONTROLS} (our own minimum)`
|
|
162
|
+
: traffic < MIN_TRAFFIC
|
|
163
|
+
? `too little traffic: the changed pages had ${traffic} ${key} over both periods, and the check needs at least ${MIN_TRAFFIC} (our own minimum)`
|
|
164
|
+
: null;
|
|
165
|
+
if (reason) return { verdict: "inconclusive", reason };
|
|
166
|
+
const change = x => Math.log((x.after[key] + 1) / (x.before[key] + 1)),
|
|
167
|
+
mean = v => v.reduce((t, y) => t + y, 0) / v.length;
|
|
168
|
+
const cv = c.map(change),
|
|
169
|
+
kv = k.map(change),
|
|
170
|
+
mc = mean(cv),
|
|
171
|
+
mk = mean(kv),
|
|
172
|
+
effect = mc - mk;
|
|
173
|
+
// Pool each page's distance from its group's mean (a lone changed page adds nothing), then resample groups of the
|
|
174
|
+
// same sizes: their difference shows how far apart two groups land with no real change. A seeded 32-bit LCG keeps
|
|
175
|
+
// the range repeatable.
|
|
176
|
+
const pool = [...(cv.length > 1 ? cv.map(y => y - mc) : []), ...kv.map(y => y - mk)];
|
|
177
|
+
let seed = 1;
|
|
178
|
+
const draw = n => {
|
|
179
|
+
let t = 0;
|
|
180
|
+
for (let i = 0; i < n; i++) {
|
|
181
|
+
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
|
182
|
+
t += pool[Math.floor((seed / 2 ** 32) * pool.length)];
|
|
183
|
+
}
|
|
184
|
+
return t / n;
|
|
185
|
+
};
|
|
186
|
+
const noise = Array.from({ length: ROUNDS }, () => draw(cv.length) - draw(kv.length)).sort((x, y) => x - y);
|
|
187
|
+
const pct = x => Math.round((Math.exp(x) - 1) * 100),
|
|
188
|
+
percent = pct(effect);
|
|
189
|
+
const low = pct(effect - noise[Math.round(0.95 * (ROUNDS - 1))]),
|
|
190
|
+
high = pct(effect - noise[Math.round(0.05 * (ROUNDS - 1))]);
|
|
191
|
+
return {
|
|
192
|
+
verdict: low > 0 ? "likely up" : high < 0 ? "likely down" : "inconclusive",
|
|
193
|
+
percent,
|
|
194
|
+
low,
|
|
195
|
+
high,
|
|
196
|
+
...(low > 0 || high < 0 ? {} : { reason: "the likely range includes no change" }),
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const clicks = estimate("clicks"),
|
|
200
|
+
impressions = estimate("impressions");
|
|
201
|
+
|
|
202
|
+
// Google's documented logging problems in the dates compared (web search only).
|
|
203
|
+
for (const x of anomaliesIn(before.from, after.to)) notes.push(anomalyNote(x, "the dates compared"));
|
|
204
|
+
return {
|
|
205
|
+
source: "change-check",
|
|
206
|
+
site: sc.origin.origin,
|
|
207
|
+
property: sc.prop,
|
|
208
|
+
changeDate: date,
|
|
209
|
+
days,
|
|
210
|
+
windows: { before, after },
|
|
211
|
+
groups: {
|
|
212
|
+
changed: { pages: c.length, paths: c.map(x => x.path), ...totals(c) },
|
|
213
|
+
control: {
|
|
214
|
+
pages: k.length,
|
|
215
|
+
rule: c.length
|
|
216
|
+
? `pages not in the list with ${lo} to ${hi} clicks in the ${days} days before the change: half the changed pages' fewest to twice their most (our own rule)`
|
|
217
|
+
: "none: no changed page had data before the change",
|
|
218
|
+
...totals(k),
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
verdict: clicks.verdict,
|
|
222
|
+
clicks,
|
|
223
|
+
impressions,
|
|
224
|
+
method: METHOD,
|
|
225
|
+
notes,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// "likely up, about +18% compared with the similar unchanged pages (likely range +5% to +33%)", or why it can't say.
|
|
230
|
+
const signed = p => `${p > 0 ? "+" : p < 0 ? "-" : ""}${Math.abs(p)}%`;
|
|
231
|
+
const said = m =>
|
|
232
|
+
m.percent == null
|
|
233
|
+
? `inconclusive, ${m.reason}`
|
|
234
|
+
: `${m.verdict}, about ${signed(m.percent)} compared with the similar unchanged pages (likely range ${signed(m.low)} to ${signed(m.high)}${m.verdict === "inconclusive" ? ", which includes no change" : ""})`;
|
|
235
|
+
|
|
236
|
+
const str = v => (typeof v === "string" ? v : null);
|
|
237
|
+
const USAGE =
|
|
238
|
+
"usage: node change-check.mjs --site https://www.example.com --date YYYY-MM-DD (--pages changed.txt | --from-diff seo-audit/seo-diff.json) [--days 28] [--out seo-audit/change-check.json]";
|
|
239
|
+
async function main(argv) {
|
|
240
|
+
const args = parseArgs(argv, {
|
|
241
|
+
flags: ["site", "date", "pages", "from-diff", "days", "out"],
|
|
242
|
+
positionals: 0,
|
|
243
|
+
usage: USAGE,
|
|
244
|
+
});
|
|
245
|
+
if (!str(args.site) || !str(args.date) || !(str(args.pages) || str(args["from-diff"]))) throw new Fail(USAGE);
|
|
246
|
+
const read = f => {
|
|
247
|
+
try {
|
|
248
|
+
return readFileSync(f, "utf8");
|
|
249
|
+
} catch (e) {
|
|
250
|
+
fail(`can't read ${f} (${e.code || e.message}).`);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const pages = str(args.pages) ? read(args.pages).split(/\r?\n/) : [];
|
|
254
|
+
if (str(args["from-diff"]))
|
|
255
|
+
try {
|
|
256
|
+
pages.push(...changedPages(JSON.parse(read(args["from-diff"]))));
|
|
257
|
+
} catch (e) {
|
|
258
|
+
if (e instanceof Fail) throw e;
|
|
259
|
+
fail(`${args["from-diff"]} isn't a seo-diff.json (run seo-diff.mjs first).`);
|
|
260
|
+
}
|
|
261
|
+
const r = await changeCheck({ site: args.site, date: args.date, days: args.days ?? DAYS, pages });
|
|
262
|
+
const out = resolve(str(args.out) || "seo-audit/change-check.json");
|
|
263
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
264
|
+
writeFileSync(out, JSON.stringify(r, null, 2));
|
|
265
|
+
const { changed, control } = r.groups;
|
|
266
|
+
console.log(
|
|
267
|
+
[
|
|
268
|
+
`change-check: ${changed.pages} changed page${s(changed.pages)} against ${control.pages} similar unchanged page${s(control.pages)} in ${r.property}, ${r.days} days before and after ${r.changeDate} (${r.windows.before.from} to ${r.windows.before.to}, then ${r.windows.after.from} to ${r.windows.after.to}).`,
|
|
269
|
+
`Clicks: ${said(r.clicks)}.`,
|
|
270
|
+
`Impressions: ${said(r.impressions)}.`,
|
|
271
|
+
`This shows what happened to the numbers, not why. Wrote ${out}`,
|
|
272
|
+
...r.notes.map(n => "note: " + n),
|
|
273
|
+
].join("\n"),
|
|
274
|
+
);
|
|
275
|
+
return 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isMain(import.meta.url)) {
|
|
279
|
+
warnProxy();
|
|
280
|
+
await runMain(() => main(process.argv.slice(2)));
|
|
281
|
+
}
|