1.4.0 • Published 2 years ago

@robingenz/capacitor-firebase-performance v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@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.5)

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.

ParamType
optionsStartTraceOptions

stopTrace(...)

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

Stops a trace.

ParamType
optionsStopTraceOptions

incrementMetric(...)

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

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

ParamType
optionsIncrementMetricOptions

setPerformanceCollectionEnabled(...)

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

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

ParamType
optionsSetPerformanceCollectionEnabledOptions

isPerformanceCollectionEnabled()

isPerformanceCollectionEnabled() => Promise<IsPerformanceCollectionEnabledResult>

Determines whether performance monitoring is enabled or disabled.

Returns: Promise<IsPerformanceCollectionEnabledResult>


Interfaces

StartTraceOptions

PropTypeDescription
traceNamestringCustom 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

PropTypeDescription
traceNamestringName of the trace that was set with startTrace.

IncrementMetricOptions

PropTypeDescription
traceNamestringName of the trace that was set with startTrace.
metricNamestringName of the metric to be incremented.
incrementBynumberAmount by which the metric has to be incremented. Default: 1

SetPerformanceCollectionEnabledOptions

PropTypeDescription
enabledbooleanShould performance monitoring be enabled.

IsPerformanceCollectionEnabledResult

PropTypeDescription
enabledbooleantrue if performance monitoring is enabled, otherwise false.

Changelog

See CHANGELOG.md.

License

See LICENSE.