You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/personas/sql-traits.md
+34-36Lines changed: 34 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Personas SQL Traits
5
5
6
6
7
7
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.
9
9
10
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.
11
11
@@ -17,7 +17,7 @@ This unlocks some interesting possibilities to help you meet your business goals
17
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
18
- To inform your outreach efforts, you can use complex queries to build churn or product adoption models.
19
19
20
-
Check out our[SQL Traits blog post](https://segment.com/blog/sql-traits){:target="_blank"} for more customer case studies.
20
+
Check out Segment's[SQL Traits blog post](https://segment.com/blog/sql-traits){:target="_blank"} for more customer case studies.
21
21
22
22
23
23
### Example: Cloud Sources Sync
@@ -27,7 +27,8 @@ SQL Traits allow you to import data from [object cloud sources](/docs/connection
27
27
The two examples below show SQL queries you can use to retrieve cloud-source information from your warehouse.
28
28
29
29
**Salesforce lead import**
30
-
If you wanted to import data from the Salesforce leads and contacts table, you can use SQL similar to the following query:
30
+
31
+
If you want to import data from the Salesforce leads and contacts table, you can use SQL similar to the following query:
31
32
32
33
```sql
33
34
select external_id_c as user_id,
@@ -40,7 +41,7 @@ If you wanted to import data from the Salesforce leads and contacts table, you c
40
41
41
42
**Has Open Ticket in Zendesk**
42
43
43
-
This query computes whether a user has an open ticket.
44
+
This query computes whether a user has an open ticket:
44
45
45
46
```sql
46
47
select distinctu.external_idas user_id, true as has_open_ticket
@@ -61,32 +62,31 @@ To use SQL Traits, you need the following:
61
62
62
63
### Step 1. Set up a warehouse source
63
64
64
-
Segment supports Redshift, Postgres, Snowflake, Azure SQL, and BigQuery as data warehouse sources for SQL Traits. The setup process for BigQuery is a bit different as it_requires_ a service user.
65
+
Segment supports Redshift, Postgres, Snowflake, Azure SQL, and BigQuery as data warehouse sources for SQL Traits. Note that the BigQuery setup process_requires_ a service user.
65
66
66
67
> info "Safeguard your data"
67
68
> For any warehouse, we recommend that you create a separate read-only user for building SQL Traits.
To connect BigQuery to Segment SQL Traits, you must create a service account for Segment to use.
81
+
To connect BigQuery to Segment SQL Traits, follow these instructions to create a service account for Segment to use:
82
82
83
83
1. Navigate to the Google Developers Console.
84
84
85
85
2. Click the drop down to the left of the search bar and select the project that you want to connect.
86
86
87
87

88
88
89
-
> **Note**: If you don't see the project you want in the menu, click the account switcher in the upper right corner, and check that you're logged in to the right Google account for the project.
89
+
> **Note**: If you don't see the project you want in the menu, click the account switcher in the upper right corner, and verify that you're logged in to the right Google account for the project.
90
90
91
91
3. Click the menu in the upper left and select **IAM & Admin**, then **Service accounts**.
92
92
@@ -112,17 +112,15 @@ To connect BigQuery to Segment SQL Traits, you must create a service account for
112
112
113
113

114
114
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.
115
+
A file with the key is saved to your computer. Save this; you'll need it to set up the warehouse source in the next step.
116
116
117
117

118
118
119
-
8. Create new BigQuery Warehouse Source in Personas
120
-
121
-
Now you can create a new BigQuery warehouse source, upload the JSON key you just downloaded, and complete the BigQuery setup
119
+
You're now ready to create a new BigQuery warehouse source, upload the JSON key you just downloaded, and complete the BigQuery setup.
122
120
123
121
### Step 2. Add the warehouse as a Personas Source
124
122
125
-
Once your warehouse is up and running:
123
+
Once your warehouse is up and running, follow these steps:
126
124
127
125
1. Navigate to the Personas settings (Personas > Settings tab > Warehouse Sources), and click **New Warehouse Source**.
128
126
@@ -152,16 +150,16 @@ If you are sending data from [object cloud sources](/docs/connections/sources/#c
152
150
153
151
<!-- need to actually give a sample here -->
154
152
155
-
When you're building your query, there are some requirements for the data your query returns.
153
+
When you're building your query, keep the following requirements in mind for the data your query returns.
156
154
157
155
- The query must return a column with a `user_id`, `email`, or `anonymous_id` (or `group_id` for account traits, if you have Personas for B2B enabled).
158
-
- It must return at least one additional trait in addition to `user_id`/`group_id`, and no more than 25 total columns
156
+
- It must return at least one additional trait in addition to `user_id`/`group_id`, and no more than 25 total columns.
159
157
- The query must not return any `user_id`s with a `null` value, or any duplicate `user_id`s.
160
158
- The query must not return more than 25 million rows.
161
159
- 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).
162
160
163
161
A successful preview returns a sample of users and their traits.
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.
162
+
If Segment recognizes a user already in Personas, it displays a green checkmark on their profile. Clicking the checkmark displays the user's profile. If a user has a question mark, Segment hasn't detected this `user_id` in Personas before.
165
163
166
164

167
165
@@ -172,14 +170,14 @@ Once you're ready to import the SQL Trait, select the Destinations to which you
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.
173
+
Give your SQL Trait a descriptive name. If you're importing multiple Traits, use 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.
176
174
177
175
If you're building Personas audiences from this data, select "Compute without enabled destinations".
178
176
179
177
Click **Create Computed Trait** to save the Trait.
180
178
181
179

182
-
Check **Compute without destinations** if you only want to send to Personas
180
+
Check **Compute without destinations** if you only want to send to Personas.
183
181
184
182
When you create a SQL Trait, Segment runs the query on the warehouse twice a day by default. You can customize the time at which Segment queries the data warehouse and the frequency, up to once per hour, from the SQL Trait's settings.
185
183
(If you're interested in a more frequent schedule, [contact Segment Support](https://segment.com/help/contact/){:target="_blank"}.)
@@ -198,25 +196,23 @@ For each row (user or account) in the query result, Personas sends an identify o
198
196
}
199
197
```
200
198
201
-
Happy Querying!
202
-
203
199
## FAQs
204
200
205
201
### Is there a limit to the result set that can be queried and imported?
206
202
207
-
The result set is capped at 25 million rows.
203
+
Yes. The result set is capped at 25 million rows.
208
204
209
205
### How often does Segment query the customer's data warehouse?
210
206
211
207
For each SQL Trait you create, you can set a compute schedule to query the data warehouse up to once per hour. Your query may run at any given time during the hour you select.
212
208
213
209
### What identifiers can I use to query a list?
214
210
215
-
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.
211
+
You can 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.
216
212
217
213
### Can I use SQL Traits to create users in Segment? Or do SQL Traits only append Traits to existing users?
218
214
219
-
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.)
215
+
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 takes place in the back-end and doesn't show up in your Debugger.
220
216
221
217
### Does Personas send identify/group calls on every run?
222
218
@@ -234,42 +230,44 @@ Yes, Segment limits request sizes to a maximum of 16kb. Records larger than this
234
230
235
231
### I'm getting a permissions error.
236
232
237
-
You might encounter a similar permissions error:
233
+
You might encounter a `permission denied for schema`error, like the following:
238
234

239
235
240
-
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:
236
+
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.
237
+
238
+
To grant access to a table, an admin usually needs to grant access to both a schema and table through the following similar commands:
241
239
242
240
```sql
243
241
GRANT USAGE ON SCHEMA ecommerce TO segment_user;
244
242
GRANTSELECTON TABLE ecommerce.users TO segment_user;
-[What does 'Grant usage on schema' do?](https://stackoverflow.com/questions/17338621/what-grant-usage-on-schema-exactly-do){:target="_blank"}
250
248
251
249
### I'm seeing a maximum columns error.
252
250
253
251

254
252
255
-
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.
253
+
Segment supports returning only 25 columns. [Contact us](https://segment.com/help/contact/) with a description of your use case if you need access to more than 25 columns.
256
254
257
255
### I'm seeing a duplicate `user_id` error.
258
256
259
257

260
258
261
259
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.
262
260
263
-
### I'm seeing some users/accounts in my preview with questions marks. What does that mean?
261
+
### I'm seeing some users/accounts in my preview with question marks. What does that mean?
264
262
265
-
This could mean one of two things:
263
+
Question marks in previews indicate one of two things:
266
264
267
-
**1. Segment doesn't recognize this `user_id`/`group_id` in Personas**
265
+
**1. Segment doesn't recognize this `user_id`/`group_id` in Personas.**
268
266
269
-
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.
267
+
In this case, for [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 two (below), as sending a different identifier as the `user_id` can corrupt your identity graph.
270
268
271
-
**2. You have the wrong `user_id` column**
269
+
**2. You have the wrong `user_id` column.**
272
270
273
-
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.
271
+
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.
274
272
275
273
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