Leveraging the data provided by Facebook Ads Insights offers businesses a great way to measure their target audiences. However, transferring the massive amounts of Facebook Ads data to Google BigQuery is no easy feat. If you’re looking to do just that, then you’re in luck. In this article, we’ll be taking a closer look at how you can migrate data from Facebook Ads to BigQuery.   

Get Real-time Streams of Your Facebook Ad Statistics

You can easily create a real-time data infrastructure for extracting data from Facebook Ads and loading them into a Data Warehouse repository. You can achieve this by subscribing to real-time updates to receive API updates with Webhooks. Armed with the proper infrastructure, you can have an almost real-time data feed into your repository and ensure that it will always be up to date with the latest bit of data. Facebook Ads is a real-time bidding system where advertisers can compete to showcase their advertising material.

Solve your data replication problems with Hevo’s reliable, no-code, automated pipelines with 150+ connectors.
Get your free trial right away!

Facebook Ads imparts a very rich API that gives you the opportunity to get extremely granular data regarding your accounting activities and leverage it for reporting and analytic purposes. This richness will cost you, though many complex resources must be tackled with an equally intricate protocol.

Reliably integrate data with Hevo’s Fully Automated No Code Data Pipeline

If yours anything like the 1000+ data-driven companies that use Hevo, more than 70% of the business apps you use are SaaS applications Integrating the data from these sources in a timely way is crucial to fuel analytics and the decisions that are taken from it. But given how fast API endpoints etc can change, creating and managing these pipelines can be a soul-sucking exercise.

Hevo’s no-code data pipeline platform lets you connect over 150+ data sources in a matter of minutes to deliver data in near real-time to your warehouse. What’s more, the in-built transformation capabilities and the intuitive UI means even non-engineers can set up pipelines and achieve analytics-ready data in minutes. 

All of this combined with transparent pricing and 24×7 support makes us the most loved data pipeline software in terms of user reviews.

Take our 14-day free trial to experience a better way to manage data pipelines.

Get started for Free with Hevo!

Prepare Your Facebook Ads Data for Google BigQuery

Before diving into the methods that can be deployed to set up a connection from Facebook Ads to BigQuery, you should ensure that it is furnished in an appropriate format. For instance, if the API you pull data from returns an XML file, you would first have to transform it to a serialization that can be understood by BigQuery. As of now, the following two data formats are supported:

  • JSON
  • CSV

Apart from this, you also need to ensure that the data types you leverage are the ones supported by Google BigQuery, which are as follows:


Let us look into both approaches one by one.

Understanding the Methods to Connect Facebook Ads to BigQuery

These are the methods you can use to move data from Facebook Ads to BigQuery:

Method 1: Using Hevo to Move Data from Facebook Ads to BigQuery

Facebook Ads to bigquery: Hevo Banner
Image Source

Hevo can help you load data in two simple steps:

  • Step 1: Configure your Facebook Ads as a source by providing the Pipeline Name, authorized account, report type, aggregation level, aggregation time, breakdowns, historical sync duration, and key fields.
Facebook Ads to BigQuery: Source Configuration
Image Source
  • Step 2: Connect to your BigQuery account and start moving your data from Facebook Ads to BigQuery by providing the project ID, dataset ID, Data Warehouse name, GCS bucket.
Facebook Ads to bigquery: Destination Configuration
Image Source
Deliver smarter, faster insights with your unified data

Using manual scripts and custom code to move data into the warehouse is cumbersome. Changing API endpoints and limits, ad-hoc data preparation and inconsistent schema makes maintaining such a system a nightmare. Hevo’s reliable no-code data pipeline platform enables you to set up zero-maintenance data pipelines that just work.

Wide Range of Connectors – Instantly connect and read data from 150+ data sources including SaaS apps and databases, and precisely control pipeline schedules down to the minute.

In-built Transformations – Format your data on the fly with Hevo’s preload transformations using either the drag-and-drop interface, or our nifty python interface. Generate analysis-ready data in your warehouse using Hevo’s Postload Transformation 

Near Real-Time Replication – Get access to near real-time replication for all database sources with log based replication. For SaaS applications, near real time replication is subject to API limits.   

Auto-Schema Management – Correcting improper schema after the data is loaded into your warehouse is challenging. Hevo automatically maps source schema with destination warehouse so that you don’t face the pain of schema errors.

Transparent Pricing – Say goodbye to complex and hidden pricing models. Hevo’s Transparent Pricing brings complete visibility to your ELT spend. Choose a plan based on your business needs. Stay in control with spend alerts and configurable credit limits for unforeseen spikes in data flow.

24×7 Customer Support – With Hevo you get more than just a platform, you get a partner for your pipelines. Discover peace with round the clock “Live Chat” within the platform. What’s more, you get 24×7 support even during the 14-day free trial.

Security – Discover peace with end-to-end encryption and compliance with all major security certifications including HIPAA, GDPR, SOC-2.

Get started for Free with Hevo!

Method 2: Writing Custom Scripts to Move Data from Facebook Ads to BigQuery

Migrating data from Facebook Ads Insights to Google BigQuery essentially involves two key steps: 

Step 1: Pulling Data from Facebook

Put simply, pulling data from Facebook involves downloading the relevant Ads Insights data, which can be used for a variety of business purposes. Currently, there are two main methods for users to pull data from Facebook: 

  • Through APIs.
  • Through Real-time streams.
Method 1: Through APIs

Users can access Facebook’s APIs through the different SDKs offered by the platform. While Python and PHP are the main languages supported by Facebook, it’s easy to find community-supported SDKs for languages such as JavaScript, R, and Ruby.

What’s more, the Facebook Marketing API is relatively easy to use – which is why it can be harnessed to execute requests that direct to specific endpoints. Also, since the Facebook Marketing API is a RESTful API, you can interact with it via your favorite framework or language.

Like everything else Facebook-related, Ads and statistics data form part of and can be acquired through the Graph API, and any requests for statistics specific to particular ads can be sent to Facebook Insights. In turn, Insights will reply to such requests with more information on the queried ad object. 

If the above seems overwhelming, there’s no need to worry and we’ll be taking a look at an example to help simplify things. Suppose you want to extract all stats relevant to your account. This can be done by executing the following simple request through curl: 

curl -F 'level=campaign' -F 'fields=[]' -F 'access_token=<ACCESS_TOKEN>' 
curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002 
curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002/insights

Once it’s ready, the data you’ve requested will then be returned in either CSV or XLS format and be able to access it via a URL such as the one below:

Method 2: Through Real-time Streams

You can also pull data from Facebook by creating a real-time data substructure and can even load your data into the data warehouse. All you need to do to achieve all this and to receive API updates is to subscribe to real-time updates.

Using the right substructure, you’ll be able to stream an almost real-time data feed to your database, and by doing so you’ll be ensuring that you’ll be kept up-to-date with the latest data. 

Facebook Ads boasts a tremendously rich API that offers users the opportunity to extract even the smallest portions of data regarding accounts and target audience activities. More importantly, however, is that all of this real-time data can be used for analytics and reporting purposes. 

However, there’s a minor consideration that needs to be mentioned. It’s no secret that these resources become more complex as they continue to grow, meaning you’ll need a complex protocol to handle them and it’s worth keeping this in mind as the volume of your data grows with each passing day.

Moving on, the data that you pull from Facebook can be in one of a plethora of different formats, yet BigQuery isn’t compatible with all of them. This means that it’s in your best interest to convert data into a format supported by BigQuery after you’ve pulled it from Facebook. 

For example, if you pull XML data, then you’ll need to convert it into any of the following data formats: 

  1. CSV
  2. JSON.

You should also make sure that BigQuery supports the BigQuery data types you’re using. BigQuery currently supports the following data types: 


Please refer to Google’s documentation on preparing data for BigQuery, to learn more.

Now that you’ve understood the different data formats and types supported by  BigQuery, it’s time to learn how to pull data from Facebook.

Prerequisites for Loading Data Into BigQuery

You’ll need to use a data source supported by BigQuery to load data from Facebook Ads. These include::

  1. Google Cloud Storage
  2. Using a POST request to send data directly to BigQuery
  3. Google Cloud Datastore
Download the Cheatsheet on How to Set Up High-performance ETL to BigQuery
Download the Cheatsheet on How to Set Up High-performance ETL to BigQuery
Download the Cheatsheet on How to Set Up High-performance ETL to BigQuery
Learn the best practices and considerations for setting up high-performance ETL to BigQuery

Step 2: Loading Data Into BigQuery

If you opt to use Google Cloud Storage to load data from Facebook Ads into BigQuery, then you’ll need to first load the data into Google Cloud Storage. This can be done in one of a few ways. 

First and foremost, this can be done directly through the console. Alternatively, you can post data with the help of the JSON API. One thing to note here is that APIs play a crucial role, both in pulling data from Facebook Ads and loading data into Bigquery.

Perhaps the simplest way to load data into BigQuery is by requesting HTTP POST using tools such as curl. Should you decide to go this route,  your POST request should look something like this:

POST /upload/storage/v1/b/myBucket/o?uploadType=media&name= TEST HTTP/1.1 
Host: www.googleapis.com Content-Type: application/text 
Content-Length: number_of_bytes_in_file 
Authorization: Bearer your_auth_token your Facebook Ads data

And if you enter everything correctly you’ll get a response that looks like this:

HTTP/1.1 200 Content-Type: application/json { "name": "TEST" }

Keep in mind, however, that tools like curl are only useful for testing purposes. So, you’ll need to write specific codes to send data to Google if you want to automate the data loading process.

This can be done in one of the following languages when using the Google App Engine to write codes:

Apart from coding for the Google App Engine, the above languages can even be used to access Google Cloud Storage. 

 Once you’ve imported your extracted data into Google Cloud Storage, you’ll need to create and run a LoadJob, which directs to the data that needs to be imported from the cloud and will ultimately load the data into BigQuery. This works by specifying source URLs that point to the queried objects.  

This method makes use of POST requests for storing data in the Google Cloud Storage API, from where it will load the data into BigQuery.

Another method to accomplish this is by posting a direct HTTP POST request to BigQuery with the data you’d like to query. While this method is very similar to loading data through the JSON API, it differs by using specific BigQuery end-points to load data directly. Furthermore, the interaction is quite simple and can be carried out via either the framework or the HTTP client library of your preferred language. 

Limitations of using Custom Scripts to Connect Facebook Ads to BigQuery

Building a custom code for transfer data from Facebook Ads to Google BigQuery may appear to be a practically sound arrangement. However, this approach comes with some limitations too.

  • Code Maintenance: Since you are building the code yourself, you would need to monitor and maintain it too. On the off chance that Facebook refreshes its API or the API sends a field with a datatype which your code doesn’t understand, you would need to have resources that can handle these ad-hoc requests.
  • Data Consistency: You additionally will need to set up a data validation system in place to ensure that there is no data leakage in the infrastructure.
  • Real-time Data: The above approach can help you move data one time from Facebook Ads to BigQuery. If you are looking to analyze data in real-time, you will need to deploy additional code on top of this.
  • Data Transformation Capabilities: Often, there will arise a need for you to transform the data received from Facebook before analyzing it. Eg: When running ads across different geographies globally, you will want to convert the timezones and currencies from your raw data and bring them to a standard format. This would require extra effort.

Utilizing a Data Integration stage like Hevo frees you of the above constraints.

Method 3: Manual Upload of Data from Facebook Ads to BigQuery

This is an affordable solution for moving data from Facebook Ads to BigQuery. These are the steps that you can carry out to manually load data from Facebook Ads to BigQuery:

  • Step 1: Create a Google Cloud project, after which you will be taken to a “Basic Checklist”. Next, navigate to Google BigQuery and look for your new project.
  • Step 2: Log In to Facebook Ads Manager and navigate to the data you wish to query in Google BigQuery. If you need daily data, you need to segment your reports by day.
  • Step 3: Download the data by selecting “Reports” and then click on “Export Table Data”. Export your data as a .csv file and save it on your PC.
Facebook Ads to BigQuery: Export Table Data
Image Source
  • Step 4: Navigate back to Google BigQuery and ensure that your project is selected at the top of the screen. Click on your project ID in the left-hand navigation and click on “+ Create Dataset”
Facebook Ads to bigquery : Create Dataset
Image Source
  • Step 5: Provide a name for your dataset and ensure that an encryption method is set. Click on “Create Dataset” followed by clicking on the name of your new dataset in the left-hand navigation. Next, click on “Create Table” to finish this step.
Facebook Ads to bigquery : Create Table
Image Source
  • Step 6: Go to the source section, then create your table from the Upload option. Find your Facebook Ads report that you saved to your PC and choose file format as CSV. In the destination section, select “Search for a project”. Next, find your project name from the dropdown list. Select your dataset name and the name of the table.
  • Step 7: Go to the schema section and click on the checkbox to allow BigQuery to either auto-detect a schema or click on “Edit as Text” to manually name schema, set mode, and type.
Facebook Ads to BigQuery: Enter Details for Table Creation
Image Source
  • Step 8: Go to the Partition and Cluster Settings section and choose “Partition by Ingestion Time” or “No partitioning” based on your needs. Partitioning splits your table into smaller segments that allow smaller sections of data to be queried quickly. Next, navigate to Advanced options and set the field delimiter like a comma.
Facebook Ads to BigQuery: Advanced Options
Image Source
  • Step 9: Click “Create table”. Your Data Warehouse will begin to populate with Facebook Ads data. You can check your Job History for the status of your data load. Navigate to Google BigQuery and click on your dataset ID.
  • Step 10: You can write SQL queries against your Facebook data in Google BigQuery, or export your data to Google Data Studio along with other third-party tools for further analysis. You can repeat this process for all additional Facebook data sets that you wish to upload and to ensure the availability of fresh data.

What is Facebook Ads?

Facebook Ads to bigquery: Facebook Ads Logo
Image Source

Facebook Ads Insights is without a doubt one of the most useful tools available to you when setting up Facebook ads. Put simply, Ads Insights allows you to collect aggregate information on your target audiences based on factors such as demographics, location, purchase behavior, and more.

Facebook Ads are paid ads like Google Ads but show up only on Facebook. These ads can be displayed across various places like:

  • Video Feeds
  • Facebook Marketplace
  • Instagram Newsfeed
  • Facebook Newsfeed
  • Right-Hand Column
  • Messenger Inbox

Facebook Ads are more suitable for reaching out to consumers who are near the top of the funnel.

What is BigQuery?

Facebook Ads to bigquery: BigQuery Logo
Image Source

Google BigQuery, on the other hand, is a data warehouse that allows you to execute super-fast SQL queries. Its cloud-based, serverless infrastructure works hand in hand with Google Storage to help users to load large datasets. 

A few key features of Google BigQuery are as follows:

  • Easy to Use: Using BigQuery only requires you to load your data and then pay for what you use. 
  • Architecture: BigQuery has a distributed architecture, so you do not have to manage to compute clusters manually as Google manages these resources dynamically. 
  • Fast Insights: BigQuery can integrate seamlessly with many popular front-end analytics tools like Tableau and Data Studio. This makes it very easy to generate insights from your data.
  • Managed Service: Google handles backend configuration and performance tuning. This makes it easier to use than other data warehouses where you may be required to perform these tasks.


This blog talks about the 3 different methods you can use to move data from Facebook Ads to BigQuery in a seamless fashion.

Hevo will take care of consistently moving data from Facebook Ads to BigQuery in real-time and for free. In addition to overcoming the above limitations and bringing data from Facebook Ads, Hevo can help you move data from 150+ data sources – Marketing and Sales Platforms (Salesforce, Google Ads, HubSpot, Twitter Ads), Support Applications (Intercom, Freshdesk, Zendesk), Databases (MySQL, MongoDB, PostgreSQL) and more.

Visit our Website to Explore Hevo

Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand.

On a concluding note, we’ve covered both the approaches and shared the necessary knowledge to move data from Facebook Ads to Google BigQuery. It’s up to you now to determine the best way that suits your use case. 

Do you have any experience in working with moving data from Facebook Ads to BigQuery? Let us know in the comments section below.

No-code Data Pipeline for BigQuery