type TrackableEvent = { time: Timestamp // When the event occurred count?: number // Number of occurrences (default: 1) value?: number // Associated value (default: 0)}
type MetricEntitySummary = { count: number // Total event count value: number // Total accumulated value lastUpdated: Timestamp // Last update timestamp}
Represents aggregated data for a specific time period:
Copy
type MetricTimelineSection = { startTime: Timestamp // Period start time endTime: Timestamp // Period end time totalCount: number // Running total count totalValue: number // Running total value count: number // Count for this period value: number // Value for this period}
type MetricConfig = { units: DateTimeUnit[] // Time units for aggregation timezone?: string // IANA timezone identifier (default: 'UTC') dateUpdated?: Timestamp // Config last updated}
// A timeline section represents aggregated dataconst section: MetricTimelineSection = { startTime: firestore.Timestamp.fromDate(new Date('2024-01-01')), endTime: firestore.Timestamp.fromDate(new Date('2024-01-02')), count: 10, // 10 events in this day value: 999.90, // $999.90 in this day totalCount: 150, // 150 events total up to this point totalValue: 14999.50 // $14,999.50 total up to this point}
// Configure a metric to track by hour, day, and monthconst config: MetricConfig = { units: ['hour', 'day', 'month'], dateUpdated: firestore.Timestamp.now()}// Apply configurationawait firebridgeMetric('product', 'purchase').set(config)// Configure with timezone for accurate local time boundariesconst regionalConfig: MetricConfig = { units: ['day', 'week', 'month'], timezone: 'America/Los_Angeles', // Pacific Time dateUpdated: firestore.Timestamp.now()}await firebridgeMetric('store', 'sales').set(regionalConfig)