指南
如何在 Capacitor 中使用 Firebase Performance
使用@capgo/capacitor-firebase-performance
Capacitor插件用于Firebase性能监控。
安装
bun add @capgo/capacitor-firebase-performance
bunx cap sync
bunx cap sync 将插件的本机code复制到您的本机项目中。每次升级插件后都要再次运行。
导入
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
API概览
| 方法 | 描述 |
|---|---|
startTrace |
开始跟踪 |
stopTrace |
停止跟踪 |
incrementMetric |
原子性地将给定名称的指标值在所选跟踪中增加。 incrementBy 增加 |
setEnabled |
启用或禁用应用性能监控。将在下次应用启动时生效。 |
isEnabled |
确定应用性能监控是否启用或禁用。 |
putAttribute |
设置一个跟踪的自定义属性值。 |
getAttribute |
获取一个跟踪的自定义属性值。 |
getAttributes |
获取一个跟踪的所有自定义属性及其值。 |
removeAttribute |
从跟踪中删除一个自定义属性。 |
putMetric |
设置一个自定义指标的值。 |
getMetric |
通过名称获取一个自定义指标的值。 |
record |
通过名称和选项记录一个跟踪。 |
Examples
startTrace()
开始一个跟踪。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.startTrace({ traceName: 'trace' });
stopTrace()
停止一个跟踪。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.stopTrace({ traceName: 'trace' });
incrementMetric()
原子性地增加了给定名称的指标的值,用于选定的跟踪。 incrementBy 增加指标的值。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.incrementMetric({
traceName: 'trace',
metricName: 'metric',
});
setEnabled()
启用或禁用性能监控。将在下一次应用启动时应用。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.setEnabled({ enabled: true });
isEnabled()
是否启用或禁用性能监控。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
const result = await FirebasePerformance.isEnabled();
console.log(result);
putAttribute()
设置跟踪的自定义属性。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.putAttribute({
traceName: 'trace',
attribute: "experiment",
value: "A",
});
上表列出了 12 个核心方法。监听器和版本辅助函数,以及每个方法的完整契约,均在 __CAPGO_KEEP_0__ 仓库中文档化。 GitHub 仓库.
文档
继续使用@capgo/capacitor-firebase-performance
如果您正在使用 使用 @capgo/capacitor-firebase-performance 为了规划原生插件工作,连接它与 Capgo 插件目录 在 Capgo 插件目录中,了解产品工作流程 Capacitor 插件由 Capgo 在 Capacitor 插件由 Capgo 中了解实现细节 添加或更新插件 在添加或更新插件中了解实现细节 Ionic 企业插件替代品 了解 Ionic 企业插件替代品中的产品工作流程 Capgo 原生构建 为Capgo Native Builds 的产品工作流程。