You can write job results in Arm Treasure Data directly to your Facebook Custom Audience.
When uploading or creating a Custom Audience, Facebook requires that you accept Custom Audience Terms. You see a notification when you export an ad object targeting a customer file or export value-based Custom Audiences. You receive subsequent reminders about Facebook Custom Audience terms every 90 days.
For sample workflows on how to write job results to Facebook Custom Audience, view Treasure Boxes.
- Basic knowledge of Arm Treasure Data, including the toolbelt.
- A Facebook Ad Account.
- Authorized Treasure Data Facebook app access to own Facebook Ad Account
Create a new connection
Visit the Treasure Data Catalog, search and select Facebook Custom Audience.
The following dialog opens.
Select an existing OAuth connection for Facebook, or click the Click here 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 TD Console. Repeat the first step (Create a new connection) and choose your new OAuth connection.
Name your new Facebook Custom Audience connection. Click Done.
Configure Export Results in Your Data Connection
In this step you create or reuse a query. In the query, you configure the data connection.
Note: Sometimes you need to define the column mapping in the query.
Configure the Connection by Specifying the Parameters
Go to the TD console. Go to Data Workbench > Queries. Access the query that you plan to use to export data.
Click Export Results located at top of your query editor.
The Choose Integration dialog opens. You have two options when selecting a connection to use to export the results:
1. Use an existing connection.
Type the connection name in the search box to filter and select your connection.
2. Create a new Facebook Custom Connection.
Fill in the field values to create the new connection.
Enter the required credentials for your new Facebook Custom Audience connection.
You see the following pane:
Set the following parameters:
- Ad Account ID (required): This is your Ad Account ID without
- 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.
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 ('email@example.com', 'John', 'Doe'), ('firstname.lastname@example.org', 'Isaac', 'Miceli'), ('email@example.com', '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 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 is used (because it’s an invalid value, it is futile to attempt a match)
- 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, the Treasure Data platform does not cut off input string (into 5 characters), because of the need to support UK zip code format.
If you choose to prepare your data (normalization and hashing) before sending to the connector, you can set the option No need to normalize and hash records to True
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.