@aptabase/react-native

中文文档
0.6.0发布于 2026/08/17MITTypeScriptCommonJS零依赖近 30 天下载 1.8万

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

原始使用文档
文档目录6 节
  1. Install
  2. Android Requirements
  3. Web Support
  4. Usage
  5. Error Reporting
  6. Preparing for Submission to Apple App Store

Aptabase

React Native SDK for Aptabase

Instrument your React Native or Expo apps with Aptabase, an Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps.

Install

Install the SDK using npm or your preferred JavaScript package manager

npm add @aptabase/react-native

Android Requirements

If you're targeting Android, you'll need to add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

Web Support

This SDK also supports React Native Web!

[!NOTE] This feature is disabled by default. To enable it, you need to pass the enableWeb option when initializing the SDK.

Aptabase.init("<YOUR_APP_KEY>", {
  enableWeb: true,
  appVersion: "1.0.0", // required on web — no native module provides it
});

When enabled, the SDK will track events in web environments using the same behavior as the web SDKs. Which means that events will be sent immediately to the /event endpoint instead of grouped to the /events endpoint.

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 by calling the init function before declaring your App component:

import Aptabase from "@aptabase/react-native";

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

export default function App() {
  return <Counter />;
}

Afterwards, you can start tracking events with trackEvent:

import { trackEvent } from "@aptabase/react-native";
import { useState } from "react";

export function Counter() {
  const [count, setCount] = useState(0);

  const increment = () => {
    setCount(count + 1);
    trackEvent("increment", { count });
  };

  const decrement = () => {
    setCount(count - 1);
    trackEvent("decrement", { count });
  };

  return (
    <View>
      <Button onPress={increment} title="Increment" />
      <Button onPress={decrement} title="Decrement" />
      <Text>Count is {count}</Text>
    </View>
  );
}

To disable tracking events, you can call the dispose function. This will stop and deinitialize the SDK.

import Aptabase from "@aptabase/react-native";

Aptabase.dispose();

Note for Expo apps: Events sent during development while running on Expo Go will not have the App Version property because native modules are not available in Expo Go. However, when you build your app and run it on a real device, the App Version property will be available. Alternatively, you can also set the appVersion during the init call so that it's also available during development.

A few important notes:

  1. The SDK will automatically enhance the event with some useful information, like the OS, the app version, and other things.
  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 for the trackEvent function, it'll run in the background.
  4. Only strings and numbers values are allowed on custom properties

Error Reporting

Error reporting is in beta. Reports appear on the Errors page of your Aptabase dashboard.

Use trackError to report errors you've caught and handled:

import { trackError } from "@aptabase/react-native";

try {
  await doSomething();
} catch (error) {
  trackError(error); // severity: error
}

For errors your app can't recover from, mark the report as fatal:

trackError(error, { fatal: true }); // severity: fatal

To also report uncaught errors and crashes automatically, enable crash reporting during init:

Aptabase.init("<YOUR_APP_KEY>", {
  enableCrashReporting: true,
});

A few important notes about error reporting:

  1. Each report includes the error type, message, stack trace, severity (error or fatal) and how it was captured (handled, unhandled or crash).
  2. On native, reports are sent immediately and kept in memory for retry when the network is unavailable. On web, reports are sent immediately and not retried (web requires the enableWeb option).
  3. Errors count against a separate monthly error quota. When the quota is exhausted, the server rejects new reports until it resets.
  4. Errors caught by React Error Boundaries never reach the global error handler — call trackError from your boundary if you want them reported.
  5. Native (non-JS) crashes are not captured. During development, fatal JS errors show the RedBox instead of crashing the app.

Preparing for Submission to Apple App Store

When submitting your app to the Apple App Store, you'll need to fill out the App Privacy form. You can find all the answers on our How to fill out the Apple App Privacy when using Aptabase guide.

For AI/LLM integration instructions, see llms.txt

版本与发布记录

@aptabase/react-native 共发布 21 个版本,首次发布于 2023/05/27;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.6.0latest2026/08/172 个月前
0.5.12026/08/152 个月前
0.5.02026/06/174 个月前
0.4.02025/09/271.1 年前
0.3.102024/08/012 年前
0.3.92023/11/152 年前

关于 @aptabase/react-native 的常见问题

@aptabase/react-native 是什么?

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

如何安装 @aptabase/react-native?

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

@aptabase/react-native 支持 TypeScript 吗?

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

@aptabase/react-native 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aptabase/react-native 可以商用吗?

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

@aptabase/react-native 的下载量有多少?

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

@aptabase/react-native 还在维护吗?

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