@capgo/capacitor-rudderstack

中文文档
8.1.17发布于 2026/10/15MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4万

Capacitor plugin for RudderStack analytics, identity, and event tracking.

原始使用文档
文档目录25 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. Usage
  7. Behavior
  8. API
  9. initialize(...)
  10. identify(...)
  11. group(...)
  12. track(...)
  13. screen(...)
  14. alias(...)
  15. reset()
  16. flush()
  17. putDeviceToken(...)
  18. setAdvertisingId(...)
  19. putAdvertisingId(...)
  20. setAnonymousId(...)
  21. putAnonymousId(...)
  22. optOut(...)
  23. getPluginVersion()
  24. Interfaces
  25. Type Aliases

@capgo/capacitor-rudderstack

Send analytics events and user identities to RudderStack from your Capacitor app with the native RudderStack SDKs. A Capacitor port of rudder-sdk-cordova.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-rudderstack in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-rudderstack to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-rudderstack for Capacitor apps

Key features

  • Setup: initialize() with your write key and data plane URL.
  • Tracking: track(), screen(), identify(), group() and alias().
  • Identity: reset(), putAnonymousId(), putAdvertisingId() and putDeviceToken().
  • Privacy and delivery: optOut() and flush().
  • Easy migration: follows the Cordova plugin API shape.
  • Platforms: iOS and Android. Uses the RudderStack iOS and Android SDKs. Web has API-compatible stubs that do not send events.

Capacitor plugin for RudderStack analytics and event tracking.

This package is a Capacitor port of rudder-sdk-cordova with native Android and iOS bridges built for Capacitor 8.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/rudderstack/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation. Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-rudderstack` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

bun add @capgo/capacitor-rudderstack
bunx cap sync

Usage

import { RudderStack } from '@capgo/capacitor-rudderstack';

await RudderStack.initialize('YOUR_WRITE_KEY', {
  dataPlaneUrl: 'https://your-dataplane.rudderstack.com',
  trackLifecycleEvents: true,
  logLevel: RudderStack.LogLevel.INFO,
});

await RudderStack.identify('user_123', {
  email: '[email protected]',
  plan: 'pro',
});

await RudderStack.track('Checkout Started', {
  value: 49,
  currency: 'EUR',
});

The API intentionally follows the Cordova plugin shape so existing Rudder Cordova integrations can migrate with minimal call-site changes.

Behavior

  • Android uses the RudderStack Android SDK and exposes the Cordova-compatible analytics surface through a Capacitor bridge.
  • iOS uses the RudderStack iOS SDK with a Swift bridge that matches the same public API.
  • Web is a lightweight compatibility implementation intended for development and API parity. It does not send events to RudderStack.
  • config.factories from the Cordova plugin is currently ignored. Native destination factory companion plugins are not part of this first Capacitor port.

API

Capacitor API that mirrors the public surface of rudder-sdk-cordova.

initialize(...)

initialize(writeKey: string, config?: RudderConfiguration | RudderOptions | undefined, options?: RudderOptions | undefined) => Promise<void>

Initializes the RudderStack client.

The method keeps the Cordova signature, so the second argument may be either a config object or a Rudder options object.

ParamType
writeKeystring
configRudderConfiguration | RudderOptions
optionsRudderOptions

identify(...)

identify(userId: string, traits?: RudderOptions | RudderTraits | undefined, options?: RudderOptions | undefined) => Promise<void>

Sends an identify call for the provided user id.

ParamType
userIdstring
traitsRudderOptions | RudderTraits
optionsRudderOptions

group(...)

group(groupId: string, groupTraits?: RudderOptions | RudderTraits | undefined, options?: RudderOptions | undefined) => Promise<void>

Sends a group call for the provided group id.

ParamType
groupIdstring
groupTraitsRudderOptions | RudderTraits
optionsRudderOptions

track(...)

track(eventName: string, properties?: RudderOptions | RudderProperties | undefined, options?: RudderOptions | undefined) => Promise<void>

Sends a track call for the provided event name.

ParamType
eventNamestring
propertiesRudderOptions | RudderProperties
optionsRudderOptions

screen(...)

screen(screenName: string, properties?: RudderOptions | RudderProperties | undefined, options?: RudderOptions | undefined) => Promise<void>

Sends a screen call for the provided screen name.

ParamType
screenNamestring
propertiesRudderOptions | RudderProperties
optionsRudderOptions

alias(...)

alias(newId: string, options?: RudderOptions | undefined) => Promise<void>

Aliases the current user to a new identifier.

ParamType
newIdstring
optionsRudderOptions

reset()

reset() => Promise<void>

Resets the current RudderStack identity state.


flush()

flush() => Promise<void>

Flushes queued events immediately.


putDeviceToken(...)

putDeviceToken(deviceToken: string) => Promise<void>

Sets the push token that RudderStack forwards to supported destinations.

ParamType
deviceTokenstring

setAdvertisingId(...)

setAdvertisingId(advertisingId: string) => Promise<void>
ParamType
advertisingIdstring

putAdvertisingId(...)

putAdvertisingId(advertisingId: string) => Promise<void>

Sets a custom advertising id value.

ParamType
advertisingIdstring

setAnonymousId(...)

setAnonymousId(anonymousId: string) => Promise<void>
ParamType
anonymousIdstring

putAnonymousId(...)

putAnonymousId(anonymousId: string) => Promise<void>

Sets a custom anonymous id value.

ParamType
anonymousIdstring

optOut(...)

optOut(optOut: boolean) => Promise<void>

Toggles RudderStack tracking opt-out.

ParamType
optOutboolean

getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Returns the plugin version marker from the native implementation.

Returns: Promise<PluginVersionResult>


Interfaces

RudderConfiguration

Supported configuration keys for the underlying RudderStack native SDKs.

PropTypeDescription
dataPlaneUrlstringRudderStack data plane URL.
flushQueueSizenumberNumber of events to batch before a flush.
dbCountThresholdnumberDatabase row threshold that triggers pruning on Android and iOS.
configRefreshIntervalnumberServer config refresh interval in hours.
logLevelRudderLogLevelValueRudderStack log verbosity.
sleepTimeOutnumberSleep timeout / sleep count used by the native SDK.
autoCollectAdvertIdbooleanAndroid only. Lets the native SDK collect the advertising identifier automatically.
trackLifecycleEventsbooleanTracks Application Installed, Application Updated, and Application Opened automatically.
controlPlaneUrlstringRudderStack control plane URL.
recordScreenViewsbooleanEnables automatic screen tracking where supported by the native SDK.
factoriesany[]Ignored in this Capacitor port. The Cordova SDK uses this field to bootstrap native destination factories from companion plugins. Those extension packages are not implemented in this first Capacitor release.

RudderOptions

RudderStack per-call options.

PropTypeDescription
externalIdsRecord<string, string>External identifiers forwarded with the event.
integrationsRecord<string, boolean>Destination enablement flags keyed by integration name.

PluginVersionResult

Plugin version payload.

PropTypeDescription
versionstringVersion identifier returned by the platform implementation.

Type Aliases

RudderLogLevelValue

RudderStack log level values exposed for migration convenience.

0 | 1 | 2 | 3 | 4 | 5

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

RudderTraits

Traits payload accepted by identify and group.

Record<string, any>

RudderProperties

Properties payload accepted by track and screen.

Record<string, any>

版本与发布记录

@capgo/capacitor-rudderstack 共发布 16 个版本,首次发布于 2026/05/11;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.17latest2026/10/1525 天前
8.1.162026/10/1327 天前
8.1.152026/10/091 个月前
8.1.132026/10/081 个月前
8.1.142026/10/081 个月前
8.1.122026/09/161 个月前

关于 @capgo/capacitor-rudderstack 的常见问题

@capgo/capacitor-rudderstack 是什么?

Capacitor plugin for RudderStack analytics, identity, and event tracking.

如何安装 @capgo/capacitor-rudderstack?

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

@capgo/capacitor-rudderstack 支持 TypeScript 吗?

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

@capgo/capacitor-rudderstack 支持 ESM 还是 CommonJS?

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

@capgo/capacitor-rudderstack 可以商用吗?

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

@capgo/capacitor-rudderstack 的下载量有多少?

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

@capgo/capacitor-rudderstack 还在维护吗?

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