seo 0.17.8 → 0.17.9

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/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-R3uezpJ-.js";
2
+ import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-BByR3SEY.js";
3
3
  import { createHash, randomUUID, sign } from "node:crypto";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import { arch, homedir, platform, tmpdir, totalmem } from "node:os";
@@ -13844,7 +13844,7 @@ function bearerFetch(token) {
13844
13844
  }
13845
13845
  });
13846
13846
  }
13847
- async function failure(response, label, subject, options) {
13847
+ async function failure$1(response, label, subject, options) {
13848
13848
  const detail = (await response.text().catch(() => "")).slice(0, 300);
13849
13849
  const status = response.status;
13850
13850
  const what = subject ? `${label} for ${subject}` : label;
@@ -13868,7 +13868,7 @@ async function googleJson(gfetch, url, input) {
13868
13868
  body: input.body === void 0 ? void 0 : JSON.stringify(input.body),
13869
13869
  signal
13870
13870
  });
13871
- if (!response.ok) throw await failure(response, input.label, input.subject, input);
13871
+ if (!response.ok) throw await failure$1(response, input.label, input.subject, input);
13872
13872
  return readJson(response, input.label, { maxBytes: input.maxBytes });
13873
13873
  });
13874
13874
  }
@@ -13961,7 +13961,7 @@ async function runAnalyticsReport(gfetch, propertyId, body, options) {
13961
13961
  }
13962
13962
  // packages/core/dist/bing/api.js
13963
13963
  const BASE = "https://ssl.bing.com/webmaster/api.svc/json";
13964
- const MAX_BYTES$5 = 8e6;
13964
+ const MAX_BYTES$6 = 8e6;
13965
13965
  function bingCall(auth, options) {
13966
13966
  return async (method, params = {}) => {
13967
13967
  const url = new URL(`${BASE}/${method}`);
@@ -13986,7 +13986,7 @@ function bingCall(auth, options) {
13986
13986
  if (response.status === 429 || /throttle/i.test(detail)) throw new SeoError("RATE_LIMITED", "Bing Webmaster is limiting requests. Try again in a few minutes.");
13987
13987
  throw new SeoError("OPTIONAL_PROVIDER_UNAVAILABLE", `Bing Webmaster answered ${response.status}. ${detail}`.trim());
13988
13988
  }
13989
- return (await readJson(response, "Bing Webmaster", { maxBytes: MAX_BYTES$5 })).d;
13989
+ return (await readJson(response, "Bing Webmaster", { maxBytes: MAX_BYTES$6 })).d;
13990
13990
  };
13991
13991
  }
13992
13992
  function day$3(value) {
@@ -14981,6 +14981,7 @@ async function runSites(input) {
14981
14981
  input.bing === void 0 ? null : bing === null ? "Bing Webmaster: not connected." : bing instanceof Error ? `Bing Webmaster: could not list sites. ${bing.message}` : bingOnly.length ? `Bing Webmaster sites with no Search Console property here (${bingOnly.length}): ${bingOnly.map((site) => site.url).join(", ")}.` : `Bing Webmaster: ${bingSites.length} verified sites; the bing column shows each one.`,
14982
14982
  `Research keys: ${research.length ? research.join(", ") : "none"}.`,
14983
14983
  input.clicky?.length ? `Clicky sites (seo_data with source "clicky"): ${input.clicky.join(", ")}.` : null,
14984
+ input.simpleAnalytics ? "Simple Analytics: API key saved; seo_data with source \"simple_analytics\" and the site's domain." : null,
14984
14985
  `Add a Google account${input.bing === void 0 ? "" : ", Bing"} or a key: ${input.connect}`,
14985
14986
  "Next: seo_report with a site."
14986
14987
  ].filter(Boolean).join("\n\n"),
@@ -14989,7 +14990,8 @@ async function runSites(input) {
14989
14990
  googleAnalytics: analytics,
14990
14991
  bing: Array.isArray(bing) ? bingSites : null,
14991
14992
  research,
14992
- clicky: input.clicky ?? []
14993
+ clicky: input.clicky ?? [],
14994
+ simpleAnalytics: Boolean(input.simpleAnalytics)
14993
14995
  }
14994
14996
  };
14995
14997
  }
@@ -27645,7 +27647,8 @@ const PROVIDER_SECRET_NAMES = {
27645
27647
  bingApiKey: "bing-api-key",
27646
27648
  clickySiteKeys: "clicky-sitekeys",
27647
27649
  dataForSeoCredentials: "dataforseo-credentials",
27648
- providerExtensionCredentials: "provider-extension-credentials"
27650
+ providerExtensionCredentials: "provider-extension-credentials",
27651
+ simpleAnalyticsKey: "simple-analytics-key"
27649
27652
  };
27650
27653
  const REMOVED_PROVIDER_SECRET_NAMES = [
27651
27654
  "indexnow-keys",
@@ -28241,7 +28244,7 @@ async function loadInstalledProviderExtensions(options = {}) {
28241
28244
  const DEFAULT_MAX_REQUESTS = 8;
28242
28245
  const MAX_RESPONSE_BYTES$1 = 10485760;
28243
28246
  const MAX_REQUEST_BODY_BYTES = 65536;
28244
- const TIMEOUT_MS$3 = 15e3;
28247
+ const TIMEOUT_MS$4 = 15e3;
28245
28248
  function normalizeProviderExtensionAccount(provider, account) {
28246
28249
  const fields = provider.connection.fields.filter((field) => field.kind === "account");
28247
28250
  const allowed = new Set(fields.map((field) => field.id));
@@ -28288,7 +28291,7 @@ function runtimeForProvider(provider, options = {}) {
28288
28291
  },
28289
28292
  fetch: providerFetch,
28290
28293
  maxResponseBytes: MAX_RESPONSE_BYTES$1,
28291
- timeoutMs: TIMEOUT_MS$3,
28294
+ timeoutMs: TIMEOUT_MS$4,
28292
28295
  retry: (input.method ?? "GET") === "GET" ? "safe" : "never",
28293
28296
  schema: z.unknown()
28294
28297
  });
@@ -35662,7 +35665,7 @@ function placementPage(input) {
35662
35665
  };
35663
35666
  }
35664
35667
  // packages/core/dist/analyze/internal-links-report.js
35665
- const DAY$1 = 864e5;
35668
+ const DAY$2 = 864e5;
35666
35669
  const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
35667
35670
  function internalLinksReportRange(input, fallbackDays, now) {
35668
35671
  if (!input.startDate && !input.endDate) return {
@@ -35674,7 +35677,7 @@ function internalLinksReportRange(input, fallbackDays, now) {
35674
35677
  return {
35675
35678
  startDate,
35676
35679
  endDate,
35677
- days: Math.round((Date.parse(`${endDate}T00:00:00Z`) - Date.parse(`${startDate}T00:00:00Z`)) / DAY$1) + 1
35680
+ days: Math.round((Date.parse(`${endDate}T00:00:00Z`) - Date.parse(`${startDate}T00:00:00Z`)) / DAY$2) + 1
35678
35681
  };
35679
35682
  }
35680
35683
  const plural$5 = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
@@ -40185,7 +40188,7 @@ async function updatePostmortemWorkflow(input, dependencies = {}) {
40185
40188
  }
40186
40189
  // packages/core/dist/clicky/api.js
40187
40190
  const ENDPOINT$1 = "https://api.clicky.com/api/stats/4";
40188
- const MAX_BYTES$4 = 5e6;
40191
+ const MAX_BYTES$5 = 5e6;
40189
40192
  var ClickyError = class extends Error {
40190
40193
  code;
40191
40194
  constructor(code, message) {
@@ -40212,7 +40215,7 @@ async function clickyStats(site, types, options = {}) {
40212
40215
  throw new ClickyError("remote", "Could not reach Clicky. Try again.");
40213
40216
  });
40214
40217
  if (!response.ok) throw new ClickyError("remote", `Clicky returned ${response.status}.`);
40215
- const groups = await readJson(response, "Clicky", { maxBytes: MAX_BYTES$4 });
40218
+ const groups = await readJson(response, "Clicky", { maxBytes: MAX_BYTES$5 });
40216
40219
  if (!Array.isArray(groups)) throw new ClickyError("remote", "Clicky returned invalid data.");
40217
40220
  const failed = groups.find((group) => typeof group?.error === "string");
40218
40221
  if (failed?.error) throw /sitekey|site id|authenticat|permission/iu.test(failed.error) ? new ClickyError("auth", `Clicky rejected site ID ${site.siteId} or its sitekey.`) : new ClickyError("remote", `Clicky: ${failed.error.slice(0, 200)}`);
@@ -43304,6 +43307,66 @@ function lintReportText(files) {
43304
43307
  if (reviews) lines.push("Errors and warnings each come with a fix. Review items are judgement calls: change a line only when it fails the question.");
43305
43308
  return lines.join("\n").trimEnd();
43306
43309
  }
43310
+ // packages/core/dist/simple-analytics/api.js
43311
+ const ORIGIN = "https://simpleanalytics.com";
43312
+ const MAX_BYTES$4 = 5e6;
43313
+ const TIMEOUT_MS$3 = 2e4;
43314
+ const SIMPLE_ANALYTICS_LIMIT = 1e3;
43315
+ var SimpleAnalyticsError = class extends Error {
43316
+ code;
43317
+ constructor(code, message) {
43318
+ super(message);
43319
+ this.code = code;
43320
+ }
43321
+ };
43322
+ function isSimpleAnalyticsKey(value) {
43323
+ return /^sa_api_key_[A-Za-z0-9_-]{8,120}$/u.test(value.trim());
43324
+ }
43325
+ const number = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
43326
+ const rows$1 = (value) => Array.isArray(value) ? value.flatMap((row) => row && typeof row.value === "string" ? [{
43327
+ value: row.value,
43328
+ pageviews: number(row.pageviews) ?? 0,
43329
+ visitors: number(row.visitors) ?? 0
43330
+ }] : []) : [];
43331
+ async function simpleAnalyticsStats(key, hostname, range, fields, filters = {}) {
43332
+ const url = new URL(`${ORIGIN}/${encodeURIComponent(hostname)}.json`);
43333
+ url.searchParams.set("version", "6");
43334
+ url.searchParams.set("info", "false");
43335
+ url.searchParams.set("start", range.startDate);
43336
+ url.searchParams.set("end", range.endDate);
43337
+ url.searchParams.set("fields", fields.join(","));
43338
+ url.searchParams.set("limit", String(SIMPLE_ANALYTICS_LIMIT));
43339
+ for (const [name, value] of Object.entries(filters)) url.searchParams.set(name, value);
43340
+ const response = await fetch(url, {
43341
+ headers: {
43342
+ "Api-Key": key,
43343
+ accept: "application/json"
43344
+ },
43345
+ signal: AbortSignal.timeout(TIMEOUT_MS$3)
43346
+ }).catch(() => {
43347
+ throw new SimpleAnalyticsError("remote", "Could not reach Simple Analytics. Try again.");
43348
+ });
43349
+ if (response.status === 404) throw new SimpleAnalyticsError("not_found", `Simple Analytics has no website ${hostname} for this key.`);
43350
+ if (response.status === 401 || response.status === 403) throw new SimpleAnalyticsError("auth", `Simple Analytics rejected the API key for ${hostname}.`);
43351
+ if (response.status === 423) throw new SimpleAnalyticsError("auth", `Simple Analytics has no API access for ${hostname} on its plan.`);
43352
+ if (response.status === 400) {
43353
+ const reason = await readJson(response, "Simple Analytics", { maxBytes: 1e4 }).catch(() => null);
43354
+ const error = String(reason?.error ?? "");
43355
+ throw /api-key|authori[sz]/iu.test(error) ? new SimpleAnalyticsError("auth", `Simple Analytics rejected the API key for ${hostname}.`) : new SimpleAnalyticsError("remote", `Simple Analytics: ${error.slice(0, 200) || "returned 400"}.`);
43356
+ }
43357
+ if (!response.ok) throw new SimpleAnalyticsError("remote", `Simple Analytics returned ${response.status}.`);
43358
+ const body = await readJson(response, "Simple Analytics", { maxBytes: MAX_BYTES$4 });
43359
+ if (body?.ok !== true) throw new SimpleAnalyticsError("remote", `Simple Analytics: ${String(body?.error ?? "invalid data").slice(0, 200)}`);
43360
+ return {
43361
+ hostname: typeof body.hostname === "string" ? body.hostname : hostname,
43362
+ timezone: typeof body.timezone === "string" ? body.timezone : null,
43363
+ pageviews: number(body.pageviews),
43364
+ visitors: number(body.visitors),
43365
+ pages: rows$1(body.pages),
43366
+ referrers: rows$1(body.referrers),
43367
+ utm_sources: rows$1(body.utm_sources)
43368
+ };
43369
+ }
43307
43370
  // packages/core/dist/commands/research-ahrefs.js
43308
43371
  async function ahrefs(key, input, missed, totals) {
43309
43372
  const where = targetParts(input).ahrefs;
@@ -45813,20 +45876,20 @@ async function pickClickySite(saved, target, connect, refresh) {
45813
45876
  }
45814
45877
  throw new CommandError("NO_ACCESS", `No saved Clicky site matches ${target}. Saved Clicky sites: ${sites.map(clickyLabel).join(", ")}. Pass one of these site IDs, or add the site: ${connect}`);
45815
45878
  }
45816
- const DAY = 864e5;
45817
- const isoDay = (time) => new Date(time).toISOString().slice(0, 10);
45879
+ const DAY$1 = 864e5;
45880
+ const isoDay$1 = (time) => new Date(time).toISOString().slice(0, 10);
45818
45881
  function clickyRange(input) {
45819
45882
  if (!input.startDate && !input.endDate) {
45820
- const end = Date.now() - DAY;
45883
+ const end = Date.now() - DAY$1;
45821
45884
  return {
45822
- startDate: isoDay(end - 27 * DAY),
45823
- endDate: isoDay(end)
45885
+ startDate: isoDay$1(end - 27 * DAY$1),
45886
+ endDate: isoDay$1(end)
45824
45887
  };
45825
45888
  }
45826
45889
  const start = Date.parse(`${input.startDate}T00:00:00Z`);
45827
45890
  const end = Date.parse(`${input.endDate}T00:00:00Z`);
45828
45891
  if (!input.startDate || !input.endDate || !(start <= end)) throw new CommandError("INVALID_INPUT", "Send a start date and an end date together, in order.");
45829
- if ((end - start) / DAY + 1 > 31) throw new CommandError("INVALID_INPUT", "Clicky reads at most 31 days at a time. Send a shorter range.");
45892
+ if ((end - start) / DAY$1 + 1 > 31) throw new CommandError("INVALID_INPUT", "Clicky reads at most 31 days at a time. Send a shorter range.");
45830
45893
  return {
45831
45894
  startDate: input.startDate,
45832
45895
  endDate: input.endDate
@@ -45915,6 +45978,143 @@ async function runClickyRows(input, keys, options) {
45915
45978
  }
45916
45979
  };
45917
45980
  }
45981
+ const FREE_LIMIT = 100;
45982
+ const FREE_HISTORY_DAYS = 30;
45983
+ function compared(now, before) {
45984
+ const rows = /* @__PURE__ */ new Map();
45985
+ const add = (name, visits, key) => {
45986
+ const row = rows.get(name) ?? {
45987
+ visits: 0,
45988
+ previousVisits: 0
45989
+ };
45990
+ row[key] += visits;
45991
+ rows.set(name, row);
45992
+ };
45993
+ for (const item of now) add(item.name, item.visits, "visits");
45994
+ for (const item of before) add(item.name, item.visits, "previousVisits");
45995
+ return [...rows].map(([name, row]) => ({
45996
+ name,
45997
+ ...row
45998
+ })).sort((left, right) => right.visits - left.visits || right.previousVisits - left.previousVisits || (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
45999
+ }
46000
+ const sum$1 = (rows) => ({
46001
+ visits: rows.reduce((total, row) => total + row.visits, 0),
46002
+ previousVisits: rows.reduce((total, row) => total + row.previousVisits, 0)
46003
+ });
46004
+ const was = (rows) => rows.slice(0, 10).map((row) => `${row.name} ${row.visits} (was ${row.previousVisits})`).join(", ");
46005
+ async function clickyBeside(keys, site, range, before, pages) {
46006
+ const saved = keys ? clickySites(keys) : [];
46007
+ if (!saved.length) return null;
46008
+ let found;
46009
+ try {
46010
+ found = await pickClickySite(saved, site, "");
46011
+ } catch {
46012
+ return null;
46013
+ }
46014
+ const types = [
46015
+ "visitors",
46016
+ "traffic-sources",
46017
+ "links-domains",
46018
+ ...pages ? ["pages-entrance"] : []
46019
+ ];
46020
+ try {
46021
+ const read = (dates) => clickyStats(found, types, {
46022
+ date: `${dates.startDate},${dates.endDate}`,
46023
+ limit: LIMIT
46024
+ });
46025
+ const now = await read(range);
46026
+ const then = await read(before);
46027
+ const tally = (items) => items.reduce((total, item) => total + (count$2(item) ?? 0), 0);
46028
+ const visits = {
46029
+ visits: tally(now.visitors ?? []),
46030
+ previousVisits: tally(then.visitors ?? [])
46031
+ };
46032
+ const sources = compared(totals(now["traffic-sources"] ?? []), totals(then["traffic-sources"] ?? []));
46033
+ const fromAi = (items) => totals(items).flatMap((item) => {
46034
+ const source = aiReferralSourceForValue(item.name);
46035
+ return source ? [{
46036
+ name: source.label,
46037
+ visits: item.visits
46038
+ }] : [];
46039
+ });
46040
+ const ai = compared(fromAi(now["links-domains"] ?? []), fromAi(then["links-domains"] ?? []));
46041
+ const aiTotal = sum$1(ai);
46042
+ const landed = (items) => {
46043
+ let total = 0;
46044
+ for (const item of items) {
46045
+ const value = count$2(item);
46046
+ if (value === null || !item.url) continue;
46047
+ try {
46048
+ if (new URL(item.url).pathname.includes(pages ?? "")) total += value;
46049
+ } catch {}
46050
+ }
46051
+ return total;
46052
+ };
46053
+ const onPages = pages ? {
46054
+ contains: pages,
46055
+ visits: landed(now["pages-entrance"] ?? []),
46056
+ previousVisits: landed(then["pages-entrance"] ?? [])
46057
+ } : null;
46058
+ const cut = (type) => [now, then].some((stats) => {
46059
+ const length = stats[type]?.length ?? 0;
46060
+ return length >= LIMIT || length === FREE_LIMIT;
46061
+ });
46062
+ const linksCut = cut("links-domains");
46063
+ const pagesCut = Boolean(pages) && cut("pages-entrance");
46064
+ const daysBack = Math.round((Date.now() - Date.parse(`${before.startDate}T00:00:00Z`)) / DAY$1);
46065
+ const notes = [
46066
+ "Visits are Clicky’s own count, in the Clicky site’s time zone; they are not Google Analytics sessions or Search Console clicks.",
46067
+ pagesCut ? "Clicky’s list of landing pages reached its row limit (100 on a free account, 1,000 otherwise), so the landing-page total can be higher than shown." : "",
46068
+ daysBack > FREE_HISTORY_DAYS ? `The earlier period starts ${daysBack} days ago; a free Clicky account keeps 30 days, so on one it can read as zero.` : ""
46069
+ ].filter(Boolean);
46070
+ const total = `${visits.visits} (was ${visits.previousVisits}, ${change$2(pct(visits.visits, visits.previousVisits))})`;
46071
+ const text = [
46072
+ `Clicky site ${clickyLabel(found)}: visits ${total}${pages ? " on the whole site" : ""}.`,
46073
+ sources.length ? `Traffic sources (visits): ${was(sources)}.` : "",
46074
+ onPages ? `Visits that landed on pages whose path contains "${pages}", from every source: ${onPages.visits} (was ${onPages.previousVisits}, ${change$2(pct(onPages.visits, onPages.previousVisits))}). Clicky does not split landing pages by source.` : "",
46075
+ ...notes
46076
+ ].filter(Boolean).join(" ");
46077
+ const limit = "Clicky’s list of incoming link domains reached its row limit (100 on a free account, 1,000 otherwise)";
46078
+ return {
46079
+ text: `${text}\n\n${[
46080
+ aiTotal.visits || aiTotal.previousVisits ? `Visits from AI assistants in Clicky’s incoming links (whole site): ${aiTotal.visits} (was ${aiTotal.previousVisits}, ${change$2(pct(aiTotal.visits, aiTotal.previousVisits))}). By source: ${was(ai)}.` : linksCut ? `Visits from AI assistants in Clicky’s incoming links (whole site): none among the domains Clicky listed. ${limit}, so this is unknown, not zero.` : "Visits from AI assistants in Clicky’s incoming links (whole site): none in either period.",
46081
+ linksCut && (aiTotal.visits || aiTotal.previousVisits) ? `${limit}, so these can be higher.` : "",
46082
+ "Only visits that pass a referrer count; AI apps that send none show as direct."
46083
+ ].filter(Boolean).join(" ")}`,
46084
+ data: {
46085
+ siteId: found.siteId,
46086
+ domain: found.domain,
46087
+ metric: "visits",
46088
+ ...visits,
46089
+ visitsChangePct: pct(visits.visits, visits.previousVisits),
46090
+ trafficSources: sources.map(({ name, ...row }) => ({
46091
+ source: name,
46092
+ ...row
46093
+ })),
46094
+ ...onPages ? { landingPages: {
46095
+ ...onPages,
46096
+ capped: pagesCut
46097
+ } } : {},
46098
+ aiAssistants: {
46099
+ ...aiTotal,
46100
+ visitsChangePct: pct(aiTotal.visits, aiTotal.previousVisits),
46101
+ bySource: ai.map(({ name, ...row }) => ({
46102
+ source: name,
46103
+ ...row
46104
+ })),
46105
+ capped: linksCut
46106
+ },
46107
+ notes
46108
+ }
46109
+ };
46110
+ } catch (error) {
46111
+ const message = error instanceof ClickyError ? error.message : error instanceof Error ? error.message : String(error);
46112
+ return {
46113
+ text: `Clicky: could not be read. ${message}`,
46114
+ data: { error: message }
46115
+ };
46116
+ }
46117
+ }
45918
46118
  // packages/core/dist/commands/domain-rating.js
45919
46119
  const DR_ATTRIBUTION = "domain_rating: Domain Rating by Ahrefs (https://ahrefs.com/).";
45920
46120
  const ENDPOINT = "https://api.ahrefs.com/v3/public/domain-rating-free";
@@ -48595,6 +48795,288 @@ async function sortedByDomainRating(rows, key) {
48595
48795
  added: true
48596
48796
  };
48597
48797
  }
48798
+ // packages/core/dist/commands/simple-analytics.js
48799
+ const SIMPLE_ANALYTICS_KEY = "x-simpleanalytics-key";
48800
+ const simpleAnalyticsKey = (keys) => keys.get("x-simpleanalytics-key")?.trim() || null;
48801
+ const MAX_AI_TOOLS = 5;
48802
+ const MAX_AI_PAIRS = 4;
48803
+ const TOP = 10;
48804
+ const DAY = 864e5;
48805
+ const isoDay = (time) => new Date(time).toISOString().slice(0, 10);
48806
+ const BARE_AI = {
48807
+ chatgpt: "chatgpt",
48808
+ openai: "chatgpt",
48809
+ perplexity: "perplexity",
48810
+ claude: "claude",
48811
+ gemini: "gemini",
48812
+ copilot: "copilot",
48813
+ grok: "grok",
48814
+ deepseek: "deepseek"
48815
+ };
48816
+ const aiTool = (value) => aiReferralSourceForValue(value) ?? AI_REFERRAL_SOURCES.find((source) => source.id === BARE_AI[value.trim().toLowerCase()]);
48817
+ function hostsOf(site) {
48818
+ const text = site.trim().toLowerCase().replace(/^sc-domain:/u, "");
48819
+ let host;
48820
+ try {
48821
+ host = new URL(text.includes("://") ? text : `https://${text}`).hostname;
48822
+ } catch {
48823
+ host = text;
48824
+ }
48825
+ const bare = host.replace(/^www\./u, "");
48826
+ return [bare, `www.${bare}`];
48827
+ }
48828
+ const byVisitors = (a, b) => b.visitors - a.visitors || b.pageviews - a.pageviews || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
48829
+ async function readPeriod(key, hostname, range, filters, withPages) {
48830
+ const stats = await simpleAnalyticsStats(key, hostname, range, [
48831
+ "pageviews",
48832
+ "visitors",
48833
+ ...withPages ? ["pages"] : [],
48834
+ "referrers",
48835
+ "utm_sources"
48836
+ ], filters);
48837
+ const referrers = [...stats.referrers].sort(byVisitors);
48838
+ const utmSources = [...stats.utm_sources].sort(byVisitors);
48839
+ const tools = /* @__PURE__ */ new Map();
48840
+ const add = (rows, side) => {
48841
+ for (const row of rows) {
48842
+ const tool = aiTool(row.value);
48843
+ if (!tool || !row.visitors) continue;
48844
+ const entry = tools.get(tool.id) ?? {
48845
+ label: tool.label,
48846
+ refs: [],
48847
+ utms: []
48848
+ };
48849
+ entry[side].push(row);
48850
+ tools.set(tool.id, entry);
48851
+ }
48852
+ };
48853
+ add(referrers, "refs");
48854
+ add(utmSources, "utms");
48855
+ const sum = (rows) => rows.reduce((total, row) => total + row.visitors, 0);
48856
+ const ranked = [...tools.values()].map((tool) => ({
48857
+ ...tool,
48858
+ total: sum(tool.refs) + sum(tool.utms)
48859
+ })).sort((a, b) => b.total - a.total || (a.label < b.label ? -1 : a.label > b.label ? 1 : 0));
48860
+ const counted = await Promise.all(ranked.slice(0, MAX_AI_TOOLS).map(async (tool) => {
48861
+ const pairs = tool.refs.flatMap((ref) => tool.utms.map((utm) => ({
48862
+ ref,
48863
+ utm
48864
+ }))).sort((a, b) => Math.min(b.ref.visitors, b.utm.visitors) - Math.min(a.ref.visitors, a.utm.visitors) || (a.ref.value + a.utm.value < b.ref.value + b.utm.value ? -1 : 1));
48865
+ const checked = pairs.slice(0, MAX_AI_PAIRS);
48866
+ const overlaps = await Promise.all(checked.map(async ({ ref, utm }) => (await simpleAnalyticsStats(key, hostname, range, ["visitors"], {
48867
+ ...filters,
48868
+ referrer: ref.value,
48869
+ utm_source: utm.value
48870
+ })).visitors ?? 0));
48871
+ return {
48872
+ tool: tool.label,
48873
+ visitors: tool.total - overlaps.reduce((sum, n) => sum + n, 0),
48874
+ referrers: tool.refs.map((row) => row.value),
48875
+ utmSources: tool.utms.map((row) => row.value),
48876
+ exact: pairs.length <= MAX_AI_PAIRS
48877
+ };
48878
+ }));
48879
+ const full = (rows) => rows.length >= SIMPLE_ANALYTICS_LIMIT;
48880
+ return {
48881
+ hostname: stats.hostname,
48882
+ timezone: stats.timezone,
48883
+ range,
48884
+ visitors: stats.visitors ?? 0,
48885
+ pageviews: stats.pageviews ?? 0,
48886
+ pages: [...stats.pages].sort(byVisitors),
48887
+ referrers,
48888
+ utmSources,
48889
+ ai: {
48890
+ visitors: counted.reduce((total, tool) => total + tool.visitors, 0),
48891
+ tools: counted,
48892
+ notCounted: Math.max(0, ranked.length - MAX_AI_TOOLS)
48893
+ },
48894
+ capped: {
48895
+ pages: full(stats.pages),
48896
+ referrers: full(stats.referrers),
48897
+ utmSources: full(stats.utm_sources)
48898
+ }
48899
+ };
48900
+ }
48901
+ async function firstPeriod(site, read) {
48902
+ for (const hostname of hostsOf(site)) try {
48903
+ return await read(hostname);
48904
+ } catch (error) {
48905
+ if (error instanceof SimpleAnalyticsError && error.code === "not_found") continue;
48906
+ throw error;
48907
+ }
48908
+ return null;
48909
+ }
48910
+ function pageFilter(pages) {
48911
+ return pages?.startsWith("/") ? { pages: `${pages.replace(/\*+$/u, "")}*` } : {};
48912
+ }
48913
+ const top = (rows) => rows.slice(0, TOP).map((row) => `${row.value} ${row.visitors}`).join("; ");
48914
+ const aiNotes = (period) => [
48915
+ period.ai.tools.some((tool) => !tool.exact) ? `${period.ai.tools.filter((tool) => !tool.exact).map((tool) => tool.tool).join(", ")} came in more referrer and utm_source pairs than were checked, so a visitor with both can count twice there.` : "",
48916
+ period.ai.notCounted ? `${period.ai.notCounted} more AI ${period.ai.notCounted === 1 ? "tool is" : "tools are"} left out of this count.` : "",
48917
+ period.capped.referrers || period.capped.utmSources ? `A referrer or utm_source list reached Simple Analytics' ${SIMPLE_ANALYTICS_LIMIT}-row limit, so AI tools past it are missing, not zero.` : ""
48918
+ ].filter(Boolean);
48919
+ const VISITORS_NOTE = "Visitors are Simple Analytics’ own count: a pageview with no referrer or one from another site, which it also counts as a visit. They are not Google Analytics sessions or users, or Search Console clicks.";
48920
+ const zoneNote = (period) => period.timezone ? `Days are in the website’s time zone, ${period.timezone}.` : "";
48921
+ const failure = (error) => error instanceof Error ? error.message : String(error);
48922
+ async function simpleAnalyticsBeside(keys, site, range, before, pages) {
48923
+ const key = keys ? simpleAnalyticsKey(keys) : null;
48924
+ if (!key) return null;
48925
+ const filters = pageFilter(pages);
48926
+ try {
48927
+ const now = await firstPeriod(site, (hostname) => readPeriod(key, hostname, range, filters, false));
48928
+ if (!now) return null;
48929
+ const then = await readPeriod(key, now.hostname, before, filters, false);
48930
+ const merged = (a, b, name) => {
48931
+ const rows = /* @__PURE__ */ new Map();
48932
+ for (const row of a) {
48933
+ const entry = rows.get(name(row)) ?? {
48934
+ visitors: 0,
48935
+ previousVisitors: 0
48936
+ };
48937
+ entry.visitors += row.visitors;
48938
+ rows.set(name(row), entry);
48939
+ }
48940
+ for (const row of b) {
48941
+ const entry = rows.get(name(row)) ?? {
48942
+ visitors: 0,
48943
+ previousVisitors: 0
48944
+ };
48945
+ entry.previousVisitors += row.visitors;
48946
+ rows.set(name(row), entry);
48947
+ }
48948
+ return [...rows].map(([key, entry]) => ({
48949
+ name: key,
48950
+ ...entry
48951
+ })).sort((x, y) => y.visitors - x.visitors || y.previousVisitors - x.previousVisitors || (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
48952
+ };
48953
+ const was = (rows) => rows.slice(0, TOP).map((row) => `${row.name} ${row.visitors} (was ${row.previousVisitors})`).join(", ");
48954
+ const referrers = merged(now.referrers, then.referrers, (row) => row.value);
48955
+ const tools = merged(now.ai.tools, then.ai.tools, (row) => row.tool);
48956
+ const scope = filters.pages ? `, pages whose path starts with "${pages}"` : "";
48957
+ const notes = [
48958
+ VISITORS_NOTE,
48959
+ zoneNote(now),
48960
+ pages && !filters.pages ? `Simple Analytics narrows only to paths that start with some text, so these numbers cover the whole site, not pages containing "${pages}".` : "",
48961
+ now.capped.referrers || then.capped.referrers ? `The referrer list reached Simple Analytics' ${SIMPLE_ANALYTICS_LIMIT}-row limit, so referrers past it are missing, not zero.` : ""
48962
+ ].filter(Boolean);
48963
+ return {
48964
+ text: `${[
48965
+ `Simple Analytics, website ${now.hostname}${scope}: visitors ${now.visitors} (was ${then.visitors}, ${change$2(pct(now.visitors, then.visitors))}), pageviews ${now.pageviews} (was ${then.pageviews}, ${change$2(pct(now.pageviews, then.pageviews))}).`,
48966
+ referrers.length ? `Top referrers (visitors): ${was(referrers)}.` : "",
48967
+ ...notes
48968
+ ].filter(Boolean).join(" ")}\n\n${[
48969
+ now.ai.visitors || then.ai.visitors ? `Visitors from AI assistants in Simple Analytics (referrers and utm_source tags, a visitor with both counted once): ${now.ai.visitors} (was ${then.ai.visitors}, ${change$2(pct(now.ai.visitors, then.ai.visitors))}). By tool: ${was(tools)}.` : now.capped.referrers || now.capped.utmSources ? "Visitors from AI assistants in Simple Analytics: none among the referrers and utm_source tags it listed, but a list reached its row limit, so this is unknown, not zero." : "Visitors from AI assistants in Simple Analytics: none in either period.",
48970
+ .../* @__PURE__ */ new Set([...aiNotes(now), ...aiNotes(then)]),
48971
+ "Only visits that pass a referrer or utm_source count; AI apps that send neither show as direct."
48972
+ ].join(" ")}`,
48973
+ data: {
48974
+ hostname: now.hostname,
48975
+ timezone: now.timezone,
48976
+ ...filters.pages ? { pathStartsWith: pages } : {},
48977
+ metric: "visitors",
48978
+ visitors: now.visitors,
48979
+ previousVisitors: then.visitors,
48980
+ visitorsChangePct: pct(now.visitors, then.visitors),
48981
+ pageviews: now.pageviews,
48982
+ previousPageviews: then.pageviews,
48983
+ referrers: referrers.map(({ name, ...row }) => ({
48984
+ referrer: name,
48985
+ ...row
48986
+ })),
48987
+ aiAssistants: {
48988
+ visitors: now.ai.visitors,
48989
+ previousVisitors: then.ai.visitors,
48990
+ visitorsChangePct: pct(now.ai.visitors, then.ai.visitors),
48991
+ byTool: tools.map(({ name, ...row }) => ({
48992
+ tool: name,
48993
+ ...row
48994
+ })),
48995
+ tools: now.ai.tools,
48996
+ previousTools: then.ai.tools
48997
+ },
48998
+ capped: {
48999
+ now: now.capped,
49000
+ before: then.capped
49001
+ },
49002
+ notes
49003
+ }
49004
+ };
49005
+ } catch (error) {
49006
+ return {
49007
+ text: `Simple Analytics: could not be read. ${failure(error)}`,
49008
+ data: { error: failure(error) }
49009
+ };
49010
+ }
49011
+ }
49012
+ async function runSimpleAnalyticsRows(input, keys, options) {
49013
+ const key = simpleAnalyticsKey(keys);
49014
+ if (!key) throw new CommandError("NO_KEY", `No Simple Analytics API key is saved. Add one: ${options.connect}`);
49015
+ let range;
49016
+ if (!input.startDate && !input.endDate) {
49017
+ const end = Date.now() - DAY;
49018
+ range = {
49019
+ startDate: isoDay(end - 27 * DAY),
49020
+ endDate: isoDay(end)
49021
+ };
49022
+ } else if (!input.startDate || !input.endDate || !(Date.parse(input.startDate) <= Date.parse(input.endDate))) throw new CommandError("INVALID_INPUT", "Send a start date and an end date together, in order.");
49023
+ else range = {
49024
+ startDate: input.startDate,
49025
+ endDate: input.endDate
49026
+ };
49027
+ let period;
49028
+ try {
49029
+ period = await firstPeriod(input.site, (hostname) => readPeriod(key, hostname, range, {}, true));
49030
+ } catch (error) {
49031
+ throw new CommandError(error instanceof SimpleAnalyticsError && error.code === "auth" ? "NO_ACCESS" : "PROVIDER_ERROR", error instanceof SimpleAnalyticsError && error.code === "auth" ? `${error.message} Save it again: ${options.connect}` : failure(error));
49032
+ }
49033
+ if (!period) throw new CommandError("NO_ACCESS", `Simple Analytics has no website ${hostsOf(input.site).join(" or ")} for this API key.`);
49034
+ const offset = input.offset ?? 0;
49035
+ const rows = period.pages.filter((row) => row.visitors > 0).map((row) => ({
49036
+ page: row.value,
49037
+ visitors: row.visitors,
49038
+ pageviews: row.pageviews
49039
+ }));
49040
+ const notes = [
49041
+ `Visitors ${period.visitors}, pageviews ${period.pageviews} in all. A page’s visitors are the visits that started on it; pages with pageviews but no visitors are left out.`,
49042
+ VISITORS_NOTE,
49043
+ zoneNote(period),
49044
+ period.referrers.length ? `Referrers (visitors): ${top(period.referrers)}.` : "Referrers: none in this range.",
49045
+ period.utmSources.length ? `utm_source tags (visitors): ${top(period.utmSources)}.` : "",
49046
+ period.ai.visitors ? `Visitors from AI assistants (referrers and utm_source tags, a visitor with both counted once): ${period.ai.visitors}. By tool: ${period.ai.tools.map((tool) => `${tool.tool} ${tool.visitors}`).join(", ")}.` : "Visitors from AI assistants: none among the referrers and utm_source tags listed.",
49047
+ ...aiNotes(period),
49048
+ period.capped.pages ? `Simple Analytics returned its ${SIMPLE_ANALYTICS_LIMIT}-row limit of pages; pages past it are missing, not zero.` : ""
49049
+ ].filter(Boolean);
49050
+ return {
49051
+ text: rowsText({
49052
+ title: `Simple Analytics website ${period.hostname}: landing pages, ${range.startDate} to ${range.endDate}.`,
49053
+ rows,
49054
+ offset,
49055
+ limit: 50,
49056
+ detail: input.detail ?? "summary",
49057
+ notes,
49058
+ more: options.call
49059
+ }),
49060
+ data: {
49061
+ hostname: period.hostname,
49062
+ timezone: period.timezone,
49063
+ range,
49064
+ metric: "visitors",
49065
+ visitors: period.visitors,
49066
+ pageviews: period.pageviews,
49067
+ referrers: period.referrers.slice(0, 50),
49068
+ utmSources: period.utmSources.slice(0, 50),
49069
+ aiAssistants: {
49070
+ visitors: period.ai.visitors,
49071
+ tools: period.ai.tools
49072
+ },
49073
+ capped: period.capped.pages,
49074
+ total: rows.length,
49075
+ offset,
49076
+ rows: rows.slice(offset, offset + 50)
49077
+ }
49078
+ };
49079
+ }
48598
49080
  // packages/core/dist/commands/sitemap-urls.js
48599
49081
  const MAX_FILES = 20;
48600
49082
  const MAX_URLS = 5e4;
@@ -48936,7 +49418,7 @@ function markdownText(markdown, url) {
48936
49418
  if (!markdown.markdown) return "Main content as Markdown: the page has no main content to read.";
48937
49419
  return `Main content as Markdown (live page${markdown.truncated ? `, cut to ${markdown.markdown.length.toLocaleString("en-US")} of ${markdown.characters.toLocaleString("en-US")} characters` : ""}):\n\n${markdown.markdown}`;
48938
49420
  }
48939
- async function runCompare(input, deps) {
49421
+ async function runCompare(input, deps, keys) {
48940
49422
  if (!realIsoDate(input.date)) throw new CommandError("INVALID_INPUT", "The date must be a real day as YYYY-MM-DD.");
48941
49423
  const last = latestFinalGscDate(deps.now?.() ?? /* @__PURE__ */ new Date());
48942
49424
  const daysAfter = Math.round((Date.parse(last) - Date.parse(input.date)) / 864e5) + 1;
@@ -48950,18 +49432,22 @@ async function runCompare(input, deps) {
48950
49432
  startDate: shiftIsoDate(input.date, -days),
48951
49433
  endDate: shiftIsoDate(input.date, -1)
48952
49434
  };
48953
- const [report, updates, analytics] = await Promise.all([
49435
+ const [report, updates, analytics, clicky, simpleAnalytics] = await Promise.all([
48954
49436
  siteOverview(sharedReader(deps.searchAnalytics), input.site, after, before, input.pages),
48955
49437
  googleUpdates({
48956
49438
  start: before.startDate,
48957
49439
  end: after.endDate
48958
49440
  }),
48959
- analyticsBeside(deps.analytics, input.site, after, before, input.pages)
49441
+ analyticsBeside(deps.analytics, input.site, after, before, input.pages),
49442
+ clickyBeside(keys, input.site, after, before, input.pages),
49443
+ simpleAnalyticsBeside(keys, input.site, after, before, input.pages)
48960
49444
  ]);
48961
49445
  return {
48962
49446
  text: [
48963
49447
  overviewText(report, `Compare on ${input.site}: ${days} days after ${input.date}`, originOf(input.site), 10),
48964
49448
  analytics?.text,
49449
+ clicky?.text,
49450
+ simpleAnalytics?.text,
48965
49451
  listOfUpdates(updates),
48966
49452
  `Next: ${deps.call("page")} for a page that moved.`,
48967
49453
  FACTS_ONLY
@@ -48969,6 +49455,8 @@ async function runCompare(input, deps) {
48969
49455
  data: {
48970
49456
  ...report,
48971
49457
  ...analytics ? { analytics: analytics.data } : {},
49458
+ ...clicky ? { clicky: clicky.data } : {},
49459
+ ...simpleAnalytics ? { simpleAnalytics: simpleAnalytics.data } : {},
48972
49460
  googleUpdates: updates
48973
49461
  }
48974
49462
  };
@@ -49304,6 +49792,31 @@ function opportunityLines(site) {
49304
49792
  " - Searches, CPC and intent are DataForSEO estimates, Domain Rating is by Ahrefs, fit with the site is a model classification and \"free tool\" is a guess from the words."
49305
49793
  ];
49306
49794
  }
49795
+ const ENGINE_NAMES = {
49796
+ chatgpt: "ChatGPT search",
49797
+ google_ai_mode: "Google AI Mode",
49798
+ google_ai_overview: "AI Overviews"
49799
+ };
49800
+ function aiAnswerLines(site) {
49801
+ const found = site.ai_answers;
49802
+ if (!found) return [];
49803
+ if (found.blocked) return [`- AI answers: ${sentence(found.blocked)}`];
49804
+ if (!found.checked_at) return [];
49805
+ const day = (ms) => dayLabel(new Date(ms).toISOString().slice(0, 10));
49806
+ const { counts } = found;
49807
+ const answers = Object.values(counts).reduce((sum, n) => sum + n, 0);
49808
+ const unknown = [counts.unavailable ? `${count(counts.unavailable)} unavailable` : "", counts.pending ? `${count(counts.pending)} not ready yet` : ""].filter(Boolean);
49809
+ const engines = list(Object.values(ENGINE_NAMES));
49810
+ const lines = [`- AI answers, checked ${day(found.checked_at)}: ${plural(found.questions.length, "question")} from Search Console asked in ${engines}. Cited in ${count(counts.cited)} of ${plural(answers, "answer")}, mentioned by name in ${count(counts.mentioned)}, neither in ${count(counts.neither)}, no AI answer shown in ${count(counts.no_answer)}${unknown.length ? `, ${list(unknown)}` : ""}.`];
49811
+ if (found.previous_checked_at) {
49812
+ const shown = found.changes.slice(0, 10);
49813
+ const label = (result) => result.replace("_", " ");
49814
+ lines.push(shown.length ? ` - Changed since ${day(found.previous_checked_at)}:` : ` - No answer changed since ${day(found.previous_checked_at)}${counts.unavailable || counts.pending ? " among the ones known both weeks" : ""}.`, ...shown.map((change) => ` - "${change.question}" in ${ENGINE_NAMES[change.engine] ?? change.engine}: ${label(change.from)}, now ${label(change.to)}${change.cited_url ? ` (${change.cited_url})` : ""}.`), ...found.changes.length > shown.length ? [` - And ${plural(found.changes.length - shown.length, "more")}.`] : []);
49815
+ }
49816
+ if (found.cited_sites.length) lines.push(` - Sites cited instead: ${found.cited_sites.slice(0, 5).map((item) => `${item.host} (${item.answers})`).join(", ")}.`);
49817
+ lines.push(" - Each answer is one sample that can change from run to run, so one week’s change is not a trend.");
49818
+ return lines;
49819
+ }
49307
49820
  function measuredLines(site) {
49308
49821
  const found = site.measured;
49309
49822
  if (!found?.total) return [];
@@ -49338,7 +49851,7 @@ function weekMarkdown(data) {
49338
49851
  "",
49339
49852
  attention.length ? total === 1 ? "Your site had changes worth a look this week." : `${attention.length} of your ${total} sites had changes worth a look this week.` : quiet.length ? total === 1 ? "Your site had a quiet week." : quiet.length === total ? `All ${total} of your sites had a quiet week.` : `${quiet.length} of your ${total} sites had a quiet week.` : "Your sites are still on their first checks."
49340
49853
  ];
49341
- for (const { site, found } of rows) out.push("", `## ${siteName(site.property)}${found.length ? `: ${list(found.map((item) => item.heading))}` : ""}`, "", ...siteLines(site, startMs, endMs, data.first).map((line) => `- ${line}`), ...opportunityLines(site), ...measuredLines(site), ...updateLines(site), ...site.link ? [`- [View site](${site.link})`] : []);
49854
+ for (const { site, found } of rows) out.push("", `## ${siteName(site.property)}${found.length ? `: ${list(found.map((item) => item.heading))}` : ""}`, "", ...siteLines(site, startMs, endMs, data.first).map((line) => `- ${line}`), ...opportunityLines(site), ...aiAnswerLines(site), ...measuredLines(site), ...updateLines(site), ...site.link ? [`- [View site](${site.link})`] : []);
49342
49855
  return out.join("\n");
49343
49856
  }
49344
49857
  async function runAllSites(deps, sites) {
@@ -49385,7 +49898,8 @@ const DATA_SOURCES = [
49385
49898
  "search_console",
49386
49899
  "google_analytics",
49387
49900
  "bing",
49388
- "clicky"
49901
+ "clicky",
49902
+ "simple_analytics"
49389
49903
  ];
49390
49904
  function tool(spec) {
49391
49905
  return spec;
@@ -49394,6 +49908,7 @@ const listSites = async (surface) => runSites({
49394
49908
  accounts: await surface.accounts(),
49395
49909
  keys: await surface.keys(),
49396
49910
  clicky: clickySites(await surface.keys()).map(clickyLabel),
49911
+ simpleAnalytics: Boolean(simpleAnalyticsKey(await surface.keys())),
49397
49912
  signIn: surface.signIn,
49398
49913
  bing: surface.deps.bing ? await surface.deps.bing() : void 0,
49399
49914
  connect: surface.connect
@@ -49522,7 +50037,7 @@ const SHARED_TOOLS = [
49522
50037
  name: "seo_compare",
49523
50038
  command: "compare",
49524
50039
  title: "Before and after a date",
49525
- description: "Compares equal periods before and after a date, such as a site change or a Google update: totals, devices, and the pages and queries that moved, Google Analytics sessions from the property whose web stream matches the site, and Google updates in the window. Optional pages narrows it to URLs that contain that text, such as /blog/.",
50040
+ description: "Compares equal periods before and after a date, such as a site change or a Google update: totals, devices, and the pages and queries that moved, Google Analytics sessions from the property whose web stream matches the site, Clicky visits from a saved Clicky site with the same domain, Simple Analytics visitors when an API key is saved and it has the site, and Google updates in the window. Optional pages narrows it to URLs that contain that text, such as /blog/.",
49526
50041
  input: z.object({
49527
50042
  site,
49528
50043
  date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe("YYYY-MM-DD: the first day after the change."),
@@ -49532,7 +50047,7 @@ const SHARED_TOOLS = [
49532
50047
  site: await surface.resolveSite(input.site),
49533
50048
  date: input.date,
49534
50049
  pages: input.pages
49535
- }, surface.deps)
50050
+ }, surface.deps, await surface.keys())
49536
50051
  }),
49537
50052
  tool({
49538
50053
  name: "seo_index",
@@ -49606,10 +50121,10 @@ const SHARED_TOOLS = [
49606
50121
  name: "seo_data",
49607
50122
  command: "data",
49608
50123
  title: "Raw rows",
49609
- description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; page_regex, query_regex and exclude_query_regex take RE2 regexes for custom cuts. google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days).`,
50124
+ description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; page_regex, query_regex and exclude_query_regex take RE2 regexes for custom cuts. google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days). simple_analytics: landing-page visitors, referrers, utm_source tags and AI tools from Simple Analytics with the API key the person saved (site is its domain).`,
49610
50125
  input: z.object({
49611
50126
  source: z.enum(DATA_SOURCES).default("search_console"),
49612
- site: z.string().min(1).describe("search_console and bing: the property or site. google_analytics: numeric property id from seo_sites. clicky: the site or its Clicky site ID."),
50127
+ site: z.string().min(1).describe("search_console and bing: the property or site. google_analytics: numeric property id from seo_sites. clicky: the site or its Clicky site ID. simple_analytics: the site domain."),
49613
50128
  dimensions: z.array(z.enum(DIMENSIONS)).max(4).default(["query"]).describe("search_console; bing uses the first, query or page."),
49614
50129
  page: z.string().min(1).optional().describe("search_console only: URL text, such as /blog/."),
49615
50130
  query: z.string().min(1).optional().describe("search_console only: query text."),
@@ -49620,6 +50135,16 @@ const SHARED_TOOLS = [
49620
50135
  ...detail
49621
50136
  }),
49622
50137
  run: async (surface, input) => {
50138
+ if (input.source === "simple_analytics") return runSimpleAnalyticsRows({
50139
+ site: input.site,
50140
+ startDate: input.start_date,
50141
+ endDate: input.end_date,
50142
+ detail: input.detail,
50143
+ offset: input.offset
50144
+ }, await surface.keys(), {
50145
+ connect: surface.connect,
50146
+ call: (offset) => `seo_data with source "simple_analytics", site "${input.site}", detail "rows", offset ${offset}`
50147
+ });
49623
50148
  if (input.source === "clicky") return runClickyRows({
49624
50149
  site: input.site,
49625
50150
  startDate: input.start_date,
@@ -49767,10 +50292,10 @@ const MCP_SERVER_INFO = {
49767
50292
  }
49768
50293
  ]
49769
50294
  };
49770
- const MCP_INSTRUCTIONS = `SEO Skill reads the person's own Search Console, Google Analytics, Bing Webmaster Tools, Clicky and optional keyword accounts, and returns facts with their dates and limits. It gives no advice.
50295
+ const MCP_INSTRUCTIONS = `SEO Skill reads the person's own Search Console, Google Analytics, Bing Webmaster Tools, Clicky, Simple Analytics and optional keyword accounts, and returns facts with their dates and limits. It gives no advice.
49771
50296
  1. seo_sites: the properties the connected accounts can read.
49772
50297
  2. seo_report: start here. Without site it summarises last week across every site in the weekly site audit and names the site to ask about next. With site it shows that property's overview and every section's count and top rows; then ask for the one section you need. Section issues keeps a list of what it found for the site between sessions; mark records which the person fixed or wants ignored.
49773
- 3. seo_page for one URL, seo_compare for before and after a date, seo_index for Google's indexing reasons and pages that lost their clicks, seo_research for keyword, competitor and backlink data, and whether AI answers cite the site, from the DataForSEO or Ahrefs key the person saved, seo_data for raw rows, including Google Analytics, Bing and Clicky.
50298
+ 3. seo_page for one URL, seo_compare for before and after a date, seo_index for Google's indexing reasons and pages that lost their clicks, seo_research for keyword, competitor and backlink data, and whether AI answers cite the site, from the DataForSEO or Ahrefs key the person saved, seo_data for raw rows, including Google Analytics, Bing, Clicky and Simple Analytics.
49774
50299
  4. seo_lint checks copy you are writing or editing (a landing page, blog post, title or meta description) for patterns common in AI-written text and for title and description length. It reads only the text or files you give it.`;
49775
50300
  const mcpCall = (command, args) => {
49776
50301
  const name = `seo_${command.replace("-", "_")}`;
@@ -49980,6 +50505,29 @@ async function readDataForSeoCredentials(input = {}) {
49980
50505
  }
49981
50506
  return migrateLegacyCredentials();
49982
50507
  }
50508
+ // packages/core/dist/simple-analytics/credentials.js
50509
+ const SIMPLE_ANALYTICS_KEY_ENV = "SEO_SIMPLE_ANALYTICS_KEY";
50510
+ const SECRET = PROVIDER_SECRET_NAMES.simpleAnalyticsKey;
50511
+ function checked(value) {
50512
+ const key = value.trim();
50513
+ if (!isSimpleAnalyticsKey(key)) throw new ProviderError({
50514
+ provider: "simple-analytics",
50515
+ operation: "credentials",
50516
+ code: "configuration",
50517
+ message: "Simple Analytics needs an API key that starts with sa_api_key_ (Account settings, API keys)."
50518
+ });
50519
+ return key;
50520
+ }
50521
+ async function readSimpleAnalyticsKey() {
50522
+ const saved = await readProviderSecret({
50523
+ name: SECRET,
50524
+ envVar: SIMPLE_ANALYTICS_KEY_ENV
50525
+ });
50526
+ return saved ? {
50527
+ key: checked(saved.value),
50528
+ source: saved.source
50529
+ } : void 0;
50530
+ }
49983
50531
  // packages/core/dist/storage/issues.js
49984
50532
  const issuesFile = () => join(getSeoCliPaths().configDir, "issues.json");
49985
50533
  function readFile$1() {
@@ -50078,10 +50626,11 @@ async function localAccounts() {
50078
50626
  }));
50079
50627
  }
50080
50628
  async function localResearchKeys() {
50081
- const [dataForSeo, ahrefs, clicky, saved] = await Promise.all([
50629
+ const [dataForSeo, ahrefs, clicky, simpleAnalytics, saved] = await Promise.all([
50082
50630
  readDataForSeoCredentials().catch(() => void 0),
50083
50631
  readAhrefsApiKey().catch(() => void 0),
50084
50632
  readClickySiteKeys().catch(() => ({})),
50633
+ readSimpleAnalyticsKey().catch(() => void 0),
50085
50634
  cloudLinked() ? cloudKeys().catch(() => ({})) : {}
50086
50635
  ]);
50087
50636
  const keys = new Headers(saved);
@@ -50094,6 +50643,7 @@ async function localResearchKeys() {
50094
50643
  keys.set("x-dataforseo-password", dataForSeo.password);
50095
50644
  }
50096
50645
  if (ahrefs?.apiKey) keys.set("x-ahrefs-key", ahrefs.apiKey);
50646
+ if (simpleAnalytics) keys.set(SIMPLE_ANALYTICS_KEY, simpleAnalytics.key);
50097
50647
  return keys;
50098
50648
  }
50099
50649
  const TYPESAFE_API_KEY_ENV = "TYPESAFE_API_KEY";