Utilising Facebook Ads data helps in marketing decision making. If you are setting up a data warehouse on BigQuery and you are advertising on Facebook it makes sense to stream all your data from Facebook Ads to BigQuery. Connecting all this data is what we cover in this article.
Overview
Facebooks Ads Insights platform provides ~300 metrics and dimensions to work with. Of course, many of these are vanity metrics, but in general advertisers want at least a subset of the available data available for data analysis.
Google BigQuery is Google’s data warehousing solution and allows to (quote from Google)
Analyze petabytes of data using ANSI SQL at blazing-fast speeds, with zero operational overhead
If you landed on this page it is probably not necessary to explain BigQuery further as chances are high that you are already using it
There are two ways of getting your data from Facebook Ads into BigQuery
Building your own data pipeline
1. Getting the data from Facebook Ads Insights
Before you can get started here you will need to have a Facebook ID with access to a Facebook Ads account (for this example).
Facebook has a well documented Marketing API with SDK’s in PHP and Python. There is an active community building and maintaining SDK’s and wrappers for R (https://github.com/daroczig/fbRads), Java Script and many more.
But let’s do a simple example here to explain how to query data from the Graph API.
The following request queries your account with an attribution window of 7 day post view for the time range between the 19/06/2020 and the 25/06/2020 and provides the fields account id, ad id, campaign id and ad-set ID on an ad-set level:
https://graph.facebook.com/v5.0/act_<YOUR ACCOUNT-ID>/insights?action_attribution_windows=%5B%227d_view%22%2C%227d_click%22%5D&time_range=%7B'since'%3A'2020-06-19'%2C'until'%3A'2020-06-25'%7D&time_increment=3&fields=account_id%2Cad_id%2Ccampaign_id%2Cadset_id%2Cdate_start%2Cdate_stop%2Caction_values&access_token=<YOUR ACCESS TOKEN>&level=adset
To modify and create your own queries I recommend using Postman and start with pasting the link above.
If you refer to the marketing API link above you can start creating your own reports easily.
2. Pushing the data into BigQuery
Before you get started here you will need to have write access to BigQuery.
The easiest way to upload data to BigQuery is the HTTP POST method. You can refer to the BigQuery API documentation for more information about it.
To get started I recommend creating an own table for the Facebook Ads data in BigQuery and then uploading the data using a Cron job every 24hours or more often (depending on the data volume and how often you run your reports).
Important note here:
The refresh token from Facebook expires, so it’s good to check logs or schedule yourself a notification in case the token expires, as this will break the data loading.
Using a connector
There are many connectors out there to help you with refreshing your BigQuery. We are one of the providers to offer such a connector and if the above instructions are too complex or you don’t have time to maintain such a solution here are the steps you would require to setup streaming using our connector. And of course we do have a free trial, so there are no commitments needed from your side.
The steps are:
1. Connect your Facebook data (or any other source you want, we support many)
2. Setup data streaming to your BigQuery Data Warehouse
Wrapping it up
As we have written in many of our blogs a lot of time data scientists and marketers is simply wasted by manual operations. Loading Facebook costs is one of them. No matter what approach you take from these two options, it will have a positive impact for your productivity immediately.