Analytics

warning
Note

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 that you 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
/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 map 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
"
Endpoint support

Mapbox wrapper libraries help you integrate Mapbox APIs into your existing application. The following SDK supports this endpoint:

See the SDK documentation for details and examples of how to use the relevant methods to query this endpoint.

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 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 ]
    }
}