@robingenz/capacitor-firebase-performance

Capacitor plugin for Firebase Performance Monitoring.

Usage no npm install needed!

<script type="module">
  import robingenzCapacitorFirebasePerformance from 'https://cdn.skypack.dev/@robingenz/capacitor-firebase-performance';
</script>

README


Firebase Performance

@robingenz/capacitor-firebase-performance

Capacitor plugin for Firebase Performance Monitoring.


Maintainers

Maintainer GitHub Social
Robin Genz robingenz @robin_genz

Installation

npm install @robingenz/capacitor-firebase-performance firebase
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS / Web).

Android

See Add the Performance Monitoring plugin to your app and follow the instructions to set up your app correctly.

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $firebasePerfVersion version of com.google.firebase:firebase-perf (default: 20.0.2)

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Usage

import { FirebasePerformance } from '@robingenz/capacitor-firebase-performance';

const startTrace = async () => {
  await FirebasePerformance.startTrace({ traceName: 'test_trace' });
};

const stopTrace = async () => {
  await FirebasePerformance.stopTrace({ traceName: 'test_trace' });
};

const incrementMetric = async () => {
  await FirebasePerformance.incrementMetric({ 
    traceName: 'test_trace', 
    metricName: 'item_cache_hit', 
    incrementBy: 1 
  });
};

const setPerformanceCollectionEnabled = async () => {
  await FirebasePerformance.setPerformanceCollectionEnabled({ enabled: true });
};

const isPerformanceCollectionEnabled = async () => {
  const result = await FirebasePerformance.isPerformanceCollectionEnabled();
  return result.enabled;
};

API

startTrace(...)

startTrace(options: StartTraceOptions) => Promise<void>

Starts a trace.

Param Type
options StartTraceOptions

stopTrace(...)

stopTrace(options: StopTraceOptions) => Promise<void>

Stops a trace.

Param Type
options StopTraceOptions

incrementMetric(...)

incrementMetric(options: IncrementMetricOptions) => Promise<void>

Atomically increments the metric with the given name for the selected trace by the incrementBy value.

Param Type
options IncrementMetricOptions

setPerformanceCollectionEnabled(...)

setPerformanceCollectionEnabled(options: SetPerformanceCollectionEnabledOptions) => Promise<void>

Enables or disables performance monitoring. Will be applied with the next start of the app.

Param Type
options SetPerformanceCollectionEnabledOptions

isPerformanceCollectionEnabled()

isPerformanceCollectionEnabled() => Promise<IsPerformanceCollectionEnabledResult>

Determines whether performance monitoring is enabled or disabled.

Returns: Promise<IsPerformanceCollectionEnabledResult>


Interfaces

StartTraceOptions

Prop Type Description
traceName string 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.

StopTraceOptions

Prop Type Description
traceName string Name of the trace that was set with startTrace.

IncrementMetricOptions

Prop Type Description
traceName string Name of the trace that was set with startTrace.
metricName string Name of the metric to be incremented.
incrementBy number Amount by which the metric has to be incremented. Default: 1

SetPerformanceCollectionEnabledOptions

Prop Type Description
enabled boolean Should performance monitoring be enabled.

IsPerformanceCollectionEnabledResult

Prop Type Description
enabled boolean true if performance monitoring is enabled, otherwise false.

Changelog

See CHANGELOG.md.

License

See LICENSE.