@funnelsgrove/analytics

中文文档
0.29.0发布于 2026/11/12TypeScriptES Module零依赖近 30 天下载 7901

Shared analytics package for public funnels.

原始使用文档
文档目录7 节
  1. Owns event identity and delivery
  2. Use This Package For
  3. Do Not Use This Package For
  4. Public Surfaces
  5. Engineering Rules
  6. Google Tag Configuration
  7. Build, Test, Publish

@funnelsgrove/analytics

Shared analytics package for public funnels.

Read this file before editing analytics code. Deeper runtime SDK docs live in docs/funnel-sdk/analytics-sdk.md.

Owns event identity and delivery

@funnelsgrove/analytics owns the browser identity, event-shaping, and delivery contract for public funnel analytics. Funnel code may decide when a business event happened, but this package decides how that event becomes a normalized SDK/PostHog/partner payload.

Use This Package For

  • browser user-id persistence
  • SDK user bootstrap for public funnel identity
  • public analytics event batching and transport
  • identify, track, step lifecycle, and checkout event helpers
  • Stripe purchase metadata shaping before payment metadata reaches the API
  • Google Tag and Meta Pixel event adapters
  • local-only no-op behavior when a real publishable key is not configured

Do Not Use This Package For

  • step routing
  • manifest logic
  • checkout orchestration
  • billing plan resolution
  • Stripe checkout UI
  • funnel-specific step components or copy

Public Surfaces

  • publicAnalyticsSdk: the canonical browser SDK for identify, track, lifecycle, checkout, and flush calls.
  • bootstrapPublicAnalyticsUser: public SDK identity bootstrap helper.
  • sdk-user-id.storage: shared browser user-id storage contract.
  • buildStripePurchaseMetadata and purchase attribute helpers: safe metadata shaping for payment handoff.
  • trackStripePaymentCheckoutReturn: parses and deduplicates Stripe browser-return diagnostics without claiming a purchase conversion.
  • google-tag.service and meta-pixel.service: partner event adapters.
  • experiment-result-metrics.service: shared experiment result metric helpers.

Engineering Rules

  • Keep transport details here; do not duplicate event batching in funnels.
  • Keep provider adapters dumb: they map canonical events, not funnel business flow.
  • Do not import payment UI or runtime routing from this package.
  • Sensitive values must be filtered before metadata reaches Stripe or partner tools.
  • A Stripe browser return is diagnostic state only. Use trackStripePaymentCheckoutReturn; never turn query parameters into checkout_completed or trusted purchase_completed.

Google Tag Configuration

NEXT_PUBLIC_GOOGLE_ANALYTICS_ID and NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID configure which Google tags load. Google Ads conversion actions also need the full send_to destination, such as AW-123456789/ConversionLabel.

  • NEXT_PUBLIC_GOOGLE_TAG_LEAD_SEND_TO sends an Ads conversion event when the SDK records a lead/email capture.
  • NEXT_PUBLIC_GOOGLE_TAG_LEAD_VALUE sets the numeric value for the lead Ads conversion. Empty or invalid values default to 0.
  • NEXT_PUBLIC_GOOGLE_TAG_PURCHASE_SEND_TO sends an Ads conversion event when the SDK records a paid checkout completion.

Ads conversion values only fire when NEXT_PUBLIC_GOOGLE_TAG_ENABLED=true. The AW-... prefix is used to load and configure gtag.js; the full AW-.../... value is sent on the conversion event.

Build, Test, Publish

npm run test:run --workspace @funnelsgrove/analytics
npm run build --workspace @funnelsgrove/analytics
npm publish --workspace @funnelsgrove/analytics --access public

The build normalizes generated relative ESM imports to explicit .js files for published package consumers.

版本与发布记录

@funnelsgrove/analytics 共发布 134 个版本,首次发布于 2026/04/04;过去 12 个月发布了 134 个版本。

版本发布日期距今
0.29.0latest2026/11/123 天前
0.28.02026/11/105 天前
0.27.02026/11/0412 天前
0.26.02026/10/3016 天前
0.25.02026/10/2819 天前
0.24.02026/10/2521 天前

关于 @funnelsgrove/analytics 的常见问题

@funnelsgrove/analytics 是什么?

Shared analytics package for public funnels.

如何安装 @funnelsgrove/analytics?

在项目目录运行 npm install @funnelsgrove/analytics,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@funnelsgrove/runtime(^0.46.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@funnelsgrove/analytics 支持 TypeScript 吗?

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

@funnelsgrove/analytics 支持 ESM 还是 CommonJS?

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

@funnelsgrove/analytics 可以商用吗?

@funnelsgrove/analytics 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@funnelsgrove/analytics 的下载量有多少?

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

@funnelsgrove/analytics 还在维护吗?

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