You can use the Facebook Conversions API to send job results (in the form of event data) from Treasure Data directly to Facebook to measure how much your Facebook ads lead to real-world outcomes, such as purchases, registrations, applications, or some other web conversions.

You can upload 1st party data as conversion data in addition to the conversion data that is ingested by Facebook Pixel as 3rd party data.

You can also upload CV logs extracted from your web server logs to the Facebook conversion API.

This topic contains:

Prerequisites

Obtain Facebook Pixel ID and Access Token


  1. Open the Business Manager dashboard, select Event Manager.

  2. Select an Event Set.

  3. Select the Settings and the Pixel ID is displayed.

  4. Select Create Access Token.
  5. Select your Pixel.
  6. Select Next.
  7. Select Generate Access Token.
  8. Copy and save the access token. For security, in our sample, we have obscured the token.
  9. Select Next.


Validate an Upload

To try an upload test, check the test code on the Test Events tab.


Use the TD Console to Create Your Connection

Create a New Connection

In Treasure Data, you must create and configure the data connection to be used during export prior to running your query. As part of the data connection, you provide authentication to access the integration.

Create a New Connection

In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration.

Open TD Console.
Navigate to Integrations Hub Catalog.
Search for and select Facebook Conversion API.

Select Create Authentication.
Type the following credentials to authenticate.
    • Pixel ID
    • Access Token


Select Continue. 
Type a name for your connection.
Select Done.



Define your Query

You need to define the column mapping in the query. The columns in the query represent Event data to be uploaded into Facebook.

Any website events shared using Conversions API require the following data parameters: 

while non-web events require only the parameter action_source.

These parameters help improve the quality of events used for ad delivery and may improve campaign performance. Additionally, for some columns, the data is hashed and normalized before being sent to Facebook.

You need at least one customer information column to configure export results. Learn more about hashing and normalization requirements and Facebook Conversions API. 

Integration Parameters for Facebook Conversions API


Parameter

Description

Test Event Code (optional)

The code to test your server events in the Test Events feature in Events Manager

Pre-hashed Columns

(Optional) Comma-separated columns already hashed using SHA256 and meet API accept requirements.

Skip Invalid Data (optional)

Use to terminate job (without revert) when invalid records are encountered. For example, a record is missing the required columns e.g. event_name, event_time...


Example Query


If you want to export data like currency that belongs to custom_data, you must set data in JSON format.

For example, the query should look similar to:

with sample_data as(
select * from (VALUES
        (1, 'USD', 104.2),
        (2, 'JPY', 10000.2),
        (3, 'USD', 103.4)
) AS t (id, currency, value))

select CAST(MAP(ARRAY['currency', 'value'], ARRAY[currency, cast(value as VARCHAR)]) as JSON) as custom_data, id from sample_dat

To query multiple values with the same name, you specify the name multiple times in the query. 

Example of a Query to Populate Events Data

From Treasure Data, run the following query with export results into a connection for Facebook Conversions:

SELECT 
  an_event_name_column AS event_name,
  an_event_time_column AS event_time,
  an_email_column AS em,
  a_country_column AS country
FROM your_table;

SELECT
  'PageView' as event_name,
  1598531676 as event_time,
  'elizabetho@fb.com' as em,
  '{"a":12, "b":"c"}' as custom_data


Integration Parameters for Facebook Conversions API


Column Name

Data Type

Required

Hash required?

Description

Server Events

event_name

String



event_time

Long



custom_data

String/JSON



Array of custom properties. See more here

event_source_url

String




opt_out

Boolean




event_id

String




action_source

String




data_processing_options

String



for LDU

data_processing_options_country

Long



for LDU

data_processing_options_state

Long



for LDU

Customer Information (at least one key provided)
em

String


Email

ph

String


Phone

ge

String


Gender

db

String


Date of birth

ln

String


Last name

fn

String


First Name

ct

String


City

st

String


State

zp

String


Zip

country

String


Country

external_id

String


External ID

client_ip_address

String

required both if using


Client IP Address

client_user_agent

String


Client user agent

fbc

String



Facebook Click ID

fbp

String



Facebook Browser ID

subscription_id

String



Subscription

lead_id

Long



Lead ID

fb_login_id

Long



FB Login ID


See more on Facebook's content pages

Optionally Schedule the Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.


Optionally Configure Export Results in Workflow

Within Treasure Workflow, you can specify the use of this data connector to export data.

Learn more at Using Workflows to Export Data with the TD Toolbelt.


timezone: UTC

_export:
  td:
    database: sample_datasets

+td-result-into-target:
  td>: queries/sample.sql
  result_connection: facebook_conversions
  result_settings:
    test_event_code: 361738844830373
    skip_invalid: false