Skip to content
Last updated

Amazon Ads Export Integration

Amazon Ads is an advertising service that enables users to promote their products and services on Amazon's platforms.

The Amazon Ads Export integration supports TD users as they manage their audience and audience records on Amazon Ads platforms like Amazon Marketing Cloud (AMC) and Amazon Demand-Side Platform (DSP).

Prerequisites

  • Basic Knowledge of Treasure Data
  • Basic knowledge of the Amazon Ad platforms AMC and DSP

Requirements and Limitations

  • The Audience ID used in the Amazon Ads API is not the Audience ID displayed under DSP Advertiser account. The Audience ID that you need for the API is displayed when a new audience is created, and it should stored in a secure location.

Static IP Address of Treasure Data Integration

If your security policy requires IP whitelisting, you must add Treasure Data's IP addresses to your allowlist to ensure a successful connection.

Please find the complete list of static IP addresses, organized by region, at the following link:
https://api-docs.treasuredata.com/en/overview/ip-addresses-integrations-result-workers/

Use the TD Console to Create a Connection

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

Create a New Authentication

Your first step is to create a new authentication with a set of credentials.

  1. Select Integrations Hub.
  2. Select Catalog.

3. Search for your Amazon Ads in the Catalog; hover your mouse over the icon and select Create Authentication.

The New Authentication modal displays. 4. Below the OAuth connection field, select the Click here link. 5. Log in to your Amazon account to approve OAuth access. 6. On the New Authentication modal, provide this information and select Continue. 7. Enter a name for the authentication, and select Done.

Getting the Authentication ID

If you want to use this authentication with TD APIs or with the TD Toolbelt, you will need to get it's Authentication ID. To get the Authentication ID:

  1. Navigate to Integrations Hub > Authentications.
  2. Select the integration you want to use. The Edit Authentication modal displays.
  3. In the browser address bar, at the end of the URL, note the Authentication ID. In this example the ID is 2881.

Define your Query

  1. Navigate to Data Workbench > Queries.
  2. Select New Query.
  3. From the table drop-down menu, select the database you want to query.
  4. Enter your query.

Here is a sample query:

SELECT   
  usr_firstname  AS firstname,   
  usr_address    AS address,   
  usr_phone      AS phone,   
  usr_city       AS city,   
  usr_state      AS state,   
  usr_postalcode AS postal,   
  usr_email      AS email,          -- required   
  usr_lastname   AS lastname,   
  usr_country    AS countrycode,   
  ext_id         AS externaluserid  -- required   
FROM   
  mytable

Here are the required fields for the query:

FieldRequiredHash Required
firstnameYes
addressYes
phoneYes
cityYes
stateYes
postalYes
emailYesYes
lastnameYes
countrycode
externalUserIdYes

Specify the Result Export Target

There are two ways to export data to Amazon Ads:

  • Create a new audience
  • Update existing audience

Create a New Audience and Export Hashed Records.

This is an example of how to create an audience on AMC and DSP and then add users to that audience.

  1. Using the TD Console, perform steps 1-4 from the "Define your Query" section above.
  2. Select Export Results.
  3. Select the integration you created for Amazon Ads.

The Export Results modal displays.

4. In the Action field, ensure that Create is selected. 5. Enter your information into the remaining fields.

FieldDescriptionNote
Audience FeeCurrency and cost per impression (CPM). Required. Format:  currrency:cpm in cents Example: USD:1Currency should align with the marketplace of the advertiser.
Time to liveSpecify time the audience time to live in seconds.Required.Value needs to be greater than 0 and less than 34300800.Default: 34300800
Country codeSpecify country codes where the audience data collected from. Required.See full list of ISO 3166-2 country codes.
Wait for next statusSelect the "Wait for upload next status" check box, and then, in the "Max waiting time" field specify in minutes how long the job should wait for Amazon services to signal the upload status. Optional.
  1. Select Done.

Example Result

************* REPORT *************2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total records: 382024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total batches: 12024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total skipped records: 02024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): ************* UPLOAD STATUS 
*************2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total completed batches: 1/12024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Total uploaded records but invalid: 02024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): ************* AUDIENCE INFO *************
2024-05-29 04:40:12.080 +0000 [INFO] (0035:task-0000): Audience ID: 361054992504331xxx2024-05-29 04:40:12.081 +0000 [INFO] (0001:transaction): {done:  1 / 1, running: 0}2024-05-29 04:40:12.082 +0000 [INFO] (0001:transaction): Incremental job, setting last_path to [job_2167618832_result]2024-05-29 04:40:12.280 +0000 [INFO] (pool-10-thread-1): Saving all buffers2024-05-29 04:40:12.280 +0000 [INFO] (pool-10-thread-1): Closing buffers2024-05-29 04:40:14.281 +0000 [INFO] (main): Stopped sending metrics

As AudienceID is only returned during the audience creation process, you will need to securely store the ID for later use. The Audience ID can be found at the end of job logs.

Tip: If the audience has been created under "AMC and DSP" and the wish is continuously upload new records to that audience. You can schedule the job in this use case to run repeatedly. No need any modifications. Otherwise, follow next use case. |

Update an Existing Audience

This is an example of how to update an audience on AMC and DSP.

Rather than create a new query, it is easier to clone a query and make modifications to the existing configuration.

  1. Using the TD Console, perform steps 1-4 from the "Define your Query" section above.
  2. Select Export Results.
  3. Select the integration you created for Amazon Ads.

The Export Results modal displays.

4. In the Action field, ensure that Updateis selected. 5. Enter your information into the remaining fields.

FieldDescriptionNote
Upload ModeSelect either - Append—appends new records to an existing audience. - Delete—deletes matching records in an existing audience.The deletion process is handled by Amazon.
TargetUser can select between: - AMC—audience created on AMC, and query records uploaded to AMC. - AMC and DSP— records uploaded to AMC and then synced to DSP.
DSP Advertiser IDRequired when target is DSP related.
Audience IDSpecify which audience to update. Required when the action is Update.This is the ID that was returned when the audience was created.
Audience DescriptionSpecify the Description of the Audience. Required.
Audience FeeCurrency and cost per impression (CPM). Required. Format:  currrency:cpm in cents Example: USD:1Currency should align with the marketplace of the advertiser.
Time to liveSpecify time the audience time to live in seconds.Required.Value needs to be greater than 0 and less than 34300800. Default: 34300800
Country codeSpecify country codes where the audience data collected from. Required.See full list of ISO 3166-2 country codes.
Wait for next statusSelect the "Wait for upload next status" check box, and then, in the "Max waiting time" field specify in minutes how long the job should wait for Amazon services to signal the upload status. Optional.
  1. Select Done.

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) 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 TD 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 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.
  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.

(Optional) Configure Export Results in Workflow

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

_export:
  td:
    database: td.database
   
+amazon_ads_export_task:
  td>: export_amazon_ads.sql
  database: ${td.database}
  result_connection: new_amazon_ads_auth
  result_settings:
    type: amazon_ads
    td_authentication_id: td_authentication_id
    amc_instance_id: amc_instance_id
    amc_account_id: amc_account_id
    dsp_region: NA
    action: CREATE
    upload_mode: APPEND
    target: AMC_AND_DSP
    dsp_advertiser_id: dsp_advertiser_id
    external_audience_id: external_audience_id
    audience_name: audience_name
    time_to_live: 34300800
    country_code: US
    wait_until_finish: true
    max_wait_time: 5

(Optional) Export Integration Using the CLI

You can also use the TD Toolbelt to export results to Amazon Ads using the  td query command with the --result option. For additional information see TD Query.

The data specified in with the --result option is in JSON format, and the general structure is as follows.

{
  "type": "amazon_ads",
  "td_authentication_id": ${authentication_id_from_td_console},
  "amc_instance_id": "amc_instance_id",
  "amc_account_id": "amc_account_id",
  "region": "NA",
  "action": "CREATE",
  "upload_mode": "APPEND",
  "target": "AMC_AND_DSP",
  "dsp_advertiser_id": "dsp_advertiser_id",
  "external_audience_id": "external_audience_id",
  "audience_name": "audience_name",
  "time_to_live": 34300800,
  "country_code": "US",
  "wait_until_finish": false,
  "max_wait_time": 1
}

Parameters

NameDescriptionValueDefault ValueRequired
typeThe destination of the export."amazon_ads"Yes
td_authentication_idThe authentication ID for the Amazon Ads authentication in the TD. Console. See Getting the Authentication ID for information on how to determine the value for this ID.Yes
amc_instance_idYour Amazon Marketing Cloud Instance IDYes
amc_account_idYour AMC Account ID. If leave you leave this field blank, the integration will automatically retrieve it.No
regionThe Region that corresponds with your DSP Advertiser account.enums ["NA", "EU", "FE"]"NA"Yes
actionAction to perform: - Create - Updateenums ["CREATE", "UPDATE"]"CREATE"Yes
upload_modeUpload mode to perform: - Append - Deleteenums ["APPEND", "DELETE"]"APPEND"Yes
targetAudience target: AMC AMC and DSPenums ["AMC", "AMC_AND_DSP"]"AMC"Yes
dsp_advertiser_idThe DSP Advertiser IDYes - if target is "AMC_AND_DSP"
external_audience_idThe user-specified external ID for their new audienceYes - if action is "CREATE"
audience_idAmazon Audience ID. The ID that was returned when the Audience was created.Yes - if action is "UPDATE"
audience_nameAudience nameYes - if action is "CREATE"
audience_descriptionAudience descriptionMust be an alphanumeric, non-null string between 0 to 1000 characters in length.No
audience_feeAudience metadata's feeFormat: currency:cpmCentsNo
time_to_liveAudience metadata's time to live in secondsMust be from 0 - 34300800No
country_codeCountry Code ISO 3166-1 alpha-2 CodesYes
wait_until_finishShould the integration wait until all the export jobs are completetrue or falseNo
max_wait_timeHow long (in minutes) the integration should wait until all the export jobs are complete.Must be from 1 - 1380 (23 hours)Yes, if wait_until_finish is TRUE

Usage Examples

This example executes a single manual export.

td query \
--database ${database_name} \
--wait "SELECT * FROM ${table_name}" \
--type presto \
--result '{"type":"amazon_ads","td_authentication_id":"${authentication_id_from_td_console}","amc_instance_id":"amc_instance_id","amc_account_id":"amc_account_id","region":"NA","action":"CREATE","upload_mode":"APPEND","target":"AMC_AND_DSP","dsp_advertiser_id":"dsp_advertiser_id","external_audience_id":"external_audience_id","audience_name":"audience_name","time_to_live":34300800,"country_code":"US","wait_until_finish":false,"max_wait_time":1}'

This example executes at a scheduled time.

td sched:create \
result_to_amazon_ads '0 0 * * *' \
--database ${database_name} 'SELECT * FROM ${table_name}' \
--result '{"type":"amazon_ads","td_authentication_id":"${authentication_id_from_td_console}","amc_instance_id":"amc_instance_id","amc_account_id":"amc_account_id","region":"NA","action":"CREATE","upload_mode":"APPEND","target":"AMC_AND_DSP","dsp_advertiser_id":"dsp_advertiser_id","external_audience_id":"external_audience_id","audience_name":"audience_name","time_to_live":34300800,"country_code":"US","wait_until_finish":false,"max_wait_time":1}'

External References

See Amazon Advertiser Audience APIs for additional information.