@aptabase/web

中文文档
0.5.0发布于 2026/01/21MITTypeScriptESM + CJS零依赖近 30 天下载 1.3万

JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps

原始使用文档

Aptabase

Aptabase SDK for Web Apps

A tiny SDK (1 kB) to instrument your web app with Aptabase, an Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps.

Building a React app? Use the @aptabase/react package instead.

👉 IMPORTANT

This SDK is for Web Applications, not websites. There's a subtle, but important difference. A web app is often a lot more interactive and does not cause a full page reload when the user interacts with it. It's often called a Single-Page Application. A website, on the other hand, is a lot more content-focused like marketing sites, landing pages, blogs, etc. While you can certainly use Aptabase to track events on websites, please be aware that each page reload will be considered a new session.

Install

Install the SDK using npm or your preferred JavaScript package manager

npm add @aptabase/web

Usage

First you need to get your App Key from Aptabase, you can find it in the Instructions menu on the left side menu.

Initialize the SDK using your App Key:

import { init } from '@aptabase/web';

init('<YOUR_APP_KEY>'); // 👈 this is where you enter your App Key

The init function also supports an optional second parameter, which is an object with the appVersion property.

It's up to you to decide how to get the version of your app, but it's generally recommended to use your bundler (like Webpack, Vite, Rollup, etc.) to inject the values at build time. Alternatively you can also pass it in manually.

Afterwards you can start tracking events with trackEvent:

import { trackEvent } from '@aptabase/web';

trackEvent('connect_click'); // An event with no properties
trackEvent('play_music', { name: 'Here comes the sun' }); // An event with a custom property

A few important notes:

  1. The SDK will automatically enhance the event with some useful information, like the OS and other properties.
  2. You're in control of what gets sent to Aptabase. This SDK does not automatically track any events, you need to call trackEvent manually.
    • Because of this, it's generally recommended to at least track an event at startup
  3. You do not need to await the trackEvent function, it'll run in the background.
  4. Only strings and numeric values are allowed on custom properties

版本与发布记录

@aptabase/web 共发布 16 个版本,首次发布于 2023/04/02;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.5.0latest2026/01/219 个月前
0.4.32024/07/202 年前
0.4.22023/12/292 年前
0.4.12023/12/292 年前
0.4.02023/12/162 年前
0.3.22023/11/053 年前

关于 @aptabase/web 的常见问题

@aptabase/web 是什么?

JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps

如何安装 @aptabase/web?

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

@aptabase/web 支持 TypeScript 吗?

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

@aptabase/web 支持 ESM 还是 CommonJS?

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

@aptabase/web 可以商用吗?

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

@aptabase/web 的下载量有多少?

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

@aptabase/web 还在维护吗?

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