Visit our new documentation site! This documentation page is no longer updated.

Writing Job Results into Instagram Custom Audience

You can write job results directly to your Instagram Custom Audience. Instagram is part of Facebook so these instructions include some references to Facebook technical specifications.

Table of Contents

Prerequisites

  • Basic knowledge of Treasure Data, including the toolbelt
  • An Instagram Ad Account
  • A Business Profile for Instagram
  • Authorized Treasure Data Facebook application access to your own Instagram Ad Account

Step 1: Create a new connection

Go to Treasure Data Connections. Locate and select Instagram Custom Audience.



The following dialog will open.



Select an existing OAuth connection for Instagram, 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.



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 Instagram Custom Audience connection

Check theOutput results box at top of your query editor and select your Instagram Custom Audience connection as follows:

There are several parameters to complete:

  • Ad Account ID (required): This is your Ad Account ID without act_ prefix
  • API Version (optional, default v2.11): Facebook/Instagram 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 one will be used. We recommend to give your Custom Audience a unique name.
  • Custom Audience Description (optional): Description of Custom Audience.
  • 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 happens (in millisecond).
  • Retry limit (optional, default 5): Number of retries before it gives up.

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 Instagram Custom Audience (see Appendix A for more details of column naming):

SELECT email, fn, ln FROM (
  VALUES ('demo1@example.com', 'John', 'Doe'),
         ('demo2@example.com', 'Isaac', 'Miceli'),
         ('demo3@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:

Step 4: Edit Ad Placement

After you output your user list into an Instagram Custom Audience, you can go to Facebook/Instagram Ads Manager and edit the ad placement. By default, Facebook will choose to display within Instagram Ads

Automatic Placements (default)

Edit Placement

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 is found from query result, an error is thrown.

You can use 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, ie. you can use either of email or EMAIL.

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 behaviour 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.

Last modified: Mar 14 2018 12:51:09 UTC

If this article is incorrect or outdated, or omits critical information, let us know. For all other issues, access our support channels.