Skip to main content

Analytics

Warning

The Analytics API beta is closed to new customers. The Analytics API is still available for use, but Mapbox will not incorporate any new features or new metrics right now. Note that map views, which are returned by the API, are deprecated and are no longer used to track map usage for Mapbox products. For details on current pricing structures including map loads, see Pricing by product.

The Mapbox Analytics API returns API usage for services by resource. For example, it can calculate the number of geocoding requests made in one week using a specific access token.

To use the Mapbox Analytics API, you need an access token with the analytics:read scope. To create a new secret token with the correct scope, visit your Account Dashboard. Click Create a token and select the analytics:read scope.

Retrieve request counts

get
https://api.mapbox.com/analytics/v1/{resource_type}/{username}/{id}?period={period}
analytics:read

Returns the request counts per day for the given resource, in the specified period of time.

Required parametersDescription
resource_typeThe resource being requested. Valid resource types are: accounts, tokens, tilesets or styles.
usernameThe username of the account that owns the resource.
idThe ID of the resource.
If resource_type is:The id is:
accountsNot required.
tokensThe complete token.
stylesThe style ID, which is the alphanumeric segment at the end of a style URL. (The style URL mapbox://styles/user/cimdoca6f00 contains the style ID cimdoca6f00.)
tilesetsThe tileset ID.

You can further refine the results from this endpoint with the optional period query parameter:

Optional parametersDescription
periodTwo comma-separated dates as ISO formatted strings. The first date must be earlier than the second, and the maximum period is one year. period is inclusive of the dates provided. The default value is the previous 90 days.

Example request: Retrieve request counts

# Request usage data for the user mapbox's tileset mapbox.streets during a specific 2-day period

$ curl "https://api.mapbox.com/analytics/v1/tilesets/mapbox/mapbox.streets?period=2018-03-22T00:00:00.000Z,2018-03-24T00:00:00.000Z&access_token=YOUR_MAPBOX_ACCESS_TOKEN"

Response: Retrieve request counts

A response to the Analytics API is a JSON object that contains the following properties:

PropertyDescription
timestampsAn array of dates as ISO formatted strings for each day included in the response.
periodA two-element array with the start and end dates of the response period as ISO formatted strings.
servicesAn object with a key for each applicable service. The value for each key is an array of request counts per day in the same sequence as timestamps. Only services applicable to the given resource are returned in the response:
Resource typeServices returned in response
accountsmapview, static, tile, directions, geocode
tokensmapview, static, tile, directions, geocode
tilesetsmapview, static, tile
stylesmapview, static, tile
For the styles resource type, static and tile services refer to the Static API. For the tilesets resource type, static and tile services refer to the Legacy Maps API.

Example response: Retrieve request counts

{
"period": ["2016-03-22T00:00:00.000Z", "2016-03-24T00:00:00.000Z"],
"timestamps": [
"2016-03-22T00:00:00.000Z",
"2016-03-23T00:00:00.000Z",
"2016-03-24T00:00:00.000Z"
],
"services": {
"mapview": [25, 22, 37],
"static": [23, 20, 34],
"tiles": [30, 39, 53]
}
}

Changelog

May 22, 2019

  • Updated the Analytics API documentation to reflect that the beta period has finished.
    • The Analytics API documentation is available at https://docs.mapbox.com/api/legacy/analytics.
    • The Analytics API is still available for use, but Mapbox will not incorporate any new features or new metrics right now.
    • Note that map views, which are returned by the API, are deprecated and are no longer used to track map usage for Mapbox products.

March 21, 2019

September 27, 2018

  • Updated the examples for the Analytics API to be more informative and user-friendly.

April 26, 2016

  • Document the maximum length of a period in the Analytics API as one year.

April 4, 2016

  • Adds documentation for the new Analytics API, which is a preview for Premium and Enterprise accounts only.