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 throughmetric.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
- Use appropriate time units: Don’t track by second if you only need daily data
- Batch updates: Use
updateMetric
for multiple events instead of individualincrementMetric
calls - Clean old data: Periodically remove old timeline data you no longer need
- Index considerations: Firestore automatically indexes the metric paths
- Timezone performance: Timezone calculations add minimal overhead and are cached by Luxon
See Also
- Overview - Introduction to metrics
- incrementMetric - Real-time tracking
- updateMetric - Batch updates
- Types Reference - Type definitions