For the Marketing API, I know that I'm able to make one call to retrieve all of the adsets from a certain account along with their insights, but am I able to specify the date_preset for the insights edge in that same call?
For example, the following gives me lifetime insights stats:
/v2.4/{accountID}/adcampaigns?fields=insights
To be clear - I know this is possible to retrieve by making separate calls for each adset id (where I know I can specify the date_preset); instead, I'd like to do this via the call where I get a long list of the ad sets plus their insights details in one go.
If you only use the Ad Insights API, you need the ads_read permission. 1. Marketing API Quickstart 2. Example Query: Campaign Statistics 1. Create App Start by creating an app with the Marketing API Quickstart which generates sample code.You can start getting insights from your Facebook Pixel or App Ads SDKs by clicking the Create Ad reports below.
Access for reporting and analytics. If you only use the Ad Insights API, you need the ads_read permission. 1. Marketing API Quickstart 2. Example Query: Campaign Statistics 1. Create App
The Insights API is available as an edge on any ads object. You can request specific fields with a comma-separated list in the fields parameters: Aggregate results at a defined object level. This automatically deduplicates data. For example, get a campaign's insights on ad level.
Note: The Facebook ads API reports all dates in the ad account's timezone. It can be useful to fetch the timezone so that you know exactly which period is being reported. Try this example on the Facebook Graph API Explorer (needs ads_management permission)
Yes this is possible using query expansion, however you probably should not do it in this anyway.
Using query expansion results in multiple requests being executed in one HTTP call, in this case one to get all the adcampaigns, and then N
requests where N
is the number of adcampaigns returned. This will in turn affect your rate limiting.
The most efficient way to request all insights for all adcampaigns (ad sets) is instead to request them at the account level, specifying aggregation level:
/v2.4/act_{ADACCOUNT_ID}/insights?date_preset=last_7_days&level=campaign
This requires just 1 request, or the number of requests to retrieve the total number of pages.
If you really want to achieve this with query expansion, you can do the following for example:
/v2.4/act_{ADACCOUNT_ID}/adcampaigns?fields=insights.date_preset(last_30_days).time_increment(all_days)
You can see the parameters to insights that would normally be query parameters of the form param_name=param_value
are now in the form of param_name(param_value)
.
To specify the date_preset , here is the correct format . Its important to use insights as edge to get the date_preset filtering .
/v2.10/act_{ADACCOUNT_ID}/insights?fields=impressions,clicks,ctr,unique_clicks,unique_ctr,spend,cpc&date_preset=last_3d
The above one is tested with latest Graph Api version(2.10) as of now . FOr more info related to the date_preset values refer to there api docs .
https://developers.facebook.com/docs/marketing-api/insights/parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With