Skip to content

Commit 59c5b65

Browse files
author
markzegarelli
authored
Merge branch 'master' into DOC-280_postgres
2 parents a407227 + 54b5c4e commit 59c5b65

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed
73.9 KB
Loading

src/personas/sql-traits.md

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ title: Personas SQL Traits
55

66

77

8-
SQL Traits allow you to import user or account traits from your data warehouse back into Personas to build audiences, or to enhance Segment data that you send to other destinations.
8+
SQL Traits allow you to import user or account traits from your data warehouse back into Personas to build audiences, or to enhance Segment data that you send to other Destinations.
99

10-
SQL Traits are only limited by what data you have in your warehouse. Anything you can write a query for can become a SQL Trait, which allows you to add more details to your user and account profiles, which allows better and more nuanced personalization.
10+
SQL Traits are only limited by the data in your warehouse. Because anything you can write a query for can become a SQL Trait, you can add detail to your user and account profiles, resulting in more nuanced personalization.
1111

1212
This unlocks some interesting possibilities to help you meet your business goals.
1313

14-
- Imagine you want to increase the CSAT (customer satisfaction score) of your Support team. You could create a SQL Trait of most common ticket requests for a customers' industry by joining data from cloud sources like Zendesk and Salesforce, so you can better anticipate the user's problems and speed up their solution.
15-
- If you wanted to determine if a user is a resident of a specific area, you could query address data in your Warehouse and send this information as a true or false trait to a Personas audience.
16-
- If you wanted to fill gaps in your customer profiles to include information from before you implemented Segment, you could import historical traits from your warehouse to fill in the gaps.
17-
- If you wanted to more accurately predict lifetime value (LTV) for a customer, you can generate a complex query based on demographic and customer data in your warehouse, and use that information in a Personas audience to send personalized offers or recommend specific products.
18-
- You could use similarly complex queries to build churn or product adoption models that cannot be easily calculated using Personas Computed Traits, and use them to inform your outreach efforts.
14+
- To improve your support team's customer satisfaction score (CSAT), you can create a SQL Trait of the most common ticket requests for a customer's industry by joining data from cloud sources like Zendesk and Salesforce. The resulting SQL Trait helps you anticipate the user's problems and accelerate potential solutions.
15+
- To determine if a user resides in a specific area, you can query address data in your warehouse and send it as a `true` or `false` Trait to a Personas audience.
16+
- To fill gaps in your customer profiles to include information before you implemented Segment, you can import historical Traits from your warehouse.
17+
- To predict a customer's lifetime value (LTV), you can generate a complex query based on demographic and customer data in your warehouse. You can then use that information in a Personas audience to send personalized offers or recommend specific products.
18+
- To inform your outreach efforts, you can use complex queries to build churn or product adoption models.
1919

20-
Check out our [blog post](https://segment.com/blog/sql-traits) for more customer case studies.
20+
Check out our [SQL Traits blog post](https://segment.com/blog/sql-traits){:target="_blank"} for more customer case studies.
2121

2222

2323
### Example: Cloud Sources Sync
2424

25-
SQL traits allow you to import data from [object cloud sources](/docs/connections/sources/#object-cloud-sources) such as Salesforce, Stripe, Zendesk, Hubspot, Marketo, Intercom and more. For example, you could bring in Salesforce Leads or Accounts, syncing Zendesk ticket behavior, or Stripe LTV calculations.
25+
SQL Traits allow you to import data from [object cloud sources](/docs/connections/sources/#object-cloud-sources) like Salesforce, Stripe, Zendesk, Hubspot, Marketo, Intercom, and more. For example, you can bring in Salesforce Leads or Accounts, Zendesk ticket behavior, or Stripe LTV calculations.
2626

27-
The two examples below show SQL queries you could use to get cloud-source information from your warehouse.
27+
The two examples below show SQL queries you can use to retrieve cloud-source information from your warehouse.
2828

2929
**Salesforce lead import**
30-
If you wanted to import data from the Salesforce leads and contacts table, you could use SQL similar to the following query:
30+
If you wanted to import data from the Salesforce leads and contacts table, you can use SQL similar to the following query:
3131

3232
```sql
3333
select external_id_c as user_id,
@@ -53,24 +53,26 @@ This query computes whether a user has an open ticket.
5353

5454
## Setting up SQL traits
5555

56-
To use SQL traits you need:
56+
To use SQL Traits, you need the following:
5757

58-
- a Warehouse connected to Segment
58+
- a warehouse connected to Segment
5959
- a Personas-enabled Segment workspace
6060
- a user account with access to Personas in that workspace
6161

6262
### Step 1. Set up a warehouse source
6363

64-
We currently support Redshift, Postgres, Snowflake, and BigQuery as data warehouse sources for SQL traits. The set up process for BigQuery is a bit different as it _requires_ a service user.
64+
Segment supports Redshift, Postgres, Snowflake, Azure, and BigQuery as data warehouse sources for SQL Traits. The setup process for BigQuery is a bit different as it _requires_ a service user.
6565

66-
For any warehouse, we recommend that you create a separate read-only user for building SQL traits.
66+
> info "Safeguard your data"
67+
> For any warehouse, we recommend that you create a separate read-only user for building SQL Traits.
6768
6869
#### Redshift, Postgres, Snowflake Setup
6970

7071
If you don't already have a data warehouse, follow one of the guides here first:
7172
- [Redshift Getting Started](/docs/connections/storage/catalog/redshift/#getting-started)
7273
- [Postgres Getting Started](/docs/connections/storage/catalog/postgres/#getting-started)
7374
- [Snowflake Getting Started](/docs/connections/storage/catalog/snowflake/#getting-started)
75+
- [Azure Getting Started](/docs/connections/storage/catalog/azuresqldw/#getting-started)
7476

7577
Remember to create a read-only service user!
7678

@@ -80,7 +82,7 @@ To connect BigQuery to Segment SQL Traits, you must create a service account for
8082

8183
1. Navigate to the Google Developers Console.
8284

83-
2. Click the drop down to the left of the search bar and select the project to which you want to connect.
85+
2. Click the drop down to the left of the search bar and select the project that you want to connect.
8486

8587
![](images/bigquery_setup1.png)
8688

@@ -92,7 +94,7 @@ To connect BigQuery to Segment SQL Traits, you must create a service account for
9294

9395
![](images/bigquery_setup2.png)
9496

95-
6. Give the service account a name - we recommend something like `segment-sqltraits`.
97+
6. Give the service account a name like `segment-sqltraits`.
9698

9799
7. Under **Project Role**, add _only_ the `BigQuery Data Viewer` and `BigQuery Job User` roles.
98100

@@ -110,7 +112,7 @@ To connect BigQuery to Segment SQL Traits, you must create a service account for
110112

111113
![](images/bigquery_setup5.png)
112114

113-
A file with the key is saved to your computer. Save this, because you'll need it to set up the Warehouse source in the next step.
115+
A file with the key is saved to your computer. Save this, because you'll need it to set up the warehouse source in the next step.
114116

115117
![](images/bigquery_setup6.png)
116118

@@ -128,7 +130,7 @@ Once your warehouse is up and running:
128130

129131
2. Select the type of warehouse you're connecting.
130132

131-
![](images/warehouse_source_setup2.png)
133+
![](images/warehouse_source_setup2A.png)
132134

133135
3. In the next screen, provide the connection credentials, and click **Save**.
134136

@@ -138,13 +140,13 @@ Once your warehouse is up and running:
138140

139141
## Creating a SQL Trait
140142

141-
Before you create a SQL trait, you must first preview it to validate your query. If you've never used SQL before, we have a few templates you can use to try it out.
143+
Before you create a SQL Trait, you must first preview it to validate your query. If you're new to SQL, try out one of the templates Segment offers.
142144

143145
### Preview the SQL trait
144146

145-
From the Personas screen, go to the Computed Traits tab, and click create a new SQL trait. Select the data warehouse that contains the data you want to query.
147+
From the Personas screen, go to the Computed Traits tab, and click **New Computed Trait**. Next, choose SQL, and click **Configure**. Select the data warehouse that contains the data you want to query.
146148

147-
If you are sending data from [object cloud sources](https://segment.com/docs/connections/sources/#cloud-apps) to your warehouse, the SQL traits UI has some pre-made templates you can try out.
149+
If you are sending data from [object cloud sources](/docs/connections/sources/#cloud-apps) to your warehouse, the SQL Traits UI has some pre-made templates you can try out.
148150

149151
![Example template: preview all users with an open Zendesk ticket](images/sql_traits_preview1.png)
150152

@@ -159,29 +161,29 @@ When you're building your query, there are some requirements for the data your q
159161
- Each record must be less than 16kb in size to adhere to [Segment's maximum request size](/docs/connections/sources/catalog/libraries/server/http-api/#max-request-size).
160162

161163
A successful preview returns a sample of users and their traits.
162-
If we have seen a user before in Personas, their profile shows a green checkmark. You can click that user to view their user profile. If a user has a question mark, we haven't seen this `user_id` in Personas before.
164+
If Segment recognizes a user already in Personas, it displays a green checkmark on their profile. You can click that user to view the user's profile. If a user has a question mark, Segment hasn't detected this `user_id` in Personas before.
163165

164166
![Click on a user to check out their profile. If a user has a question mark, we haven't seen this user_id in Personas before](images/sql_traits_preview2.png)
165167

166168

167169
### Configure SQL Trait options
168170

169-
Once you're ready to import the SQL trait, select the destinations that you want to send this data to, **or** if you want to build Personas audiences from this data, you don't need to select destinations, and can just click **Skip**.
171+
Once you're ready to import the SQL Trait, select the Destinations to which you want to send the data. If you prefer to build Personas audiences directly from the data instead of sending it to a Destination, click **Skip**.
170172

171173
![Select destinations](images/sql_traits_connect1.png)
172174

173-
Give your SQL trait a name. This is used as a label only, for descriptive purposes. If you're importing multiple traits, give it a name like "Zendesk traits". The trait names you use in audience-building or in your downstream tools correspond to the column names from the query.
175+
Give your SQL Trait a name. This is used as a label for descriptive purposes. If you're importing multiple Traits, give it a name like "Zendesk Traits". The Trait names you use in audience-building or in your downstream tools correspond to the column names from the query.
174176

175177
If you're building Personas audiences from this data, select "Compute without enabled destinations".
176178

177-
Click **Create Computed Trait** to save the trait.
179+
Click **Create Computed Trait** to save the Trait.
178180

179181
![](images/sql_traits_connect3.png)
180182
Check **Compute without destinations** if you only want to send to Personas
181183

182-
When you create a SQL trait, Segment runs the query on the warehouse twice a day by default. (If you're interested in a more frequent or customizable schedule, [contact us](https://segment.com/help/contact/).)
184+
When you create a SQL Trait, Segment runs the query on the warehouse twice a day by default. (If you're interested in a more frequent or customizable schedule, [contact Segment Support](https://segment.com/help/contact/){:target="_blank"}.)
183185

184-
For each row (user or account) in the query result, Personas sends an identify or group call with all the columns that were returned as traits. For example, if you write a query that returns `user_id,has_open_ticket, num_tickets_90_days, avg_zendesk_rating_90days` we send an identify call with the following payload:
186+
For each row (user or account) in the query result, Personas sends an identify or group call with all the columns that were returned as Traits. For example, if you write a query that returns `user_id,has_open_ticket, num_tickets_90_days, avg_zendesk_rating_90days` we send an identify call with the following payload:
185187

186188
```sql
187189
{
@@ -203,38 +205,38 @@ Happy Querying!
203205

204206
The result set is capped at 10 million rows.
205207

206-
### How often are you querying the customer's data warehouse?
208+
### How often does Segment query the customer's data warehouse?
207209

208-
We query the data warehouse every 12 hours by default, but can query up to hourly. [contact us](https://segment.com/help/contact/) if you need more customizable schedules.
210+
Segment queries the data warehouse every 12 hours by default, but can query up to hourly. [Contact us](https://segment.com/help/contact/) for customized schedules.
209211

210212
### What identifiers can I use to query a list?
211213

212-
You can currently query based on `email`, `user_id` or `anonymous_id`. If we don't locate a match based on the chosen identifier, a new user profile is created. See question below.
214+
You can currently query based on `email`, `user_id` or `anonymous_id`. If Segment doesn't locate a match based on the chosen identifier, it creates a new profile. See more below.
213215

214-
### Can you use SQL traits to create users in Segment? Or do SQL traits only append traits to existing users?
216+
### Can I use SQL Traits to create users in Segment? Or do SQL Traits only append Traits to existing users?
215217

216-
Yes, the Personas engine sends an `identify` call if there is no match between the identifier you chose and existing record. When this happens, Segment creates a new user profile. (This identify call happens in the back-end, and doesn't show up in your Debugger.)
218+
Yes. The Personas engine sends an `identify` call if there is no match between the identifier you chose and an existing record. When this happens, Segment creates a new user profile. (This identify call happens in the back-end, and doesn't show up in your Debugger.)
217219

218220
### Does Personas send identify/group calls on every run?
219221

220-
No, Personas only sends an identify/group call if the values in a row have changed from previous runs.
222+
No. Personas only sends an identify/group call if the values in a row have changed from previous runs.
221223

222224
### I have a large (1M+) query of users to import, should I be worried?
223225

224-
If you're importing a large list of users and traits, the biggest consideration is the API call usage and volume among the partners you are sending the data to. These vary depending on our partners, so [contact us](https://segment.com/help/contact/) if you are concerned about this.
226+
If you're importing a large list of users and traits, you'll need to consider your API call usage as well as volume among the partners receiving your data. These vary depending on our partners, so [reach out to us](https://segment.com/help/contact/) for more information.
225227

226228
### Is there a limit on the size of a SQL Trait's payload?
227229

228230
Yes, Segment limits request sizes to a maximum of 16kb. Records larger than this are discarded.
229231

230232
## Troubleshooting
231233

232-
### I am getting a permissions error.
234+
### I'm getting a permissions error.
233235

234236
You might encounter a similar permissions error:
235237
![](images/troubleshoot1.png)
236238

237-
This is usually because you are querying a schema and table that the current user does not have access to. To check the table privileges for a specific grantee (user), go to [your warehouse source credentials in Personas](https://app.segment.com/goto-my-workspace/personas/settings/warehouse-sources/) to retrieve the user name. Typically to grant access to a table, an admin needs to grant access to both a schema and table through the following similar commands:
239+
Segment usually displays this error because you're querying a schema and table that the current user cannot access. To check the table privileges for a specific grantee (user), go to [your warehouse source credentials in Personas](https://app.segment.com/goto-my-workspace/personas/settings/warehouse-sources/) to retrieve the user name. To grant access to a table, an admin usually needs to grant access to both a schema and table through the following similar commands:
238240

239241
```sql
240242
GRANT USAGE ON SCHEMA ecommerce TO segment_user;
@@ -245,28 +247,28 @@ Learn more about granting permissions:
245247
- https://www.postgresql.org/docs/9.0/sql-grant.html
246248
- https://stackoverflow.com/questions/17338621/what-grant-usage-on-schema-exactly-do
247249

248-
### I am seeing a maximum columns error.
250+
### I'm seeing a maximum columns error.
249251

250252
![](images/troubleshoot2.png)
251253

252-
We currently support returning only 25 columns. [Contact us](https://segment.com/help/contact/) with a description of your use case if you need to access more.
254+
Segment currently supports returning only 25 columns. [Contact us](https://segment.com/help/contact/) with a description of your use case if you need to access more.
253255

254-
### I am seeing a duplicate user_id error.
256+
### I'm seeing a duplicate `user_id` error.
255257

256258
![](images/troubleshoot3.png)
257259

258-
We require that each row of the query corresponds to a unique user. We throw this error if we see multiple rows with the same `user_id`. Use a `distinct` or `group by` statement to ensure that each row has a unique user_id.
260+
Each query row must correspond to a unique user. Segment displays this error if it detects multiple rows with the same `user_id`. Use a `distinct` or `group by` statement to ensure that each row has a unique user_id.
259261

260-
### I am seeing some users/accounts in my preview with questions marks. What does that mean?
262+
### I'm seeing some users/accounts in my preview with questions marks. What does that mean?
261263

262264
This could mean one of two things:
263265

264-
**1. We haven't seen this `user_id`/`group_id` before in Personas**
266+
**1. Segment doesn't recognize this `user_id`/`group_id` in Personas**
265267

266-
This means for the [sources connected to Personas](https://app.segment.com/goto-my-workspace/personas/settings/sources) we have not received any event (identify, track, page etc) with this `user_id`. This could still be a legitimate `user_id` for a number of reasons, but before syncing, make sure you rule out option 2 (below) as sending a different identifier as the `user_id` can corrupt your identity graph.
268+
This means for the [sources connected to Personas](https://app.segment.com/goto-my-workspace/personas/settings/sources) Segment has not received any event (identify, track, page etc) with this `user_id`. This could still be a legitimate `user_id` for a number of reasons, but before syncing, make sure you rule out option 2 (below) as sending a different identifier as the `user_id` can corrupt your identity graph.
267269

268270
**2. You have the wrong `user_id` column**
269271

270-
You might be returning a value for `user_id` that is inconsistent with how you track `user_id` elsewhere. We've seen cases where some customers want to return `email` as the `user_id`, or a partner's tool id as the `user_id`. These are against our best practices and corrupt the identity graph if you are then tracking `user_id` differently elsewhere in your apps.
272+
You might be returning a value for `user_id` that is inconsistent with how you track `user_id` elsewhere. Some customers want to return `email` as the `user_id`, or a partner's tool id as the `user_id`. These conflict with Segment best practices and corrupt the identity graph if you then track `user_id` differently elsewhere in your apps.
271273

272-
If you see only question marks in the preview, and have already tracked data historically with Segment, then you probably just have the wrong column. If you cloud source doesn't have the database `user_id`, we recommend JOINing with an internal users table before sending the results back to Segment.
274+
If you see only question marks in the preview, and have already tracked data historically with Segment, then you likely have the wrong column. If your cloud source doesn't have the database `user_id`, we recommend using a `JOIN` clause with an internal users table before sending the results back to Segment.

0 commit comments

Comments
 (0)