A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Facebook Insights API : Single Ad Performance Results

The facebook Ad Inisghts API provides access to your ad campaign performance statistics. Below, you'll find some basic calls which may come in handy.

you can find the Graph API Explorer here: https://developers.facebook.com/tools/explorer

API Call for a single ad: 

https://graph.facebook.com/v2.8/<YOUR AD ID>/insights?fields=actions,date_start,date_stop,impressions,spend,account_id,campaign_id,adset_id,ad_id,ad_name,buying_type,action_values,campaign_name,clicks,adset_name&time_range={"since":"2016-10-30","until":"2016-10-30"}&format=json&access_token=<YOUR ACCESS TOKEN>

Result:

{
   "data": [
      {
         "actions": [
            {
               "action_type": "comment",
               "value": "1"
            },
            {
               "action_type": "like",
               "value": "2"
            },
            {
               "action_type": "link_click",
               "value": "100"
            },
            {
               "action_type": "offsite_conversion.fb_pixel_add_to_cart",
               "value": "26"
            },
            {
               "action_type": "offsite_conversion.fb_pixel_purchase",
               "value": "2"
            },
            {
               "action_type": "offsite_conversion.fb_pixel_view_content",
               "value": "231"
            },
            {
               "action_type": "offsite_conversion.other",
               "value": "4"
            },
            {
               "action_type": "post",
               "value": "1"
            },
            {
               "action_type": "post_reaction",
               "value": "23"
            },
            {
               "action_type": "page_engagement",
               "value": "127"
            },
            {
               "action_type": "post_engagement",
               "value": "125"
            },
            {
               "action_type": "offsite_conversion",
               "value": "263"
            }
         ],
         "date_start": "2016-10-30",
         "date_stop": "2016-10-30",
         "impressions": "15568",
         "spend": "113.73",
         "account_id": "our ids",
         "campaign_id": "our ids",
         "adset_id": "our ids",
         "ad_id": "our ids",
         "ad_name": "our ad name",
         "action_values": [
            {
               "action_type": "offsite_conversion.fb_pixel_add_to_cart",
               "value": "724.53"
            },
            {
               "action_type": "offsite_conversion.fb_pixel_purchase",
               "value": "13990"
            },
            {
               "action_type": "offsite_conversion.other",
               "value": "432.4"
            },
            {
               "action_type": "offsite_conversion",
               "value": "15146.93"
            }
         ],
         "campaign_name": "m6-Single Product Styles 7/29/2016",
         "clicks": "154",
         "adset_name": "Retention Remarketing"
      }
   ],
   "paging": {
      "cursors": {
         "before": "MAZDZD",
         "after": "MAZDZD"
      }
   }
}

 

API Call for Ad Account : 

https://graph.facebook.com/v2.8/act_<account_id>/insights?fields=website_clicks,unique_social_clicks,cpc,cpm&access_token=<your access token>

Result: 

{
  "data": [
    {
      "website_clicks": "552008",
      "unique_social_clicks": "227833",
      "cpc": "0.439427",
      "cpm": "6.523525",
      "date_start": "2016-09-28",
      "date_stop": "2016-10-27"
    }
  ],
  "paging": {
    "cursors": {
      "before": "MAZDZD",
      "after": "MAZDZD"
    }
  }
}