@djangocfg/analytics

中文文档
2.1.653发布于 2026/11/12MITTypeScriptESM + CJS零依赖近 30 天下载 1.5万

First-party analytics for django-cfg apps: one route listener, N transports (self-hosted + GA4). Pageviews, sessions, and authenticated-user attribution.

原始使用文档

@djangocfg/analytics

First-party product analytics for DjangoCFG. One client fans out pageviews and custom events to django-cfg and optional GA4 transports.

Product events

Mount AnalyticsProvider once (Layouts BaseApp does this automatically), then use the typed React API:

import { useAnalytics } from '@djangocfg/analytics'

const { event } = useAnalytics()
event('layouts.auth.step_viewed', { step: 'otp' })
event('billing.checkout_started', { plan: 'pro' })

For browser integration code outside React, use the optional facade installed by the provider. It is the same client — not a second transport:

window.analytics?.event('billing.checkout_started', { plan: 'pro' })

Unknown product event names are accepted. Extend AnalyticsEventMap to make your product's names and properties type-safe everywhere:

declare module '@djangocfg/analytics' {
  interface AnalyticsEventMap {
    'billing.checkout_started': { plan: 'pro' | 'team' }
  }
}

Use stable event names as your analytics contract. Django goals and funnels are configured against those names; do not encode dynamic identifiers in names — put bounded, non-sensitive dimensions in props instead.

Identity and funnels

Browser journeys are scoped to a host. A property can aggregate hosts, but it does not merge anonymous visitor identities across them. Server-confirmed auth events use the request-derived identity for their originating host, so an auth funnel on that host can join its UI and successful-login events safely.

版本与发布记录

@djangocfg/analytics 共发布 151 个版本,首次发布于 2026/07/21;过去 12 个月发布了 151 个版本。

版本发布日期距今
2.1.653latest2026/11/12今天
2.1.6522026/11/11今天
2.1.6512026/11/111 天前
2.1.6502026/11/111 天前
2.1.6482026/11/111 天前
2.1.6472026/11/111 天前

关于 @djangocfg/analytics 的常见问题

@djangocfg/analytics 是什么?

First-party analytics for django-cfg apps: one route listener, N transports (self-hosted + GA4). Pageviews, sessions, and authenticated-user attribution.

如何安装 @djangocfg/analytics?

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

@djangocfg/analytics 支持 TypeScript 吗?

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

@djangocfg/analytics 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@djangocfg/analytics 可以商用吗?

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

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

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

@djangocfg/analytics 还在维护吗?

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