Metrics Service
Introduction
The MetricsService provides an interface to fetch performance metrics and insights for your Google Business Profile locations using the modern Business Profile Performance API (v1).
These types define the schema used to request performance metrics such as Map views, Search queries, website clicks, and direction requests.
You can access this service via client.metrics.
Official Documentation
Google Business Profile: Performance API Reference
Methods
fetchMultiDailyMetricsTimeSeries(locationId, request)
Returns a report containing performance metrics by location across a specific date range.
Example
typescript
import { PerformanceMetricsRequest, DailyMetric } from '@vitabletech/gbp-sdk';
const requestBody: PerformanceMetricsRequest = {
dailyMetrics: [
DailyMetric.BUSINESS_IMPRESSIONS_DESKTOP_MAPS,
DailyMetric.WEBSITE_CLICKS,
],
dailyRange: {
start_date: { year: 2023, month: 1, day: 1 },
end_date: { year: 2023, month: 1, day: 31 },
},
};
// Fetch Metrics for a location using the native service
const response = await client.metrics.fetchMultiDailyMetricsTimeSeries(
'locations/12345',
requestBody
);
console.log('Metrics Response:', response);Key Interfaces and Enums
The SDK exports the following primary types based on Google's official Performance API schema:
PerformanceMetricsRequest: The root object containingdailyMetricsanddailyRange.DailyRange: Containsstart_dateandend_date(asDateRangeobjects with year, month, day).DailyMetric(Enum): The exact performance data points you want to track, including:BUSINESS_IMPRESSIONS_DESKTOP_MAPSBUSINESS_IMPRESSIONS_DESKTOP_SEARCHBUSINESS_IMPRESSIONS_MOBILE_MAPSBUSINESS_IMPRESSIONS_MOBILE_SEARCHBUSINESS_CONVERSATIONSBUSINESS_DIRECTION_REQUESTSCALL_CLICKSWEBSITE_CLICKSBUSINESS_BOOKINGSBUSINESS_FOOD_ORDERSBUSINESS_FOOD_MENU_CLICKS