Analytics

Fetch Google, Bing, and Facebook profile analytics with the listingsapi-js SDK.

The analytics methods pull platform-level insights, such as search impressions, clicks, direction requests, and phone calls, from Google Business Profile, Bing Places, and Facebook Pages. All analytics methods live directly on the ListingsAPI client instance and are scoped to a location ID. Numeric location IDs are encoded automatically, so 16808 and 'TG9jYXRpb246MTY4MDg=' are interchangeable.

All three methods share the same signature: a location ID plus an optional { fromDate, toDate } range. Both dates are optional, individually or together; omit them to use the platform's default reporting window.

fetchGoogleAnalytics

Fetch Google Business Profile insights for a location.

TypeScript
const google = await client.fetchGoogleAnalytics(16808, {
fromDate: '2024-01-01',
toDate: '2024-12-31',
});
 
console.log(google.totalSearches);
console.log(google.totalViews);
console.log(google.totalActions);

Options

ParameterTypeDescription
fromDatestringStart date, YYYY-MM-DD.
toDatestringEnd date, YYYY-MM-DD.

The return type is an open-ended object. Typical fields include totalSearches, totalViews, totalActions, directionRequests, phoneCallClicks, and websiteClicks. The exact shape depends on which metrics Google makes available for the connected profile.

fetchBingAnalytics

Fetch Bing Places insights for a location.

TypeScript
const bing = await client.fetchBingAnalytics(16808, {
fromDate: '2024-01-01',
toDate: '2024-12-31',
});
 
console.log(bing.totalImpressions);
console.log(bing.totalClicks);

Options

ParameterTypeDescription
fromDatestringStart date, YYYY-MM-DD.
toDatestringEnd date, YYYY-MM-DD.

fetchFacebookAnalytics

Fetch Facebook page insights for a location.

TypeScript
const facebook = await client.fetchFacebookAnalytics(16808, {
fromDate: '2024-01-01',
toDate: '2024-12-31',
});
 
console.log(facebook.pageViews);
console.log(facebook.pageLikes);

Options

ParameterTypeDescription
fromDatestringStart date, YYYY-MM-DD.
toDatestringEnd date, YYYY-MM-DD.

Multi-platform report

Fetch all three platforms in parallel with Promise.all:

analytics_report.ts
import { ListingsAPI } from 'listingsapi-js';
 
const client = new ListingsAPI(); // reads LISTINGSAPI_KEY from env
const LOCATION_ID = 16808; // Acme Dental
const range = { fromDate: '2024-01-01', toDate: '2024-12-31' };
 
const [google, bing, facebook] = await Promise.all([
client.fetchGoogleAnalytics(LOCATION_ID, range),
client.fetchBingAnalytics(LOCATION_ID, range),
client.fetchFacebookAnalytics(LOCATION_ID, range),
]);
 
console.log('Google searches:', google.totalSearches ?? 0);
console.log('Bing impressions:', bing.totalImpressions ?? 0);
console.log('Facebook views:', facebook.pageViews ?? 0);

If a profile is not connected for a given platform, the method resolves with an empty object rather than rejecting, so guard optional fields with ?? as shown above. Request failures still throw the SDK's typed errors.

  • Locations: look up location IDs
  • Reviews: review analytics (overview, timeline, sites-stats)
  • Use cases: analytics report recipe