@gscdump/analysis

中文文档
7.15.0发布于 2026/11/16MITTypeScriptES Module构建来源已验证近 30 天下载 9025

GSC analyzers — striking-distance, opportunity, movers, decay, brand, clustering, concentration, seasonality. Pure row-based + DuckDB-native.

原始使用文档
文档目录10 节
  1. Install
  2. Choose an export
  3. Analyze rows
  4. Sources
  5. Reports
  6. DuckDB and browser use
  7. Date windows
  8. Fetch budget and output limit
  9. Public API
  10. License

@gscdump/analysis

npm version npm downloads license

SEO Analyzers and Reports for Google Search Console data. Use pure functions for rows you already have, or run an Analyzer against a Source.

Install

npm install @gscdump/analysis

Node.js 22 or newer is required for Node consumers.

Choose an export

SubpathPurpose
@gscdump/analysisPure Analyzers, browser dispatch, and shared Analyzer contracts
@gscdump/analysis/registryAll 30 registered Analyzers, including SQL implementations
@gscdump/analysis/reportReport registry, runReport, and formatting
@gscdump/analysis/sourceComposite and in-memory Source factories
@gscdump/analysis/sitemap-healthSitemap health deltas and sitemap collapse checks, with no imports
@gscdump/analysis/errorsTyped analysis errors and rendering helpers

@gscdump/engine owns the Analyzer, Source, and period contracts. The analysis root re-exports the common contracts. The default registry imports every Analyzer; avoid it when you need a smaller browser bundle.

Analyze rows

import { analyzeDecay, analyzeMovers } from '@gscdump/analysis'

const current = [{
  query: 'example query',
  page: 'https://example.com/docs',
  clicks: 40,
  impressions: 1000,
  ctr: 0.04,
  position: 8,
}]
const previous = [{
  query: 'example query',
  page: 'https://example.com/docs',
  clicks: 100,
  impressions: 1000,
  ctr: 0.1,
  position: 4,
}]

const movers = analyzeMovers({ current, previous })
const decay = analyzeDecay({ current, previous })
console.log(movers.declining, decay)

Comparison functions take one { current, previous } input object. Options are a separate second argument. See the SEO guide for a complete striking-distance example.

Sources

Use runAnalyzerFromSource to choose an Analyzer's row or SQL plan:

import { defaultAnalyzerRegistry } from '@gscdump/analysis/registry'
import { createGscApiQuerySource } from '@gscdump/engine-gsc-api'
import { runAnalyzerFromSource } from '@gscdump/engine/analyzer'
import { googleSearchConsole } from 'gscdump'

const client = googleSearchConsole({ accessToken: process.env.GSC_ACCESS_TOKEN! })
const source = createGscApiQuerySource({ client, siteUrl: 'sc-domain:example.com' })
const result = await runAnalyzerFromSource(source, {
  type: 'striking-distance',
  startDate: '2026-08-01',
  endDate: '2026-08-28',
  minImpressions: 100,
}, defaultAnalyzerRegistry)

console.log(result.results)

Install @gscdump/engine, @gscdump/engine-gsc-api, and gscdump for this example.

Thirteen Analyzers have row plans:

  • brand, cannibalization, clustering, concentration
  • data-detail, data-query, decay, movers
  • opportunity, seasonality, striking-distance, trajectory, zero-click

All 30 Analyzers have SQL plans. SQL-only Analyzers need a Source that supports their required capabilities.

FactoryImport pathInput
createGscApiQuerySource@gscdump/engine-gsc-api{ client, siteUrl }
createLiveGscSource@gscdump/engine-gsc-api{ siteUrl, getAccessToken }
createEngineQuerySource@gscdump/engine/source{ engine, ctx }
createSqliteQuerySource@gscdump/engine-sqlite{ executor, siteId, regex? }
createInMemoryQuerySource@gscdump/analysis/source{ queryRows }
createCompositeSource@gscdump/analysis/source{ engine, live, site }

For a composite Source, site contains oldestDateSynced, newestDateSynced, and optional coveredSpans. It routes supported queries to Google when stored coverage is missing or stored dimensions cannot answer the query. SQL execution always uses the Engine.

Reports

Reports combine Analyzers into bounded Sections. After creating source above, run a Report supported by that Source:

import { defaultReportRegistry, runReport } from '@gscdump/analysis/report'
import { resolveWindow } from '@gscdump/engine/period'
import { getLatestGscDate } from 'gscdump/dates'

const report = defaultReportRegistry.getReport('movers')!
const window = resolveWindow({ preset: 'last-28d', anchor: getLatestGscDate(), comparison: 'prev-period' })
const result = await runReport(report, {
  source,
  analyzers: defaultAnalyzerRegistry,
  ctx: {
    site: 'sc-domain:example.com',
    window,
    params: {},
    registryVersion: defaultReportRegistry.version,
  },
})

console.log(result.sections, result.meta.degraded)

See the Report list for inputs and defaults. If an optional step fails, meta.degraded is true. A required step failure rejects the Report.

Use defineReport from @gscdump/engine/report to define your own Report.

DuckDB and browser use

For Node, create an Engine Source with createEngineQuerySource({ engine, ctx }) from @gscdump/engine/source. The context supplies userId and siteId. Node attachment helpers live at @gscdump/engine/node.

For browsers, use @gscdump/engine-duckdb-wasm to attach Parquet tables. analyzeInBrowser accepts a runner with query(sql, params, signal?), options, analysis parameters, and an Analyzer registry. Browser analysis uses attached tables as described in ADR-0001.

For SQLite and D1, use @gscdump/engine-sqlite. Analyzer support depends on the Source's SQL dialect and capabilities.

Date windows

import { resolveWindow } from '@gscdump/analysis'

const window = resolveWindow({ preset: 'last-30d', anchor: '2026-08-28', comparison: 'yoy' })
console.log(window.start, window.end, window.comparison)

Every preset except custom needs an anchor: the last date the window includes. Pass the newest complete date in your data, such as the Store's newest synced day or getLatestGscDate() from gscdump/dates. resolveWindow never reads the clock.

Presets: last-7d, last-28d, last-30d, last-90d, last-180d, last-365d, mtd, qtd, ytd, last-quarter, and custom. Comparisons: none, prev-period, and yoy. yoy shifts the window back 364 days, so each day compares with the same weekday.

Fetch budget and output limit

limit caps the rows an Analyzer returns. It never caps the rows it reads. Row plans read at most fetchBudget rows per query: 25,000 (one GSC page) by default, up to 100,000. meta.total counts every match on every Analyzer with a row plan, not only the returned rows. The SQL-only Analyzers are the exception. They still report meta.total after limit: bayesian-ctr, bipartite-pagerank, change-point, ctr-anomaly, intent-atlas, long-tail, query-migration, stl-decompose, and trends. meta.coverage is { kind: 'complete' }, or { kind: 'truncated', fetched } when a query reached its fetch budget. A truncated run can miss rows, so treat its totals and rankings as partial.

Public API

Use the package exports listed above. Files under src/ are private and may change without a public migration path.

License

MIT

版本与发布记录

@gscdump/analysis 共发布 265 个版本,首次发布于 2026/04/27;过去 12 个月发布了 265 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.15.0latest2026/11/16今天
7.14.02026/11/16今天
7.13.22026/11/151 天前
7.13.12026/11/152 天前
7.13.02026/11/124 天前
7.12.12026/11/116 天前

关于 @gscdump/analysis 的常见问题

@gscdump/analysis 是什么?

GSC analyzers — striking-distance, opportunity, movers, decay, brand, clustering, concentration, seasonality. Pure row-based + DuckDB-native.

如何安装 @gscdump/analysis?

在项目目录运行 npm install @gscdump/analysis,或使用 pnpm add / yarn add / bun add。

@gscdump/analysis 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gscdump/analysis 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gscdump/analysis 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gscdump/analysis 可以商用吗?

@gscdump/analysis 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gscdump/analysis 的下载量有多少?

根据 npm 官方下载统计,@gscdump/analysis 在 2026/10/17 – 2026/11/15 这 30 天内被下载 9,025 次,日均约 301 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gscdump/analysis 还在维护吗?

最新版本 7.15.0 发布于 2026/11/16(今天);至今共发布 265 个版本,其中过去 12 个月发布了 265 个;首次发布于 2026/04/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。