Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to specify date_preset with insights edge in Facebook Ads API?

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.

like image 657
Loren Appin Avatar asked Jul 15 '15 06:07

Loren Appin


People also ask

How to get insights from Facebook ads using the marketing API?

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.

What permissions do I need to use ad insights API?

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

How do I use the insights API?

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.

What does the Facebook Ads API Report about the timezone?

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)


2 Answers

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).

like image 171
Paul Bain Avatar answered Sep 19 '22 17:09

Paul Bain


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

like image 30
TheVigilant Avatar answered Sep 20 '22 17:09

TheVigilant