Import Facebook Ads Data to Google Sheets via Apps Script

There are a few Google Sheets add-ons that allow exporting Facebook Ads reports to Sheets, however, some of them tend to be expensive or lack the support of some new metrics and dimensions. Today, I will walk you through how to get Facebook Ads data to Google Sheets without buying any add-ons and even schedule your reports to run on an ongoing basis.

I built the solution leveraging the Facebook Marketing API and the Google App scripts, it supports all report types and metrics. Follow the steps below to get started.

1- Create Facebook App

Navigate to Facebook for Developers, click ‘Create App’, then choose ‘Manage Business Integrations’. You will be asked to enter more info like App name and your contact details.

After you create the app, Navigate your business manager settings, and under Apps click ‘Add’ and link your new app to the business manager.

Next, click ‘Add Assets’ and select the ad accounts you’d like to pull reports for.

2- Generate your Access Token

Once you create the app, please head to Marketing API > Tools then select all the 3 token permissions then hit ‘Get Token’. Copy and save your token, you will need it in the following steps

3- Configure your Google App Script

Make a copy of this Google Sheet.

To configure the script, you need to add all your relevant details in the config tab:

ACCOUNT_ID: this should be you ad account ID

ACCESS_TOKEN: this is the access token we generated above from the Facebook App

START_DATE: this should be the start date of your report

END_DATE: this should be the end date of your report

FIELDS: This is all the fields you’d like to have in your report like impressions, clicks, cost..etc. For all reporting metrics and fields, please see here.

REPORT_LEVEL: this is the level of your report, it could be set to: ad, adset, campaign, account

Once you are done with your report configuration, you can just click run report, the data should be exported in the FB Ads raw tab.

To schedule the script, click Tools > Script Editor. Inside the script editor click ‘Triggers’ then ‘Add Trigger’:

Select from the ‘Choose which function to run’ dropdown menu downloadReport. The rest of the fields set per your needs, like the type of the time trigger and the actual time.

Please try it out and let me know if you have any questions in comments below.

Leave a Comment