Articles on: Tutorials and use cases

Save new Facebook Leads Ads Leads to Google Sheets

In this example, we will create a workflow that stores the Contact information to Google Sheets when a new lead is created in Facebook Lead Ads.

Background



When leads start rolling in, you usually download them from your lead ad form in the form of a .XLS or a .CSV file and upload them to a spreadsheet, in most cases, Google Sheets.
Going through all that effort of manually downloading the leads every time you get them and exporting them to Google Sheets, It can take seemingly forever.

You have Easyflow to help you win back that time and those opportunities.

At the end of this scenario, the new leads data in your Facebook account should be added into Google Sheets, as shown in the following screenshots:





To use the predefined template please click here.
Based on your own individual needs, you can always expand and customize it.

Overview



The scenario workflow consists of these steps:

Create a workflow
Retrieve the new Facebook Leads
Transform data into flatten rows
Specify the required columns
Transform data into valid Google Sheets Format
Insert rows into Google Sheets
Add condition to prevent error in case of no data
Run the workflow

Create a workflow



Login to Easyflow portal,
Navigate to plus button from the top menu, choose the Start New Flow
Give it a title then save



Retrieve the new Facebook Leads



To retrieve the newly created Facebook leads, will use the Watch Lead operation.

In the left menu, search for Facebook Lead Ads connector, drag it into designer
Click on the Facebook Lead Ads connector,
From the right menu, select Watch Lead operation under TRIGGER section
Add a connection for your Facebook Account
Rename the connector if needed, by clicking on pencil icon on top right menu
Add your Form ID then click Apply

The state manager of this operation is configured with the key name data[*].created_time.

State Manager used to indicate the latest row retrieved from Facebook Leads, To know more about state manage, please visit, this link
The maximum rows could be retrieved per each run is 100


Since this Connector is the first one in the workflow, It should be the Starting point of the process, this will be done by right click on the connector then choose Set as starting point, It will be highlighted with green color.

Now, its time for testing the connector, click on Preview Results from the bottom menu, the data displays under the bottom menu.
Also the Schema of this connector will appear after this test in the Dynamic Content & Expressions panel on right.

To see the Connector schema, click on the four dots icon next to Form ID



Transform data into flatten rows



The Array data from the previous step, returns in nested levels, in order to prepare it a valid data for Google Sheets connector, we use the Transform connector function name Flatten rows, to know more about this connector and its rich functions, click here

Search for Transform connector, drag it into designer, click on it and select the Flatten rows function
Click on four dots icon next to Dataset and choose the Array of data then click Apply

On every test, make sure to remove the Start Value value from Facebook lead ads connector.



Specify the required columns



This step to specify which columns should be added into Google Sheets, we will remove the columns contains keys like full_name, email, ...
And will keep add the columns contains data.

Drag new Transform connector into designer, and select Select columns function
Pick the Dataset which will be the dataset of the previous step
Add the columns names with comma separator from the last result data, then Apply



Test the result by clicking on Preview Results, As you can see below, the data appears with only the selected columns, and also the Schema of this connector appears on the right menu



Transform data into valid Google Sheets Format



Simply, this function is to convert the Array of data into valid Google Sheets Format (Array of arrays)

Drag new Transform connector into designer, and select Convert array of objects to array of arrays function
Pick the Dataset which will be the dataset of the previous step, then Apply



As you can see below, the data is in a different format, and ready to be added into Google Sheets



Insert rows into Google Sheets



Search for Google sheets connector, drag it into designer, and select Add a Row function
Add a connection for your Google Sheets Account
Rename the connector if needed, by clicking on pencil icon on top right menu
Pick the Spreadsheet, by clicking on folder icon next to Spreadsheet ID, choose from right menu
Pick the Sheet, by clicking on folder icon next to Range, choose from right menu
In the Data field, is the place to add the payload data for Google Sheets which will be the dataset of the previous step, here we use toDic text function, then click Apply

The text function name toDic converts string to to a list or Dictionary. To know more about Function expressions, please click here. Also you can watch the video here

As you can see below, The Google Sheets display a successful response, and the data added into Google Sheets in the next screenshot





Add condition to prevent error in case of no data



In case Facebook lead ads does not have new leads, we add the following condition to prevent error in workflow

Click on the arrow under Facebook lead Ads connector
In the right menu, give a name for this condition
In Criteria field, Pick the Length function from Array functions and pick the Greater than function from Math Functions in the right panel, type the zero value then Save
Test the result by clicking on Preview Results



Run the workflow



In Facebook lead ads connector, remove the Start Value value.
Set the time interval in Regular Intervals (Designer -- Top menu)
The Start event on to select the connector where the event start on, in our case here the Facebook lead ads connector
Interval is the time interval, we set 1 day
Time from and Date start to specify when this interval will start working
Change the workflow status from Offline to Online
On the top right corner of designer, click on Offline grey button, then on Yes, change it! button
The workflow now will run automatically based on applied time interval

Updated on: 06/10/2022

Was this article helpful?

Share your feedback

Cancel

Thank you!