Analytics
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
Returns the request counts per day for the given resource, in the specified period of time.
Required parameters | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
resource_type | The resource being requested. Valid resource types are: accounts , tokens , tilesets or styles . | ||||||||||
username | The username of the account that owns the resource. | ||||||||||
id | The ID of the resource.
|
You can further refine the results from this endpoint with the optional period
query parameter:
Optional parameters | Description |
---|---|
period | Two 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:
Property | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
timestamps | An array of dates as ISO formatted strings for each day included in the response. | ||||||||||
period | A two-element array with the start and end dates of the response period as ISO formatted strings. | ||||||||||
services | An 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:
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
- Updated the Analytics API documentation to show that the API is in public beta.
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.