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, direction requests, and search keyword impression counts.
You can access this service via client.metrics or conveniently through client.locations.
Official Documentation
- Method: locations.getDailyMetricsTimeSeries
- Method: locations.fetchMultiDailyMetricsTimeSeries
- REST Resource: locations.searchkeywords.impressions.monthly
Methods
getDailyMetricsTimeSeries(locationId, request)
Returns daily metrics time series for a location for a single daily metric across a date range.
Example
import {
DailyMetric,
GetDailyMetricsTimeSeriesRequest,
} from '@vitabletech/gbp-sdk';
const request: GetDailyMetricsTimeSeriesRequest = {
dailyMetric: DailyMetric.WEBSITE_CLICKS,
dailyRange: {
startDate: { year: 2024, month: 1, day: 1 },
endDate: { year: 2024, month: 1, day: 31 },
},
};
const response = await client.metrics.getDailyMetricsTimeSeries(
'locations/12345',
request
);
// or client.locations.getDailyMetricsTimeSeries('12345', request);
console.log('Daily Metrics Time Series:', response.timeSeries);fetchMultiDailyMetricsTimeSeries(locationId, request)
Returns a report containing performance metrics by location across a specific date range for multiple metrics.
Example
import { PerformanceMetricsRequest, DailyMetric } from '@vitabletech/gbp-sdk';
const requestBody: PerformanceMetricsRequest = {
dailyMetrics: [
DailyMetric.BUSINESS_IMPRESSIONS_DESKTOP_MAPS,
DailyMetric.WEBSITE_CLICKS,
],
dailyRange: {
start_date: { year: 2024, month: 1, day: 1 },
end_date: { year: 2024, month: 1, day: 31 },
},
};
const response = await client.metrics.fetchMultiDailyMetricsTimeSeries(
'locations/12345',
requestBody
);
console.log('Multi Daily Metrics:', response.multiDailyMetricTimeSeries);listSearchKeywordsImpressionsMonthly(locationId, request)
Returns search keywords used to find the business along with monthly impression counts or threshold privacy flags.
Example
const response = await client.metrics.listSearchKeywordsImpressionsMonthly(
'12345',
{
monthlyRange: {
startMonth: { year: 2024, month: 1 },
endMonth: { year: 2024, month: 3 },
},
pageSize: 50,
}
);
console.log('Keywords:', response.searchKeywordsCounts);listAllSearchKeywordsImpressionsMonthly(locationId, request)
Automatically paginates and returns all keyword counts across all pages.
const allKeywords =
await client.metrics.listAllSearchKeywordsImpressionsMonthly('12345', {
monthlyRange: {
startMonth: { year: 2024, month: 1 },
endMonth: { year: 2024, month: 3 },
},
});listSearchKeywordsImpressionsMonthlyPaginator(locationId, request)
Returns a cursor paginator to traverse keyword impressions page-by-page.
const paginator = client.metrics.listSearchKeywordsImpressionsMonthlyPaginator(
'12345',
{
monthlyRange: {
startMonth: { year: 2024, month: 1 },
endMonth: { year: 2024, month: 3 },
},
pageSize: 25,
}
);
while (paginator.hasMore) {
const page = await paginator.next();
console.log(`Fetched ${page.length} keywords`);
}REST Resource Syntax: searchkeywords.impressions.monthly.list
You can also use the exact REST resource hierarchy as documented in Google API references:
const response = await client.locations.searchkeywords.impressions.monthly.list(
'12345',
{
monthlyRange: {
startMonth: { year: 2024, month: 1 },
endMonth: { year: 2024, month: 3 },
},
}
);Key Interfaces and Enums
The SDK exports the following primary types based on Google's official Performance API schema:
DailyMetric(Enum): The exact performance data points:BUSINESS_IMPRESSIONS_DESKTOP_MAPSBUSINESS_IMPRESSIONS_DESKTOP_SEARCHBUSINESS_IMPRESSIONS_MOBILE_MAPSBUSINESS_IMPRESSIONS_MOBILE_SEARCHBUSINESS_CONVERSATIONSBUSINESS_DIRECTION_REQUESTSCALL_CLICKSWEBSITE_CLICKSBUSINESS_BOOKINGSBUSINESS_FOOD_ORDERSBUSINESS_FOOD_MENU_CLICKS
DayOfWeek(Enum):MONDAY,TUESDAY,WEDNESDAY, etc.DailyRange: ContainsstartDate/start_dateandendDate/end_date.MonthlyRange: ContainsstartMonth/start_monthandendMonth/end_month.GetDailyMetricsTimeSeriesRequest: Request parameters for single-metric daily time series.GetDailyMetricsTimeSeriesResponse: Response containingtimeSeriesanddatedValues.PerformanceMetricsRequest: Request parameters for multi-daily metrics.FetchMultiDailyMetricsTimeSeriesResponse: Response containingmultiDailyMetricTimeSeries.ListSearchKeywordsImpressionsMonthlyRequest: Request parameters for monthly keyword impressions.ListSearchKeywordsImpressionsMonthlyResponse: Response containingsearchKeywordsCountsandnextPageToken.