# Snapchat Export Integration You can write job results from Treasure Data directly to Snapchat. Use this data connector to create User Segments, upload data into existing segments, and remove users from a segment. The connector supports follow features: - Add, replace, or remove users from multiple segments - Auto-create a new segment if the segment does not exist - Clear all users from segments - Auto-detect and hash the user ID (email, phone, or mobile_ad_id) if the value is not hashed - Specify an option to skip or stop invalid values ## Prerequisites - Basic knowledge of Treasure Data, including the TD toolbelt - A valid Snapchat Ad Account account - Authorized Treasure Data account access to Snapchat Marketing account ## Use the TD Console to Create Your Connection ### Create a New Connection 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. Go to the **Catalog**, search and select **Snapchat**. ![](/assets/snapicon.0ca38b774caa0896efe0d41214276a3ff40cc71ebd1c5b252270380bf5927d5d.285d718f.png) The following dialog opens. ![](/assets/snapnewauth.88837e9909e637988e2d626753d35fe2e5f6dc970a3a4364706b5e75a5bb9673.285d718f.png) ### Authenticating Your Connection Select **Click here to connect to a new account**. You are redirected to Snapchat to log in if you haven't yet, or to the consent page to grant access to Treasure Data. ![](/assets/mceclip3-2.e1578e5759d705d835407753a7ddc77120fcd7863a1720a6c8e84d90222030be.285d718f.png) You will be redirected back to TD Console. Repeat the first step (Create a new connection) and choose your new OAuth connection. ![](/assets/blobid0.8f01c71a8906e920f875de8e7ac9a05ad9ee8b5aa6c96064a25f695cf2f00446.285d718f.png) Enter your Ad Account ID. See Appendix: What is my Ad Account ID. Select **Continue** and name your new Snapchat connection. Select **Done.** ![](/assets/mceclip5-2.94854d0902a7559b71080abd1913e5bf880682f1f3f44728166fbec3299660ea.285d718f.png) ### Configure Export Results in Your Data Connection In this step, you create or reuse a query and configure the data connection in the query. Sometimes, you need to define the column mapping in the query. ### Configure the Connection by Specifying the Parameters Go to the TD Console. Go to **Data Workbench** > **Queries**. Access the query that you plan to use to export data. Select **Export Results**, located at the top of your query editor. The Choose Integration dialog opens. You have two options when selecting a connection to use to export the results: 1. Use an existing connection Type the connection name in the search box to filter and select your connection. The dialog opens ![](/assets/snapchatsourcetype.29c4588c73a5ddd822bdf6a6d98170197430c8ea18527d6c13da75f06941fa6c.285d718f.png) 2. Create a new Snapchat Connection. Select **New Integration**, and select Snapchat from the **Type** dropdown. You see the following: ![](/assets/snapchatnew1-2.09622086cc9289825167290841df6b9f6879871f1db64b2f0b90d25c2681b581.285d718f.png) Select **Save and Continue**. You see: ![](/assets/snapchatnew2.2a88fd3110d56b9c54caf1e3782ed4fe1f7fde5b004f4f70bb1948d75b014fe0.285d718f.png) Complete the steps described in Create a new connection, including the creation of an OAuth connection. Enter the required credentials for your new SnapChat connection. Set the following parameters. - **Segment Operation** (required): **Add Users**, **Remove Users, Replace Users** (remove all users and add new users) from segments, or **Clear Segments Data** (remove all users from segments) - **Source Type**: Export source type. Supported values are - First Party (Default) - Pixel - Mobile - Foot Traffic Insights - **Skip Invalid Data**: option to skip invalid rows and segments and to continue importing others. Invalid rows are listed in the job log. If this option is not selected, jobs terminate when an invalid record is encountered, and uploaded data is not reverted. - **Max users uploaded per request** (required): the maximum number of users uploaded in a single request. The default is 100000. Accepted value from 1-200000. If you specify more than 100000 users per request, you might receive an error message from Snapchat due to the limitation of uploaded users per request. The job splits the upload data into multiple requests based on this parameter. The query requests are processed until finished, and all data is uploaded. ### Column Name for the Query The Snapchat data connector understands and interprets only the following columns and data types. You must modify alias column names to match the following specified columns: | Column name | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | segment_id | string | optional | | if both segment_id and segment_name are specified, the segment_id will be used. | | segment_name | string | optional | | If the segment_name does not exist in Snapchat.- Create a new segment with the same name if Segment Operation is Add Users - Treated as invalid data if Segment Operation is Remove Users - Throw an error or ignore depending on the option: **Skip Invalid Data** for **Clear Segment Data** | | segment_description | string | optional | | | | retention_in_days | integer | optional | 9999 | Set the default as 9999 if 0 or not specified. Accept value from 1 to 9999 | | id_type | string | required | | Must be either- email - phone - mobile_ad_id | | id_value | string | required | | Either SHA256 hashed or raw value of email, phone, mobile_ad_id | You must include either segment_id or segment_name column in the Query otherwise, your jobs fail. ### Example Queries to Populate Snapchat Data From Treasure Data, run the following query with export results into a connection for Snapchat: The following example query uploads all emails to the existing Segments specified by **segment_id** if Segment Operation is specified as Add Users. ```sql SELECT segment_id AS segment_id, 'email' AS id_type, email AS id_value FROM my_table; ``` The following example query checks for the segment **Football fans** or creates a new segment with a Retention of 30 days if the Segment Operation is specified as Add Users. ```sql SELECT 'Football fans' AS segment_name, 30 AS retention_in_days, 'phone' AS id_type, mobile_phone AS id_value FROM my_table ``` ### (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. ### 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. ![](/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). ### Q: Why is **Reach** in Snapchat Audiences list unchanged after I uploaded users? - Snapchat takes up to 72 hours to process and match your uploaded users with its database. When the process is finished, the audience number is updated, and the status is set to **Ready**. ### Q: Why does the Reach in Snapchat Audiences list increase after I remove users? - After sending requests to remove users from the Audience list, Snapchat may show temporarily uploaded users. You must wait until Snapchat finishes the process of matching and removing. The process can take up to 72 hours. The process is complete when you see the status set to **Ready**. # Appendix ## Ad Account ID To find your Ad Account ID, log in to your Business account, and navigate to the Ad Account as shown in the following image. From there, you can see your Ad Account ID. ![](/assets/blobid1-2.734aa68bca7b05dd5446f028c82999ff4f9e3c317cbbba8fcccfd9383c17916d.285d718f.png) ## Find the Segment ID When working with Segments, you need either a Segment name or Segment ID. Here's how to find the Segment ID from your browser: - Log into your Snapchat Ad Account - Go to the **Audiences** section. - Select an existing Segment - The Segment ID is on the address bar of your browser as follows: ![](/assets/mceclip0.eb71e111951db1154d38a9fa8ce36852b67f91b59e599e91291e8af76484a18a.285d718f.png)