Page tree
Skip to end of metadata
Go to start of metadata

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

  • Basic Knowledge of Treasure Data.

  • Basic knowledge of Facebook Conversions and Facebook Event

  • To upload event data, you need access to one of the following on Facebook:

    • Business Manager admin

    • Admin system user who created the event set

  • Admin on the ad_account connected to the event set 
  • Facebook Pixel ID
  • Facebook Access Token

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.

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

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


6. Select Continue. 
7. Type a name for your connection.
8. 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: 

  • client_user_agent
  • action_source
  • event_source_url

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. 

  1. Complete the instructions in Creating a Destination Integration.
  2. Navigate to Data Workbench > Queries.

  3. Select a query for which you would like to export data.

  4. Run the query to validate the result set.

  5. Select Export Results.

  6. Select an existing integration authentication.
  7. Define any additional Export Results details. In your export integration content review the integration parameters.
    For example, your Export Results screen might be different, or you might not have additional details to fill out:
  8. Select Done.

  9. Run your query.

  10. Validate that your data moved to the destination you specified.

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:

  • Regular SELECT query from a table

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;

  • Query custom_data column

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.


1. Navigate to Data Workbench > Queries.
2. Create a new query or select an existing query.
3. Next to Schedule, select None.

4. In the drop-down, select one of the following schedule options.

Drop-down ValueDescription
Custom cron...

Review Custom cron... details.

@daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
@hourly (:00)Run every hour at 00 minutes.
NoneNo schedule.

Custom cron... Details

Cron Value

Description

0 * * * *

Run once an hour

0 0 * * *

Run once a day at midnight

0 0 1 * *

Run once a month at midnight on the morning of the first day of the month

""

Create a job that has no scheduled run time.

 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat

  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description

a single value, within the limits displayed above for each field.



a wildcard ‘*’ to indicate no restriction based on the field. 

‘0 0 1 * *’ configures the schedule to run at midnight (00:00) on the first day of each month.
a range ‘2-5’, indicating the range of accepted values for the field.‘0 0 1-10 * *’ configures the schedule to run at midnight (00:00) on the first 10 days of each month.
a list of comma-separated values ‘2,3,4,5’, indicating the list of accepted values for the field.

0 0 1,11,21 * *’


configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
a periodicity indicator ‘*/5’ to express how often based on the field’s valid range of values a schedule is allowed to run.

‘30 */2 1 * *’


configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. ‘0 0 */5 * *’ configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
a comma-separated list of any of the above except the ‘*’ wildcard is also supported ‘2,*/5,8-10’‘0 0 5,*/10,25 * *’configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
5.  (Optional) If you enabled the Delay execution, you can delay the start time of a query.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically imported to the specified container destination.


Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.



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



  • No labels