Skip to content
Last updated

OpenAI Ads Conversion API Export Integration

Overview

The OpenAI Ads Conversion API connector exports server-side conversion events from Treasure AI to an OpenAI Ads Pixel. It uses the OpenAI Ads Conversions API to validate, batch, and deliver standard or custom events.

The connector derives the OpenAI event data shape from each event type, normalizes and hashes restricted user identifiers, and sends a maximum of 1,000 events per request.

Prerequisites

  • Basic knowledge of Treasure AI.
  • An active OpenAI Ads account.
  • An existing OpenAI Ads web Pixel and its Pixel ID.
  • A server-side Conversions API key for the OpenAI Ads account.

Limitations and Known Issues

  • Events must have timestamps within the previous seven days and no more than ten minutes in the future.
  • Each request can contain at most 1,000 events. If OpenAI rejects one event in a request, the entire request fails.
  • Skip Invalid Records applies to records rejected by connector validation before upload. It cannot isolate one event after OpenAI rejects an uploaded batch.
  • The OpenAI API uses only the first three valid, unique values in each user-list field.
  • Raw email addresses, phone numbers, external IDs, first names, and last names are normalized and SHA-256 hashed before delivery.
  • Android GAID is supported through android_advertising_id.
  • The OpenAI documentation does not define a complete successful-delivery response schema. Confirm measurement and attribution results in OpenAI Ads Manager.

Use the Treasure Console

Create a New Connection

Create the authentication and data connection before exporting query results.

  1. Open Treasure Console.
  2. Navigate to Integrations Hub > Catalog.
  3. Search for and select OpenAI Ads Conversion API.

  1. Select Create Authentication.
  2. Enter the server-side Conversions API Key.

  1. Select Continue.
  2. Enter a name for the authentication and select Done.
  3. Select the authentication, and configure the connector parameters.

Authentication Parameters

FieldDescriptionRequired
Conversions API KeyServer-side key used only to send conversion events. The key is stored as a secret and is not displayed after creation.Yes

Define Your Query

Treasure Console supports multiple ways to export data. To export from Data Workbench:

  1. Navigate to Data Workbench > Queries.
  2. Select New Query and define your query.
  3. Select Export Results.
  4. Select an existing OpenAI Ads Conversion API authentication, or create one as described previously.
  5. Configure the export parameters.

  1. Select Done.

Connector Configuration Parameters

FieldDescriptionRequiredDefault
Pixel IDThe OpenAI Ads Pixel ID that receives conversion events.Yes
Skip Invalid RecordsWhen enabled, records that fail connector validation are counted and skipped. When disabled, the job stops on the first invalid record.Notrue

Query Data Specifications

Each query-result row represents one conversion event. Column names are trimmed and matched case-insensitively. For example, EVENT_ID, Event_Id, and event_id are equivalent.

Duplicate names that differ only by case or surrounding whitespace are invalid. Unknown columns are ignored. Columns with NULL values are skipped for that record.

Export Query Specifications

SpecificationDescription
Required ColumnsEvery record requires:
  • event_id
  • event_type
  • event_timestamp
Data ShapeThe connector derives events[].data.type from event_type. Do not include a separate data-type column.
Custom EventsWhen event_type is custom, custom_event_name is required. It must contain 1–64 letters, digits, underscores, or hyphens; begin and end with a letter or digit; and not match a standard event name.
Web EventsWhen action_source is web, source_url is required and must contain a URL scheme and host.
App Lifecycle Eventsapp_installed and app_opened require action_source to be mobile_app.
Monetary Valuesdata_currency is required when data_amount is present. For item-level values, provide content_currency[N] or an event-level data_currency when content_amount[N] is present.
Numbered User FieldsUser-list columns accept numeric suffixes, such as email, email1, and email2. OpenAI uses the first three valid, unique values in schema order and ignores additional values without rejecting the event.
Numbered Content ItemsContent columns with the same numeric suffix form one item in events[].data.contents[]. The unsuffixed columns form the first item.
Variant Dictionary Pairscontent_variant_dict_key[N] and content_variant_dict_value[N] must be provided together. They create a string map on the correspondingly suffixed content item. For example, key size and value medium produce {"size":"medium"}.
Duplicate ColumnsDuplicate column names are not allowed after trimming and case normalization.
Unknown ColumnsColumns that do not match a supported name or pattern are ignored.

Supported Event Types

event_typeDerived data.typeDescription
app_installedcustomer_actionA user installs an application. Requires action_source=mobile_app.
app_openedcustomer_actionA user opens an application. Requires action_source=mobile_app.
appointment_scheduledcustomer_actionA user books a meeting, demo, or consultation.
checkout_startedcontentsA user starts checkout.
contents_viewedcontentsA user views a product, listing, article, or other content unit.
customcustomA user-defined event that is not covered by the standard taxonomy. Requires custom_event_name.
items_addedcontentsA user adds one or more items to a cart, bundle, or selection.
lead_createdcustomer_actionA user submits a lead form or requests contact.
order_createdcontentsA purchase is completed.
page_viewedcontentsA user lands on or views an important page.
registration_completedcustomer_actionA user finishes an account or event registration flow.
subscription_createdplan_enrollmentA paid subscription starts.
trial_startedplan_enrollmentA free trial starts.

Event Fields

Column NameDestination FieldData TypeRequiredDescription
event_idevents[].idStringYesNon-empty, stable identifier. Reuse it for retries and browser/API deduplication.
event_typeevents[].typeStringYesSupported standard event name or custom. Matching is case-insensitive.
event_timestampevents[].timestamp_msLong or TimestampYesUnix time in milliseconds, or an Embulk timestamp converted to milliseconds. Must be within the allowed API window.
custom_event_nameevents[].custom_event_nameStringWhen event_type=customCustom event name. OpenAI converts the value to lowercase.
source_urlevents[].source_urlStringWhen action_source=webURL where the web conversion occurred. Nonblank values must include a scheme and host.
action_sourceevents[].action_sourceStringConditionalAccepted values: web, mobile_app, offline, physical_store, phone_call, email, or other. Matching is case-insensitive.
opprefevents[].opprefStringNoOpaque OpenAI attribution identifier. Passed through without modification.
opt_outevents[].opt_outBoolean or LongNoUse a boolean or 0/1.

Event Data Fields

Column NameDestination FieldData TypeRequiredDescription
data_amountevents[].data.amountLongNoMonetary value in the currency's standard minor unit. For example, use 4200 for USD 42.00.
data_currencyevents[].data.currencyStringWhen data_amount is presentThree-letter ISO 4217 code. The connector converts the value to uppercase.
data_plan_idevents[].data.plan_idStringNoInternal plan identifier. Available only for plan_enrollment and custom data types.

Content Item Fields

Use numeric suffixes to create multiple content items. For example, content_id1, content_name1, and content_quantity1 describe the same item.

Content fields are supported when the derived data type is contents, plan_enrollment, or custom. They are invalid for customer_action events.

Column NameDestination FieldData TypeDescription
content_id, content_id[N]events[].data.contents[].idStringInternal product, item, or content identifier.
content_group_id, content_group_id[N]events[].data.contents[].group_idStringProduct group or parent item identifier.
content_name, content_name[N]events[].data.contents[].nameStringHuman-readable item name.
content_type, content_type[N]events[].data.contents[].content_typeStringNon-empty item category, such as product, plan, or page.
content_quantity, content_quantity[N]events[].data.contents[].quantityLongItem quantity.
content_amount, content_amount[N]events[].data.contents[].amountLongItem-level monetary value in the currency's standard minor unit.
content_currency, content_currency[N]events[].data.contents[].currencyStringThree-letter ISO 4217 code. May be omitted when data_currency applies to the whole event.
content_variant_dict_key, content_variant_dict_key[N]Key in events[].data.contents[].variant_dictStringPaired with the value column for the same suffix.
content_variant_dict_value, content_variant_dict_value[N]Value in events[].data.contents[].variant_dictStringPaired with the key column for the same suffix.

Hashed User-Matching Fields

Raw values are normalized, UTF-8 encoded, and SHA-256 hashed to lowercase hexadecimal. A supplied 64-character hexadecimal hash is used as-is and converted to lowercase.

Column NameDestination FieldNormalization
email, email[N]events[].user.emails_sha256[]Trim leading and trailing whitespace and convert to lowercase.
phone_number, phone_number[N]events[].user.phone_numbers_sha256[]Remove whitespace, parentheses, periods, hyphens, a leading plus sign, and leading zeroes. The result must contain 8–15 digits.
external_id, external_id[N]events[].user.external_ids_sha256[]Trim leading and trailing whitespace. Preserve case and other characters.
first_name, first_name[N]events[].user.first_names_sha256[]Convert to lowercase and remove whitespace and ASCII punctuation. Preserve non-ASCII characters.
last_name, last_name[N]events[].user.last_names_sha256[]Convert to lowercase and remove whitespace and ASCII punctuation. Preserve non-ASCII characters.

Raw User-Matching Fields

Column NameDestination FieldData TypeNotes
region, region[N]events[].user.regions[]StringRaw region value. Maximum normalized length is 128 characters.
postal_code, postal_code[N]events[].user.postal_codes[]StringLetters, numbers, spaces, or hyphens; maximum 32 characters.
city, city[N]events[].user.cities[]StringRaw city value. Maximum normalized length is 128 characters.
country, country[N]events[].user.countries[]StringTwo-letter country code. The connector converts the value to uppercase.
android_advertising_idevents[].user.android_advertising_idStringRaw Android GAID in UUID format. Apple IDFA is not supported.
obrefevents[].user.obrefStringOpaque browser reference from the Pixel __obref cookie. Sent only when nonblank and measurement consent permits.
ip_addressevents[].user.ip_addressStringValid IPv4 or IPv6 address.
user_agentevents[].user.user_agentStringNon-empty client user-agent string.

Example Query

SELECT
  CONCAT('order-', CAST(order_id AS VARCHAR)) AS event_id,
  'order_created' AS event_type,
  CAST(TO_UNIXTIME(order_time) * 1000 AS BIGINT) AS event_timestamp,
  'web' AS action_source,
  confirmation_url AS source_url,
  total_amount_minor_units AS data_amount,
  currency_code AS data_currency,
  customer_email AS email,
  country_code AS country,
  product_id AS content_id,
  product_name AS content_name,
  'product' AS content_type,
  quantity AS content_quantity,
  'size' AS content_variant_dict_key,
  product_size AS content_variant_dict_value
FROM completed_orders

(Optional) Schedule Query Export Jobs

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

Treasure Data's scheduler feature supports periodic query execution to achieve high availability.

When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.

For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.

Scheduling your Job Using Treasure Console

  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 ValueDescription
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 Value Example Example 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.
  1. (Optional) You can delay the start time of a query by enabling the Delay execution.

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 exported to the specified destination.

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

(Optional) You can delay the start time of a query by enabling the Delay execution.

Activate a Segment in Audience Studio

You can also send segment data to the target platform by creating an activation in the Audience Studio.

  1. Navigate to Audience Studio.
  2. Select a parent segment.
  3. Open the target segment, right-mouse click, and then select Create Activation.
  4. In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
  5. Customize the activation output in the Output Mapping panel.

  • Attribute Columns
    • Select Export All Columns to export all columns without making any changes.
    • Select + Add Columns to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select + Add Columnsto add new columns for your activation output.
  • String Builder
    • + Add string to create strings for export. Select from the following values:
      • String: Choose any value; use text to create a custom value.
      • Timestamp: The date and time of the export.
      • Segment Id: The segment ID number.
      • Segment Name: The segment name.
      • Audience Id: The parent segment number.
  1. Set a Schedule.

  • Select the values to define your schedule and optionally include email notifications.
  1. Select Create.

If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.

(Optional) Configure Export Results in Workflow

Use an existing OpenAI Ads Conversion API connection in Treasure Workflow.

_export:
  td:
    database: conversions_db

+openai_conversion_export:
  td>: queries/openai_conversions.sql
  database: ${td.database}
  result_connection: openai_ads_conversions
  result_settings:
    pixel_id: "xxxxxx"
    skip_invalid_records: true

(Optional) Export Integration Using the CLI

The TD Toolbelt can export query results from the command line. Specify the existing Console authentication and connector settings with --result.

{
  "type": "openai_conversion_api",
  "conversions_api_key": "xxxxxx",
  "pixel_id": "xxxxxxx",
  "skip_invalid_records": true
}

CLI Parameters

NameDescriptionValueDefaultRequired
typeConnector type identifier.openai_conversion_apiYes
conversions_api_keyServer-side Conversions API keyStringYes
pixel_idOpenAI Ads Pixel ID receiving the events.StringYes
skip_invalid_recordsSkip locally invalid records instead of stopping the job.true / falsetrueNo

CLI Example

td query \
  --result '{"type":"openai_conversion_api","conversions_api_key":"xxxx","pixel_id":"xxxxxx","skip_invalid_records":true}' \
  -d conversions_db \
  "SELECT event_id, event_type, event_timestamp, email FROM conversion_events" \
  -T presto

Other