开始使用
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-performance`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-performance/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题:安装bun add @capgo/capacitor-firebase-performancebunx cap sync导入
标题:导入import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';API 概述
标题:API 概述startTrace
标题:startTrace开始追踪
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.startTrace({} as StartTraceOptions);stopTrace
标题:“stopTrace”停止跟踪。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.stopTrace({} as StopTraceOptions);incrementMetric
标题:“incrementMetric”原子性地将给定名称的指标在选定的跟踪中增加指定的值。 incrementBy 复制到剪贴板
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.incrementMetric({} as IncrementMetricOptions);setEnabled
启用或禁用性能监控。
将在下次启动应用时应用。复制到剪贴板
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.setEnabled({} as SetEnabledOptions);isEnabled
复制到剪贴板确定是否启用或禁用性能监控。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.isEnabled();putAttribute
“putAttribute”部分设置一个跟踪的自定义属性到一个给定的值。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.putAttribute({} as PutAttributeOptions);getAttribute
“getAttribute”部分返回一个跟踪的自定义属性的值。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.getAttribute({} as GetAttributeOptions);getAttributes
“getAttributes”部分获取一个跟踪的所有自定义属性及其值。
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.getAttributes({} as GetAttributesOptions);removeAttribute
“removeAttribute”部分移除一个trace的自定义属性
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.removeAttribute({} as RemoveAttributeOptions);putMetric
标题:putMetric设置自定义指标的值
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.putMetric({} as PutMetricOptions);getMetric
标题:getMetric通过名称获取自定义指标的值
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.getMetric({} as GetMetricOptions);record
标题:record记录一个trace
仅在web上可用
import { FirebasePerformance } from '@capgo/capacitor-firebase-performance';
await FirebasePerformance.record({} as RecordOptions);类型参考
类型参考StartTraceOptions
开始跟踪选项export interface StartTraceOptions { /** * Custom trace name. * * Names for custom code traces must meet the following requirements: * no leading or trailing whitespace, no leading underscore (_) character, * and max length is 100 characters. * * @since 0.1.0 */ traceName: string;}StopTraceOptions
停止跟踪选项export interface StopTraceOptions { /** * Name of the trace that was set with `startTrace`. * * @since 0.1.0 */ traceName: string;}IncrementMetricOptions
增量指标选项export interface IncrementMetricOptions { /** * Name of the trace that was set with `startTrace`. * * @since 0.1.0 */ traceName: string; /** * Name of the metric to be incremented. * * @since 0.1.0 */ metricName: string; /** * Amount by which the metric has to be incremented. * * @default 1 * @since 0.1.0 */ incrementBy?: number;}SetEnabledOptions
设置启用选项export interface SetEnabledOptions { /** * Should performance monitoring be enabled. * * @since 0.1.0 */ enabled: boolean;}IsEnabledResult
是否启用结果export interface IsEnabledResult { /** * `true` if performance monitoring is enabled, otherwise `false`. * * @since 0.1.0 */ enabled: boolean;}PutAttributeOptions
Section titled “PutAttributeOptions”export interface PutAttributeOptions { /** * Name of the trace to set its attribute. * * @since 6.3.0 */ traceName: string; /** * Name of the attribute to set its value. * * @since 6.3.0 * @example "experiment" */ attribute: string; /** * The value to set to the attribute. * * @since 6.3.0 * @example "A" */ value: string;}GetAttributeOptions
Section titled “GetAttributeOptions”export interface GetAttributeOptions { /** * Name of the trace to set its attribute. * * @since 6.3.0 */ traceName: string; /** * Name of the attribute to retrieve its value. * * @since 6.3.0 */ attribute: string;}GetAttributeResult
Section titled “GetAttributeResult”export interface GetAttributeResult { /** * The value of the custom attribute. * * @since 6.3.0 */ value: string | null;}GetAttributesOptions
Section titled “GetAttributesOptions”export interface GetAttributesOptions { /** * Name of the trace to get its attributes. * * @since 6.3.0 */ traceName: string;}GetAttributesResult
Section titled “GetAttributesResult”export interface GetAttributesResult { /** * A map of all custom attributes of a trace with their values. * * @since 6.3.0 */ attributes: { [key: string]: string };}RemoveAttributeOptions
Section titled “RemoveAttributeOptions”export type RemoveAttributeOptions = GetAttributeOptions;PutMetricOptions
Section titled “PutMetricOptions”export interface PutMetricOptions { /** * Name of the trace to set its metric. * * @since 6.3.0 */ traceName: string; /** * The metric name. * * @since 6.3.0 */ metricName: string; /** * The value to set for the metric. * The given value is floored down to the nearest integer. * * @since 6.3.0 */ num: number;}真实数据来源
Section titled “真实数据来源”本页面是由插件生成的 src/definitions.ts. 当公共 API 上游更改时,请重新运行同步。