Custom audiences for Facebook Ads/ Google Ads based on Google Cloud and Retool

Andrey Osypov
Beards Analytics 🇺🇦
8 min readMar 23, 2022


The relatively new analytics tool, Google Analytics 4, has collected the best solutions on the market for marketing and product analysis. But in addition to a convenient, flexible, and customizable interface, it became possible to save raw data in Google BigQuery for free and quickly. Thanks to this, a simple opportunity to work with raw data has appeared, available to large companies and medium and small businesses.

There are many tasks for using the raw data, from reporting automation and conversion prediction to recommender systems and marketing automation. Let’s discuss the last in more detail and analyze the possibility of creating and filling a remarketing audience based on raw data stored in Google BigQuery.

Everyone knows that if we segment the audience, and for each segment, we make our advertising message that better describes the needs of this segment, the higher the resulting conversion.

The problem is that achieving a good audience segmentation, according to many parameters, technically, without automation, is rather laborious work that takes a lot of time. But by using Google Cloud and other tools, it is possible to make a simple, effective solution.

How to create a custom audience using only Google Ads/ Facebook Ads opportunities

You need to install a tag for tracking user actions for a website or an SDK to track user activity in an application to collect users in an audience.

Google Ads custom audience

Cons of working with Google Ads audience segments:

1. Audiences are not flexible. You can create audiences only for those events made in the system.

2. Lack of flexibility. After creating an audience, you cannot make changes to the audience because you must restart the data collection process.

3. Google Ads has a limit of 540 days for user participation in audience lists.

To get started with custom remarketing audiences, head to the Audience Manager in your Google Ads Tools and Instruments tab:

Google Ads Tools and Instruments tab

In Google Ads, you have the following audience source options:

  • App users
  • Website visitors
  • Customer lists
  • YouTube users
  • Adding your customer list
  • Custom combination

The most common sources of app audiences are websites and apps. You can choose one of the following options. Using specific selections, you can customize which users get funneled into your audience:

  • Visitors of a page
  • Visitors of a page who also visited another page
  • Visitors of a page who did not visit another page
  • Visitors of a page during specific dates
  • Visitors of a page with specific tags

Remarketing using the Customer List option

The customer list option works by matching the data you provide Google on your existing customers to Google accounts. You can fill out the data for customers based on email, phone, name, country, zip codes, and any additional information you might have.

Facebook Ads custom audience

Cons of working with Facebook Ads audience segments:

1. Facebook Ads has a limit of 180 days for user participation in audience lists.

2. Audiences are not flexible. You can create audiences only for those events made in the system.

3. Lack of flexibility. After creating an audience, you cannot make changes to the audience because you must restart the data collection process.

The Facebook Sources options will be easier for many people than the others, as Facebook supplies all the data you need. You won’t need to import or sync data from your site, app, or customer lists. The main, most popular data sources are web and app sources and customer list audience.

Choose a Custom Audience Source

If you are interested in making custom audiences based on your own website data, you’ll need to install a Facebook pixel.

Create a Website Custom Audience

After that, you need to choose a data source for your audience and the user’s period of participation in the audience and specify the related settings.

You also have an option to create a customer list audience. You need to click on the Customer List option on the Custom Audiences page.

Create audience from a list

In the next step, you can begin importing your customer list. You can do this in one of two ways:

  • Import a customer list from Mailchimp
  • Import a CSV or TXT file

With Mailchimp, you need to click on “Import from Mailchimp” and follow the prompts.
If you are manually importing a list as a CSV or TXT file, you’ll need to pay attention to file formatting so that Facebook can understand all the data you’re giving it.
Facebook matches users with your data through identifiers like email addresses, phone numbers, and names. The more identifiers you include, the more accurate Facebook will be targeting.
When formatting your CSV or TXT file, follow the guidelines that Facebook sets out in this document to make your list as clear as possible to Facebook’s AI.
People new to this sort of thing use Facebook’s template to avoid mistakes.

So the common problems for both Google and Facebook are:

1. Lack of flexibility once the audience is already created: it is impossible to make adjustments without re-run the audience collection.

2. Restriction on the duration of the user’s participation in the audience.

3. Restrictions on data sources for the audience. It is possible to set up audiences only for events that are created.

How to build automatization of creating custom audience with Google Cloud and Retool

We have an option to create audiences for remarketing in Google and Facebook is not very flexible and allows you to work only with those event parameters that are made as events into these advertising systems or manually upload data collected from other systems.

Since we store a lot of data from different sources in Google BigQuery, we can automatically create more flexible audiences.

For example, we can use RFM segments:

An alternative approach is to create audiences based on RFM analysis.

RFM analysis is a marketing technique used to quantitatively rank and group customers based on the recency, frequency, and monetary total of their recent transactions to identify the best customers and perform targeted digital-marketing campaigns.

We divided users into the following segments:

Users who made transactions:

  • for a period of 1 to 30 days
  • for a period of 30 to 90 days
  • for a period of 90 to 190 days
  • for the period from 180 to 359 days
  • for a period of more than 360 days

Also created segments by the number of transactions per user:

  • more than 1 transaction
  • from 2 to 4 transactions
  • from 5 to 9 transactions
  • from 10 to 19 transactions
  • over 20 transactions

Technical process

To accomplish the task of creating audiences, we combine data from GA4, Firebase, as well as data from CRM systems, using the convergence and transformation of data from various systems. We bring the data to the form in which we received segments that can later be used for creating audiences in advertising systems. In order to merge data, we combine data from GA4 / Firebase and CRM by user_id and user_pseudo_id, obtaining information about how many users made transactions in the specified time periods and the number of transactions made by a particular user.

After that, in our models, we converted them into data segments based on the number of transactions per user and the time and amount of time since the last transaction.

As a result, we get data that will be convenient to further segment into audiences that we will use in Google Ads and Facebook Ads.

SQL query constructor and execution

Using the functionality of Retool, we made a query builder, which relies on the data of the auxiliary plate. Using a nice interface, you can easily build a SQL query, which will be displayed in the appropriate field, which, if necessary, can be edited manually. It is also possible to add the received query to the BigQuery table. After executing the query, we get a table, the data of which is subsequently uploaded to custom audiences by pressing the Upload Audience button.


Authorization is done in two ways. This can be OAuth2 or authorization using the API and client configuration data (since applications created in Retool can be private)

Authorization using Service Account
Authorization using API with credentials

Tech process in general

Retool allows you to implement automation and a responsive interface using JavaScript and built-in UI components. The service also provides the ability to construct API requests and execute them without code. Communication with BigQuery is organized at the built-in Retool level, which can also connect to various databases. Direct connection to BigQuery is implemented using OAuth2. This allows you to write SQL queries and, in general, perform various data manipulations at the built-in Retool service level.

In the case with Google Ads Custom Audience, you need to create a Google Cloud Function with a server that provides an API for interacting with audiences: getting their list, creating new ones, and loading user data into existing ones. After creating such a server, you can make authorized HTTP requests to the URL address of the created cloud function.

Code part which uploads an audience.


Finally, we have tables with hashed user data, which we’re going to fill our audience with by pressing the Upload audience button. All you have to do next is to wait for the result and enjoy your audience.


Using data from GA4 / Firebase + CRM + Retool allows us to have a more flexible approach to forming audiences. Enable us to make changes to the audience, add a column or parameter to the audience, instantly get a new audience with new parameters, which you need to upload to the advertising account. Our approach allows you to be very flexible in building audiences.



Andrey Osypov
Beards Analytics 🇺🇦

Marketing/product analytics based on google cloud platform.