使用 @capgo/capacitor-rudderstack
镜像了 Capacitor API 的公开接口 rudder-sdk-cordova.
安装
bun add @capgo/capacitor-rudderstack
bunx cap sync
bunx cap sync 将插件的原生 code 复制到你的原生项目中。每次升级插件后都要重新运行。
导入
import { nativePlugin } from '@capgo/capacitor-rudderstack';
API 概览
| 方法 | 描述 |
|---|---|
initialize |
初始化 RudderStack 客户端。 |
identify |
为提供的用户 ID 发送 identify 调用。 |
group |
为提供的 group ID 发送 group 调用。 |
track |
为提供的事件名称发送 track 调用。 |
screen |
为提供的屏幕名称发送 screen 调用。 |
alias |
将当前用户关联到新的标识符。 |
reset |
重置当前的 RudderStack 身份状态。 |
flush |
立即发送队列中的事件。 |
putDeviceToken |
设置 RudderStack 转发到支持的目标端的 push token。 |
setAdvertisingId |
查看源码定义以了解当前行为。 |
putAdvertisingId |
设置自定义广告 ID 值。 |
setAnonymousId |
查看源码定义以了解当前行为。 |
putAnonymousId |
设置自定义匿名 ID 值。 |
optOut |
切换 RudderStack 追踪退出状态。 |
示例
initialize()
初始化 RudderStack 客户端。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.initialize('write-key-123');
identify()
为提供的用户 ID 发送 identify 调用。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.identify('user-id-123');
group()
为提供的 group ID 发送 group 调用。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.group('group-id-123');
track()
为提供的事件名称发送 track 调用。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.track('event');
screen()
为提供的屏幕名称发送 screen 调用。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.screen('screen');
alias()
将当前用户关联到新的标识符。
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.alias('new-id-123');
上表列出了 14 个核心方法。监听器与版本辅助函数,以及每个方法的完整规范,均记录在 GitHub 仓库.
完整参考文档
继续阅读“使用 @capgo/capacitor-rudderstack”
如果你正在使用 使用 @capgo/capacitor-rudderstack 要规划 dashboard 和 API 操作,请将其连接到 @capgo/capacitor-rudderstack 了解 @capgo/capacitor-rudderstack 中的实现细节, 快速入门 有关“入门指南”中的实现细节, API 概览 关于 API Overview 中的实现细节, 简介 关于简介中的实现细节,以及 API 密钥 关于 API Keys 中的实现细节。