Learn more about Amplitude Import Integration.
Use queries to create Amplitude Events from the data you store in Treasure Data.
- Basic knowledge of Treasure Data, including the TD Toolbelt.
- An Amplitude account that can grant permissions to Treasure Data.
If you do not have an Amplitude account, go to https://amplitude.com and register. Then, create an organization and a project. When you create a project, you receive an API Key for the project.

In the Amplitude console, you can view User Activity to explore Amplitude events:

Go to the TD Console, and Queries and select New Query to access the query editor. You can pick the query language and write your query. Select Output results.

| Option | Task Steps | Tip |
|---|---|---|
| Create a connector | - Go to Connections. - Select on the Amplitude icon from Sources Catalog. - Complete the required fields on the first pane. - In the API Key field, enter the key that you use in Amplitude. - In the Secret Key field, delete the default entry and leave the field empty. Next you complete the Configuration fields. | Sometimes you need to define the column mapping before writing the query. |
| Select a connector | - Go to Treasure Data console. - Go to Query Editor. - Access the query that you plan to use to export data. - Select Output results. The Choose Saved Connection dialog opens. - Type the connection name in the search box to filter and select the connection that you want. Next you complete the Configuration fields. | You can also create a new connection from here by selecting on Create New Connection. |
Creating a new connection:

You must enter your API Key. For output to Amplitude, the Secret Key field must be empty. If necessary, delete the default entry the Secret Key field. Region: support the data center for each region in the EU and the US (default)
Selecting an existing connection:

After creating a new amplitude connection or selecting an existing one, you see the Additional configuration popup, for example:


| Parameters | Description | Default values |
|---|---|---|
| Target | Target Amplitude object to which data needs to be uploaded. Supported: - Event - Identify | Event |
| Disable auto-generation of Insert IDs for deduplication | By default, TD automatically generates the insert_ids for deduplication. See Event Deduplication for details. | Unchecked |
| Operation | Operation to perform on Amplitude. Supported: - Set - Set Once - Add - Append - Prepend - Unset - Pre Insert - Post Insert - Remove | Add |
| Region | Support the data center for each region in the EU and the US (default). | US |
| Number of events per batch | Number of records that TD connector sends as a batch to Amplitude | 10 |
In the following example, the Amplitude project has no events before the output of a query result:

In Treasure Data, run the following query with Amplitude as Result Export:
SELECT
user_id,
device_id,
event_type,
event_properties,
country,
time
FROM (
VALUES(
'a@gmail.com',
'f925065b-4d56-486f-a2be-e97952e62925',
'game_open',
'{"load_time":0.0619166532,"dates":["sunday","monday"],"source":"notification"}',
'United States',
1515083919310
),
(
'b@gmail.com',
'b36c8c80-71a0-4de4-8bcb-c801f5c1c6c3',
'select_avatar',
'{"load_time":0.0517593568,"dates":["friday","sunday"],"source":"notification"}]',
'United States',
1515083943092
),
(
'c@gmail.com',
'e44a1024-c4bb-4eef-a02a-f2a7b3bf68b3',
'watch_tutorial',
'{"load_time":0.0689998562,"dates":["sunday","monday"],"source":"notification"}',
'United States',
1515083970894
),
(
'd@gmail.com',
'8274fee1-7222-4e41-83ed-fb5521d5f4b8',
'game_start',
'{"load_time":0.0976384392,"dates":["friday","monday"],"source":"notification"}',
'United States',
1515084000948
),
(
'e@gmail.com',
'29ba193d-0955-4084-9640-bb4d8ba9a23f',
'ad_clicked',
'{"load_time":0.0708434955,"dates":["monday","saturday"],"source":"notification"}',
'United States',
1515084024759
)
) tbl(
user_id,
device_id,
event_type,
event_properties,
country,
time
)The preceding query requires no source table, which makes testing easy, but you still must choose a database. Pick "sample_datasets" or any other arbitrary table. Also, make sure that Presto is chosen as the SQL dialect.
The query completes in a few seconds. Log into your Amplitude account and check User Activity. It should look similar to this:

All columns or aliases included in your query must use the names and data types as described in the Amplitude API specification.
If you have multiple values, you can combine them into a single JSON column value as follows:
SELECT CAST(MAP(ARRAY['source', 'status', 'action'], ARRAY['notification', 'pending', 'add']) AS JSON) AS event_propertiesYou create a simple JSON object for event_properties: '{"action":"add","source":"notification","status":"pending"}'.
You can create a more complex column, as follows:
SELECT CAST(MAP(ARRAY['load_time', 'source', 'dates'], ARRAY[CAST (0.8371 AS JSON), CAST ('notification' AS JSON), CAST(ARRAY['monday', 'tuesday'] AS JSON)]) AS JSON) AS event_propertiesYou create the following JSON object as the event_properties value: '{"dates":["monday","tuesday"],"load_time":0.8371,"source":"notification"}'.
An example of a TD database table that can be used to create records for Amplitude is as follows:

In the Treasure Data console, go to query editor and enter a query, for example:
SELECT user_id, device_id, event_type, event_properties, country, event_time AS time FROM eventsSelect Output results to send the data to Amplitude. Next, you select an existing connector, or create a new connection using your api_key.
When the connector has been selected or created, in the query editor, select Run to begin the data transfer.
It is highly recommended that an insert_id be sent with each event to prevent duplicate events from being saved by Amplitude. The insert_id is a unique identifier an event. Amplitude drops events that have the same insert_id if the IDs are sent within 7 days of each other.
If you do not select to disable auto-generation of insert IDs, then TD automatically generates a SHA256 insert_id for each record.
If you select to disable auto-generation of insert IDs, then insert_id’s must be provided by the user.
The following table lists event columns and data types supported by Amplitude.
| Key | Description |
|---|---|
| user_id string | (required unless device_id is present) A readable ID specified by you. "datamonster@gmail.com" |
| device_id string | (required unless user_id is present) A device specific identifier, such as the Identifier for Vendor on iOS. "C8F9E604-F01A-4BD9-95C6-8E5357DF265D" |
| event_type string | (required) A unique identifier for your event. "watch_tutorial" |
| time long | The timestamp of the event in milliseconds since epoch. It will be set to the upload time by default. 1396381378123 |
| event_properties4 json | {"load_time": 0.8371, "source": "notification", "dates": ["monday", "tuesday"]} |
| user_properties4 json | {"age": 25, "gender": "female", "interests": ["chess", "football", "music"]} |
| groups4 json | (Enterprise only) {"company_id": "1", "company_name":["Amplitude", "DataMonster"]} |
| app_version | The version of your application the user is on. "2.1.3" |
| platform1,2 string | Platform of the device. "iOS", "Android", or "Web" |
| os_name1,2 string | The mobile operating system or browser the user is on. "iOS", "Android", "Chrome" |
| os_version1,2 string | The version of the mobile operating system or browser the user is on. "8.1", "4.2.2", "37" |
| device_brand1,2 string | The device brand the user is on. "Verizon" |
| device_manufacturer1,2 string | The device manufacturer the user is on. "Samsung", "Asus", "Apple" |
| device_model1,2 string | The device model the user is on. "Mac", "iphone 9,1", "sm-g30f" |
| carrier1,2 string | Carrier of the device. "Verizon" |
| country1,3 string | The country the user is in. "United States" |
| region1,3 string | The geographical region the user is in. "California" |
| city1,3 string | What city the user is in. "San Francisco" |
| dma1,3 string | The Designated Market Area of the user. "San Francisco-Oakland-San Jose, CA" |
| language1 string | What language the user has set. "English" |
| price5 float | (required for revenue data if revenue is not sent) The price of the item purchased. You can use negative values to indicate refunds. 4.99, -1.99 |
| quantity5 integer | (required for revenue data, defaults to 1 if not specified) The quantity of the item purchased. 1,2 |
| revenue5 float | revenue = price * quantity If you send all three fields of price, quantity, and revenue, then (price * quantity) will take precedence and be the revenue value. You can use negative values to indicate refunds. 4.99, -1.99 |
| productId5 string | An identifier for the product. Note: You must send a price and quantity with this field. "Google Play Store Product Id", "Medium Bundle" |
| revenueType5 string | Type of revenue. Note: You must send a price and quantity with this field. "tax", "refund" |
| location_lat float | Latitude of the user. 37.77 |
| location_lng float | Longitude of the user. -122.39 |
| ip1 string | IP address of the user. Use "$remote" to use your server’s IP address. "127.0.0.1" |
| idfa string | (iOS) Identifier for Advertiser. "AEBE52E7-03EE-455A-B3C4-E57283966239" |
| idfv string | (iOS) Identifier for Vendor. "BCCE52E7-03EE-321A-B3D4-E57123966239" |
| adid string | (Android) Google Play Services advertising ID (AdID). "AEBE52E7-03EE-455A-B3C4-E57283966239" |
| Optional Amplitude Specific Key | Description |
|---|---|
| event_id int | An incrementing counter to distinguish events with the same user_id and timestamp from each other. Note: We recommend you send an event_id, increasing over time, especially if you suspect any events to occur simultaneously. An event_id is not required to send a session_id though. 1 |
| session_id long | The start time of the session is in milliseconds since it uses epoch (Unix Timestamp), which is necessary if you want to associate events with a particular session (a session_id of -1 implies that you not sending a session_id, and so no session metrics will be tracked). Learn more about tracking sessions in Amplitude. 1396381378123 |
| insert_id string | A unique identifier for the event being inserted; we will deduplicate events with the same insert_id sent within 7 days of each other. Some combination of device_id, user_id, session_id, event_type, and event_id or time, would likely serve as a sufficient insert_id value. "f47ac10b-58cc-4372-a567-0e02b2c3d479" |
| Column name | Data type | Required? | Description |
|---|---|---|---|
user_id | String | Conditional | Required unless device_id is present. A UUID (unique user ID) specified by you. If you send a request with a user_id that's not in the Amplitude system yet, then the user tied to the user_id isn't marked new until their first event. |
device_id | String | Conditional | Required unless user_id is present. A device-specific identifier, such as the Identifier for Vendor (IDFV) on iOS. |
user_properties_x | String, Plattent to build an array | Optional | A dictionary of key-value pairs that represent data tied to the user. Each distinct value appears as a user segment on the Amplitude dashboard. Object depth may not exceed 40 layers. You can store property values in an array, and date values are transformed into string values. Amplitude compares dates as strings, so Amplitude recommends that you use the ISO 8601 format (YYYY-MM-DDTHH:mm: ss). This lets you perform date comparisons in the web app. For example, '2016-01-31' > '2016-01-01'). This also applies to datetime values like '2017-08-07T10:09:08' > '2017-08-07T01:07:00'. |
app_version | String | Optional | The version of the app the user is on. |
platform | String | Optional | The platform that's sending the data. |
os_name | String | Optional | The mobile operating system or browser the user is on. |
os_version | String | Optional | The version of the mobile operating system or browser the user is on. |
device_brand | String | Optional | The device brand the user is on. |
device_manufacturer | String | Optional | The device manufacturer of the device that the user is using. |
device_model | String | Optional | The device model the user is on. |
carrier | String | Optional | The carrier the user has. |
country | String | Optional | The country that the user is in. |
region | String | Optional | The geographical region the user is in. |
city | String | Optional | The city the user is in. |
dma | String | Optional | The Designated Market Area of the user. |
language | String | Optional | The language the user has set. |
paying | String | Optional | Whether the user is paying. |
start_version | String | Optional | The version of the app the user was on first. |
| User Property (Key) | Description | Sample Value | Type |
|---|---|---|---|
| cohort | Behavioral segment or experiment group | "Beta Users" | string |
| subscription_plan | User subscription level | "Pro" | string |
| signup_date | The user’s signup date (ISO format) | "2025-01-01" | timestamp |
| onboarding_complete | Whether the user completed onboarding | true | boolean |
| login_count | Total number of logins | 5 | long |
| referrer_code | Invite/referral code used | "ABC123" | string |
| utm_source | Marketing campaign source | "Facebook" | string |
| utm_medium | Type of campaign channel | "email" | string |
| utm_campaign | Campaign name | "BlackFriday2025" | string |
| last_purchase_date | Last successful purchase date | "2025-05-01" | timestamp |
| has_active_subscription | The user has an active subscription | false | boolean |
| features_enabled | List of enabled feature flags | ["chat", "dark_mode"] | string |
| interests | User interests | ["music", "sports"] | string |
| feedback_rating | Feedback rating from user (e.g., 1 to 5) | 4 | double |
| survey_completed | Whether the user submitted a survey | true | boolean |
| preferred_language | UI/display language preference | "en" | string |
| lifetime_value | Total value the user has generated (e.g., in USD) | 129.99 | double |
| has_push_enabled | Whether push notifications are enabled | true | boolean |
| demo_attended | Whether the user joined a demo call/webinar | false | boolean |
| team_size | Team or organization size (for B2B use cases) | 50 | long |
Or any field that not in Identify Schema list column is the user_properties columns.
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.
Navigate to Data Workbench > Queries
Create a new query or select an existing query.
Next to Schedule, select None.

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

Drop-down Value Description 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. None No schedule.

| 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. |
- (Optional) You can delay the start time of a query by enabling the Delay execution.
You can also use CLI (Toolbelt) to export results to Shopify by specifying the information you want to export to your Shopify server using the --result option of the td query command. For more information about the td query command, refer to TD Toolbelt: Query Commands.
Options for the yml configuration files used for TD Toolbelt are formatted in JSON, and the general structure is as follows.
- For Event Target
out:
type: amplitude
api_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
target: 'event'
disable_auto_generation_insert_ids: false
region: 'US'
events_per_batch: 10- For Identify Target
out:
type: amplitude
target: identify
api_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
region: EU
operation: set
skip_invalid_records: falseParameters
| Name | Description | Value | Default Value | Required |
|---|---|---|---|---|
| type | Connector type | amplitude | N/A | Yes |
| api_key | API key to export data | N/A | N/A | Yes |
| target | Target Amplitude object to which data needs to be uploaded. | Supported values: - event - identify | event | Yes |
| region | The API region for Amplitude export data. | Supported values: - US - EU | US | Yes |
| operation | Operation to perform on Amplitude. | Supported values: - set - set_once - add - append - prepend - unset - pre_insert - post_insert - remove | add | Yes |
| disable_auto_generation_insert_ids | Disable auto generation insert ids | False | N/A | |
| events_per_batch | Event batch size | Integer | 10 | N/A |
| skip_invalid_records | Enable skipping of invalid records. | True or False | True | N/A |
Upload Event
td query \
--result '{"type":"amplitude","api_key":"api_key","target":"event","region":"US","disable_auto_generation_insert_ids":"false","events_per_batch":10}' \
-d sample_database \
"select user_id,device_id,event_type,value from tbl_shop" \
-T prestoUpload Identify
td query --result \
'{"type":"amplitude","api_key":"api_key","target":"identify","region":"US","operation":"add","skip_invalid_records":true}'\
-d sample_database \
"select user_id,device_id,user_properties,value from tbl_shop" \
-T presto- The Result Export can be scheduled to periodically upload data to a target destination. See Scheduling Jobs Using TD Console.
- All import and export integrations can be added to a TD Workflow. The td>: data operator can export a query result to a specified integration. For more information, see Reference for Treasure Workflow Operators.