Closed tdevitt closed 8 years ago
Hi @tdevitt ,
Based on the docs at https://developers.facebook.com/docs/marketing-api/reference/ads-insights/ you should be able to query the 'objective' field while trying to retrieve insights about campaigns. If you want to use this on the SDK level, you can directly query with hardcoded 'objective' in the code for example:
insights = campaign.get_insights(fields=[ Insights.Field.ad_id, Insights.Field.unique_clicks, 'objective'....]
for your purpose.
Can you elaborate further since objective is not defined in the sdk? I am getting "NameError: name 'objective' is not defined". I need to use account.get_insights (with level=campaign) rather than campaign.get_insights so I don't have to call get_insights for every single campaign (which causes too many API calls given large # of campaigns)
Here is my pseudocode:
account = AdAccount('act_XXXXXXXXXXXXXXXXX') params = { 'fields': [Insights.Field.account_id,Insights.Field.campaign_id,Insights.Field.date_start,Insights.Field.spend,Insights.Field.reach,Insights.Field.impressions,Insights.Field.frequency,Insights.Field.inline_link_clicks,Insights.Field.call_to_action_clicks,Insights.Field.unique_clicks,Insights.Field.actions,Insights.Field.action_values,Insights.Field.total_actions,Insights.Field.total_unique_actions,Insights.Field.ctr,Insights.Field.unique_ctr,Insights.Field.cpm,Insights.Field.cpp,Insights.Field.cost_per_unique_click,Insights.Field.campaign_name,Insights.Field.objective,], 'level': 'campaign', 'date_preset': 'last_7_days', 'time_increment': 1, }
stats = account.get_insights(params=params) print stats
Instead of using Insights.Field.objective just use 'objective' directly. That is:
'fields': [Insights.Field.account_id,Insights.Field.campaign_id,Insights.Field.date_start,Insights.Field.spend,Insights.Field.reach,Insights.Field.impressions,Insights.Field.frequency,Insights.Field.inline_link_clicks,Insights.Field.call_to_action_clicks,Insights.Field.unique_clicks,Insights.Field.actions,Insights.Field.action_values,Insights.Field.total_actions,Insights.Field.total_unique_actions,Insights.Field.ctr,Insights.Field.unique_ctr,Insights.Field.cpm,Insights.Field.cpp,Insights.Field.cost_per_unique_click,Insights.Field.campaign_name,objective,]
Just using objective throws "NameError: name 'objective' is not defined"
My library includes are as follows: from facebookads.api import FacebookAdsApi from facebookads import objects from facebookads.objects import ( AdAccount, Campaign, Insights, )
My bad. Use 'objective' with the qoutes, since it is just a string. If it still doesn't work then it is an API issue.
Ah ok thanks. It looks like it's not an available field in the API for that edge after all (even though Facebook engineer indicated it was)
It appears 'objective' is not available as a field within the sdk's Insights.Field class, although I was told by a Facebook engineer that the 'objective' field is indeed available on the Insights edge when using level=campaign.