Skip to main content
The metrics system provides several utility functions to help you work with metrics data, build timelines, and access metric configurations.

firebridgeMetric

The main utility for accessing and managing metrics.

Function Signature

Returns

A metric utility object with methods for:
  • Managing metric configuration
  • Accessing entity data
  • Working with timelines

Example Usage

Entity Methods

When you access an entity through metric.entity(entityId), you get:

Summary Methods

Timeline Access

buildTimeline

Builds aggregated timeline sections from an array of events.

Function Signature

Parameters

  • events: Array of events to aggregate
  • unit: Time unit for aggregation (default: ‘day’)
  • timezone: IANA timezone identifier (default: ‘UTC’)
  • startingCount: Initial count value (default: 0)
  • startingValue: Initial value sum (default: 0)

Example

getEventsInRange

Filters events within a specific date range.

Function Signature

Example

Advanced Patterns

Custom Metric Wrapper

Create a typed wrapper for your metrics:

Metric Migration

Migrate metrics between different structures:

Timeline Analysis

Analyze timeline data for insights:

Batch Processing

Process metrics in batches for better performance:

Timezone Examples

Configure Timezone for Account-Specific Metrics

Set up metrics to aggregate based on local business hours:

Multi-Region Support

Handle metrics for different regions with appropriate timezones:

Timezone-Aware Event Tracking

When events cross day boundaries, they’re correctly assigned:

Performance Tips

  1. Use appropriate time units: Don’t track by second if you only need daily data
  2. Batch updates: Use updateMetric for multiple events instead of individual incrementMetric calls
  3. Clean old data: Periodically remove old timeline data you no longer need
  4. Index considerations: Firestore automatically indexes the metric paths
  5. Timezone performance: Timezone calculations add minimal overhead and are cached by Luxon

See Also