This article explains how to write job results directly to your Facebook Custom Audience.
- Basic knowledge of Arm Treasure Data, including the toolbelt.
- A Facebook Ad Account.
- Authorized Treasure Data Facebook app access to own Facebook Ad Account
Step 1: Create a new connection
Go to Treasure Data Connections, search and select Facebook Custom Audience.
The following dialog will open.
Select an existing OAuth connection for Facebook, or click the link under OAuth connection to create a new connection.
Create a new OAuth connection
Log into your Facebook account:
And grant access to Treasure Data app.
You will be redirected back to Treasure Data Connections. Repeat the first step (
Create a new connection) and choose your new OAuth connection.
Step 2: Configure to output results to Facebook Custom Audience connection
Output results at top of your query editor and select your Facebook Custom Audience connection as follows:
There are several parameters to define:
- Ad Account ID (required): This is your Ad Account ID without
- API Version (optional, default
v2.11): Facebook API Version, it’s best to keep default value
- Custom Audience Name (required): Name of Custom Audience to create/update, if none exists, one will be created.
- Important note: If you have many Custom Audiences with same name as this input, the latest Custom Audience Name will be used. We recommend that you give your Custom Audience a unique name.
- Custom Audience Description (optional): Description of Custom Audience.
- Source of customer data: Specify the source of the user information collected into this file.
- No need to normalize and hash records (default
false): Indicates whether the data has already been normalized and hashed. If not, TD automatically normalizes and hashes the records.
- Initial intervals in milliseconds between retries (optional, default
60000): Interval to retry if a recoverable error occurs (in milisecond).
- Retry limit (optional, default
5): Number of retries before attempts end.
Here is a sample configuration:
Step 3: Write the Query to Populate a user list
Here is an example Audiences list before output of a query result:
From Treasure Data, run the following query with
Output results into a connection of Facebook Custom Audience (see Appendix A for more details of column naming):
SELECT email, fn, ln FROM ( VALUES ('firstname.lastname@example.org', 'John', 'Doe'), ('email@example.com', 'Isaac', 'Miceli'), ('firstname.lastname@example.org', 'Christopher', 'Agar') ) tbl (email, fn, ln)
The above query will not match any real users, it’s for demo purpose only. Also, the query requires no source table (for the ease of testing out this feature), but you still must choose a database, so pick “sample_datasets” or any other arbitrary table.
The query should complete in a few seconds. After that, check your Audience List:
Appendix A: Column naming
Output result needs to follow Facebook User schema here. Supported column names are:
- EXTERN_ID: External ID
- EMAIL: Email addresses
- PHONE: Phone numbers
- GEN: Gender
- DOBY: Birth Year
- DOBM: Birth Month
- DOBD: Birthday
- LN: Last Name
- FN: First Name
- FI: First Initial
- CT: City
- ST: States
- ZIP: Zip code
- MADID: Mobile advertiser id
- COUNTRY: Country code
If no supported column are found from query result, you receive an error.
You can use an alias in your query to rename columns of your query result, for example:
SELECT an_email_column AS EMAIL, another_phone_column AS PHONE FROM your_table;
- Note: column name is case-insensitive, for example, you can use either of
Appendix B: Data Normalization
Treasure Data result output normalizes your values automatically to follow Facebook’s normalizing rules, see here.
All values, uploaded to Facebook for matching, must be normalized with the normalizing rules of Facebook. The values will just miss chances to match if they are not normalized. If you need to normalize the data manually, apply your own normalization before attempting to output results.
The following conversion behavior is applied according to data type during result output for normalization.
- EXTERN_ID (External ID): no action needed.
- EMAIL (Email addresses): trimming leading and trailing whitespace and convert all characters to lowercase.
- PHONE (Phone numbers): removing any non-digit characters and leading zeros.
- GEN (Gender): trimming leading and trailing whitespace and convert all characters to lowercase. If the result does not match with “m” or “f”, an empty string will be used (because it’s an invalid value, there is no use to match it)
- DOBY (Birth Year): removing any non-digit characters and get first 4 digits.
- DOBM (Birth Month) and DOBD (Birthday): removing any non-digit characters and get first 2 digits.
- FN (First Name) and LN (Last Name): trimming leading and trailing whitespace and convert all characters to lowercase. Remove all punctuations. Supports special characters in UTF-8 encoding.
- FI (First Initial): apply the same as First Name and get first character.
- CT (City): convert all characters to lowercase and remove any non alphabetic (a-z) characters.
- ST (States): convert all characters to lowercase and remove any non alphanumeric (a-z and 0-9) characters.
- Note: If your value is US State, use 2-character ANSI abbreviation code, the Treasure Data platform does not cut off input string (into 2 characters), because of the need to support states outside US.
- ZIP (Zip code): trimming leading and trailing whitespace and convert all characters to lowercase, remove any non alphanumeric or whitespace from result.
- Note: If your value is US zip code, use exactly 5 digits, our the Treasure Data platform does not cut off input string (into 5 characters), because of the need to support UK zip code format.
Appendix C: Add Ad Account to Business Manager
As of Oct 15 2018, if you see the following error:
This ad account is not connected to Business Manager. To create or edit a customer file Custom Audience, your admin needs to connect this ad account to a business account.
You must add your Ad Account to a Business Manager account.
Follow these steps:
- Create Business Manager account: https://www.facebook.com/business/help/1710077379203657
- Add Ad Account: https://www.facebook.com/business/help/910137316041095
Which option to choose?
Add an Ad Account: Adding an ad account moves the account permanently into Business Manager. You must be both the owner of the ad account and an admin in Business Manager to add the ad account. When you add an ad account and it's moved into your Business Manager, you cannot reverse the action. Also note that all management of your ad account must be completed within your Business Manager profile. You can't add an ad account that's owned by another Business Manager. If you still want to work on an ad account that is owned by a different business, you can request access to it.
Request Access to an Ad Account: If you request access to an ad account in Business Manager, the admin of that Business Manager can grant you permission to work on it.
Create a new ad account: If you create a new ad account in Business Manager, it'll permanently belong to that Business Manager. When the ad account is created within Business Manager, the ad account can't be transferred to an individual owner who doesn't own a Business Manager role.