ガイド
Capacitor で Firebase Performance を使用する方法
@capgo/capacitor-firebase-performance の使用方法
Firebase Performance Monitoring 用の Capacitor プラグイン
インストール
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 value. |
setEnabled |
パフォーマンスモニタリングの有効/無効を切り替えます。設定は次回のアプリ起動時に適用されます。 |
isEnabled |
パフォーマンスモニタリングが有効か無効かを判定します。 |
putAttribute |
トレースのカスタム属性に指定した値を設定します。 |
getAttribute |
トレースのカスタム属性の値を返します。 |
getAttributes |
トレースのすべてのカスタム属性とその値を取得します。 |
removeAttribute |
指定した名前のカスタム属性をトレースから削除します。 |
putMetric |
カスタムメトリクスの値を設定します。 |
getMetric |
指定した名前のカスタムメトリクスの値を取得します。 |
record |
名前とオプションを指定してトレースを記録します。 |
例
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 value.
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個のコアメソッドを一覧にしています。リスナーとバージョンのヘルパー、および各メソッドの完全な仕様は、以下に記載されています。 GitHub リポジトリ.
完全なリファレンス
@capgo/capacitor-firebase-performance の使用方法へ
使用している場合 @capgo/capacitor-firebase-performance の使用方法 ネイティブプラグインの作業を計画するには、次と連携してください: Capgo プラグインディレクトリ Capgo プラグインディレクトリのプロダクトワークフローについては、 Capgo による Capacitor プラグイン Capgo による Capacitor プラグインの実装詳細については、 プラグインの追加または更新 プラグインの追加または更新に関する実装詳細については、 Ionic Enterprise プラグインの代替案 Ionic Enterprise Plugin Alternatives のプロダクトワークフロー、および Capgo Native Build Capgo Native Builds のプロダクトワークフローについては、