# Amazon DSP Data Provider Export Integration Amazon Demand-Side Platform (DSP) enables advertisers to programmatically buy display, video, and audio ads on or off Amazon. Amazon DSP is available to advertisers on Amazon irrespective of whether they sell products on Amazon. You can use Amazon's DSP to reach audiences through Amazon sites, apps, publishing partners, and third-party exchanges. The Amazon DSP Data Provider Export Integration allows you to export segment data like hashed emails and customer information to Amazon DSP. ## Prerequisites - Basic knowledge of Amazon DSP and an advertiser account. - Basic Knowledge of Treasure Data functions like Authentication, Queries, Results Export, and (optionally) Workflow. ## Limitations - The `External Audience ID` is the key to specifying the target audiences on Amazon. (It is unique to all audiences.) The values of this field will be unique for each advertiser account. - The job may split the result set into multiple batches. If one batch fails, the integration will not revert the successfully uploaded batches. - The integration will add the prefixes required per Amazon DSP API (COOKIE- or MAID-). Do not add these prefixes manually in the result set. - The integration will not update the Audience Metadata. - Null or empty column data will be ignored. - The result output schema must have either the cookie or maid columns or both in their metadata. - `Maid` and `cookie` columns must have the `string` data type. - The maximum length for a `cookie` field is 1999 characters. - For PII data export to Amazon DSP, we recommend using  [Amazon Ads Export Integration](/int/amazon-ads-export-integration). This connector uses a different API pathway and may yield better match performance. ## 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/](https://api-docs.treasuredata.com/en/overview/ip-addresses-integrations-result-workers/) ## Steps to create or remove an audience using PII information 1. Prepare a Hashed Records Datasource, including an external identifier * External identifier (external_id): A unique id represents a customer profile for a target advertiser. Using a hashed number generated from a combination of the advertiser ID and email (or phone) is recommended. If multiple customer profiles use the same external identifier (,.e. ID: 12345), it will be overwritten in the matching process in Amazon DSP, resulting in a low matching rate. Example of generating the external_id using the combination of advertiser_id and email: * External_id is the combination of advertiser_id and email: ```sql SELECT TO_HEX(SHA256(TO_UTF8(CONCAT(advertiser_id, email)))) AS external_id FROM table_name; ``` 1. In the data connector configuration, select the `hashed records` data source to send the above data to Amazon DSP for matching. 2. The matching process will begin within the Amazon DSP. The SLA (Service Level Agreement) is set at 48 hours. This timeframe starts when the hashed record API is called to utilize the uploaded external IDs for audience creation. It is important to note that the SLA remains consistent and does not change regardless of the volume of records being processed. 3. Add to Audience or Remove from Audience: * Prepare an external_user_id table for the audience to be added or removed from. The external_user_id is the external_id in step 1 ```SQL SELECT external_id as external_user_id FROM TABLE_NAME ``` 1. Then, export the result by selecting the ‘Audiences' data source. ## Create a New Authentication In Treasure Data, before running your query, you must create and configure the data connection to be used during the export. As part of the data connection, you provide authentication to access the integration. 1. Login to TD Console. 2. Navigate to **Integrations Hub** > **Catalog**. 3. Select the search icon on the far right of the Catalog screen, and enter **Amazon DSP**. 4. Hover over the Amazon DSP Data Provider connector and select **Create Authentication**. Alternatively. [create an activation](/products/customer-data-platform/audience-studio/activation/create-an-activation) (which includes authentication information) in TD Console. The following dialog opens: ![](/assets/amazondsp.bf6e047906c79a0a8f5e6c26297cd2334b8575bbbd108d4dde249b731b983155.f9a7c3b0.png) ![](/assets/screen-shot-2020-05-27-at-13.40.41.2bc8ab62e5c70618ed582661ad5fb889f139bea4600e7d0704012b55ba8077ba.f9a7c3b0.png) 1. Choose the **Region** of your advertiser account. 2. Enter your **Advertiser ID**. Then select **Continue.** 3. Enter a name for your connection. 4. Select **Done.** ![](/assets/screen-shot-2020-05-27-at-13.42.55.4d34700cee2167614824e61c2b38c8cdbf593601c96eadfdcd4cbdb90f898638.f9a7c3b0.png) ## Define your Query 1. Navigate to **Data Workbench > Queries**. 2. Select **New Query**. 3. Run the query to validate the result set. ![](/assets/image2021-9-7_15-1-38-1.a0ef34a3cfb6035eb6a53a758a755062decbb29fac046d1b24440a76d0662c7a.f9a7c3b0.png) ## Specify the Result Export Target 1. Select **Export Results**. ![](/assets/image2021-9-7_15-10-56.ee7ed43caab64adefafcc22595462fd8068c974c4f47b5959a7babd7d99972b8.f9a7c3b0.png) 1. You can select an existing authentication or create a new authentication for the external service to be used for output. Choose one of the following: ### Column Name for the Query The Amazon DSP Data Provider data connector understands and interprets only the following columns and data types. It would be best if you modified alias column names to match the following specified columns: **Data Source: Audiences** (require at least one of the below columns) | Column name | Type | Required | Description | | --- | --- | --- | --- | | cookie | string | optional | a cookie Id sent from a data provider to Amazon by a cookie sync | | maid | string | optional | a mobile advertising identifier | | external_user_id | string | optional | an external id defined by data providers | **Data Source: Hashed_records** (all below columns are required) | Column name | Type | Required | Description | | --- | --- | --- | --- | | first_name | string | required | The first name | | last_name | string | required | The last name | | address | string | required | The street address | | phone | string | required | The phone number | | city | string | required | The city | | postal_code | string | required | The postal code | | state | string | required | The state or province | | email | string | required | The email address | | external_id | string | required | The external identifier for this record | To export results: 1. Log into TD Console. 2. Navigate to **Data Workbench** > **Queries**. 3. Select the query that you plan to use to export data. 4. Example Audience Datasource: ```SQL SELECT a_cookie_column AS cookie, a_maid_column AS maid FROM your_table; ``` Example Hashed Records Datasource: Note that all columns are required; you can use dummy data strings for fields where you do not have data. E.g "first_name", "last_name_column". (Do not use empty strings "") ```sql SELECT first_name_column AS first_name, last_name_column AS last_name, address_column AS address, phone_column AS phone, city_column AS city, postal_code_column AS postal_code, state_column AS state, email_column AS email, external_id_column AS external_id FROM your_table ``` 1. Select **Export Results,** located at the top of your query editor. 2. The Choose Integration dialog box opens. 3. You have two options when selecting a connection to use to export the results: - Use an Existing Integration - Create New Integration #### Use an Existing Connection 1. Type the connection name in the search box to filter. 2. Select your connection. ![](/assets/screen-shot-2020-05-27-at-13.54.54.0de74d57120d47336b296e4b84600dfaf50050ca85c472ffc8597af3ebe90602.f9a7c3b0.png) 1. Select **Next**. 2. Type values for **Audience Name**, **Audience Description**, **External Audience ID**, **Time to live**, and **Operation,** and **Ignore Invalid Records.** #### Create New Integration 1. Select **Create New Integration.** 2. Type a **Name** for your connection. 3. Select your region. 4. Enter your **Advertiser ID**. ![](/assets/screen-shot-2020-05-27-at-13.59.54.b30d4ecce25556d4bdc37cf4064fdec8e41a8785d863c0b876077c1fe1999e6e.f9a7c3b0.png) 1. Select **Next**. 2. Enter values for the **Audience Name**, **Audience Description**, **External Audience ID**, **Time to live**, **Data Source Country**, **Operation,** and **Ignore Invalid Records** fields**. 3. Select **Done.**​​ ### (Optional) Specify information for Export to Amazon DSP ![](/assets/amazon-dsp-data-provider-export-integration-2024-01-29-2.a7c76a54b68b5fca39c478d6de9b269ddb79553c3d5084f34b3749979569fd25.f9a7c3b0.png) | **Parameter** | **Description** | | --- | --- | | **Data Source** (required) | The data source could be audiences or hashed_records. | | **Audience Name** (required if the data source is audiences) | The name of the audience you would like to create. | | **Audience Description** (optional) | Description for your audience. | | **External Audience ID** (required if the data source is audiences) | Unique key for your audience. | | **Time to live** (required if the data source is audiences) | The time in seconds that the audience will stay valid. | | **Data Source Country** (required) | Country codes are where your audience data is collected. Examples: "DE," "JP," etc. *The DMA (Digital Markets Acts) requires this. From February 29, 2024, all audience creation/update requests should contain the field indicating where the audience data was collected.* | | **Operation** (required if the data source is audiences) | The operation to perform on output data (add or remove). | | **Ignore Invalid Records** | If this check box is selected when the time data is sent to Amazon DSP, incorrect records or errors are skipped, and the remaining rows of data continue sending. If this checkbox is not selected, an exception is thrown when inaccurate records or errors are encountered. | ### (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. ![](/assets/image2021-1-15_17-28-51.f1b242f6ecc7666a0097fdf37edd1682786ec11ef80eff68c66f091bc405c371.0f87d8d4.png) 4. In the drop-down, select one of the following schedule options: ![](/assets/image2021-1-15_17-29-47.45289a1c99256f125f4d887e501e204ed61f02223fde0927af5f425a89ace0c0.0f87d8d4.png) | Drop-down Value | Description | | --- | --- | | Custom cron... | Review [Custom cron... details](#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. | | None | No schedule. | #### Custom cron... Details ![](/assets/image2021-1-15_17-30-23.0f94a8aa5f75ea03e3fec0c25b0640cd59ee48d1804a83701e5f2372deae466c.0f87d8d4.png) | **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 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. ## Configure Export Results in Workflow Example Audience Datasource ``` timezone: UTC_export: td: database: sample_datasets+td-result-into-target: td>: queries/sample.sql result_connection: your_connections_name result_settings: datasource: audiences region: NA advertiser_id: 12345 audience_name: This is a test audience audience_description: This is for testing purpose external_audience_id: test_audiences time_to_live: 3600 data_source_country: GB,IN,DE operation: Add ignore_error: false ``` Example Hashed Records: ```yaml timezone: UTC _export: td: database: sample_datasets +td-result-into-target: td>: queries/sample.sql result_connection: your_connections_name result_settings: datasource: hashed_records region: NA advertiser_id: 12345 time_to_live: 3600 ignore_error: false ``` To learn more about using data connectors in a workflow, refer to the [Workflows](https://docs.treasuredata.com/smart/project-product-documentation/treasure-workflow-terms-and-concepts) section of the documentation. ## 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. ![](/assets/ouput.b2c7f1d909c4f98ed10f5300df858a4b19f71a3b0834df952f5fb24018a5ea78.8ebdf569.png) - 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 Columns**to 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**. ![](/assets/snippet-output-connector-on-audience-studio-2024-08-28.a99525173709da1eb537f839019fa7876ffae95045154c8f2941b030022f792c.8ebdf569.png) - 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](/products/customer-data-platform/journey-orchestration/batch/creating-a-batch-journey-activation). # Export Integration Using the CLI You can also use TD Toolbelt CLI to export results to Amazon DSP. It would be best to specify the information for export to your Amazon DSP server using the `--result` option of the `td query` command. For more information about `td query,` refer to [TD Toolbelt Query Commands](https://api-docs.treasuredata.com/en/tools/cli/api/#query-commands). The format of the option is JSON, and the general structure is as follows: ```json {"type": "amazon_dsp_dp", "region": "NA", "advertiser_id": "12345", "audience_name": "This is a test audience", "audience_description": "This is for testing purpose", "external_audience_id": "test_audiences", "time_to_live": 3600, "data_source_country": "GB, IN, DE", "ignore_error": false} ```