The Query API returns pre-aggregated analytics, such as installs, clicks, and opens, grouped by the dimensions you choose. To pull large data sets, or more than 7 days in one request, use an export API such as the Cross-Events Export API instead. Every request and response field is in the API reference.
What you can do
Before you begin
| Operation | Credential | Where to send it |
|---|---|---|
| Query analytics data | Branch Key and Branch Secret | In the request body as branch_key and branch_secret |
You can send app_id instead of branch_key. To find each credential, see Credentials.
Your app needs access to the Query API, and your Branch package needs to include Data Feeds or analytics data. Without them, requests return an HTTP 403 error, so contact your Customer Success Manager. The API doesn't check user permissions, and agency data filters don't apply to it. Anyone who has your app's Branch Key and Branch Secret can query all of the app's data, so keep your Branch Secret private.
How it works
Each section covers a behavior to know before you build.
Dates and time zones
Send start_date and end_date as dates in YYYY-MM-DD format, such as 2023-05-01. Branch rejects date-times. Branch reads the dates in your app's time zone and counts events on end_date.
A query can cover at most 7 days, so end_date can be up to 6 days after start_date. For a longer period, send one request for each 7 days. The earliest start date is 2017-10-14 at midnight UTC-08:00. If your app's time zone is ahead of UTC-08:00, use 2017-10-15 or later.
Dimensions
The dimensions field is the list of event fields to group results by, and it needs at least one. Each result has your dimension values and one key named for your aggregation, such as total_count. The reference lists every dimension.
Use filters to count only some events. Each key is a dimension and each value is a list of values to match. Put ! before a key to leave out events that match.
Data sources
The data_source field is the type of event to count. The eo_click and eo_impression sources count only events that Branch records itself. The xx_click and xx_impression sources also include the clicks and impressions that ad partners report to Branch. The reference describes every data source.
Some aggregations work with only one data source. The revenue aggregations need eo_commerce_event, and the cost data source needs a cost aggregation.
Pages of results
Branch sorts the whole result and returns one page of it. Use limit to set the page size (1,000 by default, up to 50,000) and after to skip results. When there's another page, the response has a next_url in its paging object. To read that page, send the same request body to https://api2.branch.io followed by the next_url. Each page is a separate request, so it counts toward your rate limit.
If end_date is today or later, the next_url includes a query_id. Branch uses it to read later pages from the first result it saved, so counts don't change between pages. Don't change it or use it with a different query. If it isn't valid for your dates, Branch returns HTTP 400. If it expires, Branch returns HTTP 404. In either case, run the query again without it.
Days with no data
By default, Branch leaves out results whose count is 0. If you set zero_fill to true and at least one day has data, Branch adds a result with a count of 0 and null dimensions for each other day, except the last day, when granularity isn't all. If no day has data, Branch returns a result with a count of 0 for every day, or one result when granularity is all.
Fields that Branch ignores
Branch ignores any request body field that the reference doesn't list, without returning an error. That includes enable_install_recalculation.
Errors
Branch returns a 503 error when the API is temporarily unavailable, and you can retry in a few minutes. A 400 error means Branch rejected the request. The body says why, but its shape depends on where Branch rejected the request. Credential and JSON errors have an error object with a code and a message. See Errors for the common messages. The Query API also returns a 400 when a query matches 50,000 rows or more, so use fewer dimensions, a shorter time range, or filters.
Limits
Branch limits requests for each app. Some apps have higher or lower limits. A request over a limit returns HTTP 429, and the response might not be JSON. See Rate limits for how Branch counts requests.
| Limit | Value |
|---|---|
| Requests per second | 5 |
| Requests per minute | 20 |
| Requests per hour | 150 |
- Rows: a query that matches 50,000 rows or more returns an HTTP 400 error instead of results.
- Date range: a query can cover up to 7 days.
- Request size: a request body can be up to 5 MB.
- Timeout: a query that takes too long returns an HTTP 500 error, or sometimes an HTTP 504 error. Use a shorter date range or filters that match less data.
Examples
These examples show common tasks from start to finish.
Count installs by day
Count installs for each day, split by whether the install is attributed. The query returns 5 results. See Query analytics data in the reference.
curl -X POST "https://api2.branch.io/v1/query/analytics?limit=5" -H "Content-Type: application/json" \
-d '{
"branch_key": "key_live_xxxx",
"branch_secret": "secret_live_xxxx",
"start_date": "2022-03-01",
"end_date": "2022-03-07",
"data_source": "eo_install",
"aggregation": "total_count",
"granularity": "day",
"dimensions": ["attributed"]
}'{
"results": [
{ "result": { "attributed": "false", "total_count": 44 }, "timestamp": "2022-03-05T00:00:00.000-08:00" },
{ "result": { "attributed": "false", "total_count": 23 }, "timestamp": "2022-03-07T00:00:00.000-08:00" },
{ "result": { "attributed": "true", "total_count": 14 }, "timestamp": "2022-03-05T00:00:00.000-08:00" },
{ "result": { "attributed": "false", "total_count": 12 }, "timestamp": "2022-03-03T00:00:00.000-08:00" },
{ "result": { "attributed": "false", "total_count": 10 }, "timestamp": "2022-03-02T00:00:00.000-08:00" }
],
"paging": {
"next_url": "/v1/query/analytics?limit=5&after=5",
"total_count": 13
}
}Count installs by operating system
Count installs for each day, split by the operating system of the device. Branch sorts the results by total_count, highest first. See Query analytics data in the reference.
curl -X POST "https://api2.branch.io/v1/query/analytics?limit=5" -H "Content-Type: application/json" \
-d '{
"branch_key": "key_live_xxxx",
"branch_secret": "secret_live_xxxx",
"start_date": "2017-12-12",
"end_date": "2017-12-18",
"data_source": "eo_install",
"aggregation": "total_count",
"granularity": "day",
"dimensions": ["user_data_os"]
}'{
"results": [
{ "result": { "user_data_os": "ANDROID", "total_count": 246 }, "timestamp": "2017-12-16T00:00:00.000-08:00" },
{ "result": { "user_data_os": "ANDROID", "total_count": 194 }, "timestamp": "2017-12-17T00:00:00.000-08:00" },
{ "result": { "user_data_os": "IOS", "total_count": 191 }, "timestamp": "2017-12-17T00:00:00.000-08:00" },
{ "result": { "user_data_os": "ANDROID", "total_count": 144 }, "timestamp": "2017-12-18T00:00:00.000-08:00" },
{ "result": { "user_data_os": "IOS", "total_count": 142 }, "timestamp": "2017-12-18T00:00:00.000-08:00" }
],
"paging": {
"next_url": "/v1/query/analytics?limit=5&after=5",
"total_count": 14
}
}Count unique clicks by campaign without Deepviews
Count unique clicks for each campaign, and leave out clicks on Deepviews. Branch sorts the results by unique_count, highest first. See Query analytics data in the reference.
curl -X POST "https://api2.branch.io/v1/query/analytics?limit=3" -H "Content-Type: application/json" \
-d '{
"branch_key": "key_live_xxxx",
"branch_secret": "secret_live_xxxx",
"start_date": "2017-12-12",
"end_date": "2017-12-18",
"data_source": "eo_click",
"aggregation": "unique_count",
"dimensions": [
"last_attributed_touch_data_tilde_feature",
"last_attributed_touch_data_tilde_channel",
"last_attributed_touch_data_tilde_campaign"
],
"filters": {
"!last_attributed_touch_data_plus_current_feature": ["MOBILE_DEEPVIEWS", "DESKTOP_DEEPVIEWS"]
},
"ordered_by": "unique_count",
"ordered": "descending"
}'{
"results": [
{
"timestamp": "2017-12-12T00:00:00.000-08:00",
"result": {
"last_attributed_touch_data_tilde_feature": "paid advertising",
"last_attributed_touch_data_tilde_channel": "ads",
"last_attributed_touch_data_tilde_campaign": "Xmas",
"unique_count": 750
}
},
{
"timestamp": "2017-12-12T00:00:00.000-08:00",
"result": {
"last_attributed_touch_data_tilde_feature": "paid advertising",
"last_attributed_touch_data_tilde_channel": "taptica#1",
"last_attributed_touch_data_tilde_campaign": "taptica#1",
"unique_count": 723
}
},
{
"timestamp": "2017-12-12T00:00:00.000-08:00",
"result": {
"last_attributed_touch_data_tilde_feature": "paid advertising",
"last_attributed_touch_data_tilde_channel": "Apple App Store",
"last_attributed_touch_data_tilde_campaign": null,
"unique_count": 432
}
}
],
"paging": {
"next_url": "/v1/query/analytics?limit=3&after=5",
"total_count": 143
}
}