Traits are part of the Advanced Customer Studio, available as an add-on to Business tier plans.
Overview
When defining audiences, you sometimes need computed or calculated attributes rather than raw data.
For example, you may want to create an audience based on Lifetime Value (LTV) though you don't have this column in your Users
table.
Creating it entails summing the price of all purchases made by a particular user.
Hightouch Traits enable users of any technical background to:
- Create computed fields
- Use them to define audiences
- Sync them to business applications
You can use these computed fields—called traits—to supercharge personalization across marketing channels without having to rely on data teams.
Trait types
Trait Type | Example Usage |
---|---|
Sum | Sum of price of all purchases a user has made in their lifetime |
Count | Count of songs listened to in the past two weeks |
Average | Average session time of a user |
Most Frequent | Most Frequent category of articles read |
First | First page a user visited |
Last | Last product a user viewed |
Custom SQL | All SKUs a user added to their cart before abandoning it |
Formula | Use the result of a string column to create a boolean flag |
Traits are defined on parent model, but you can also create traits based on events to capture information about customer actions in a customer funnel.
Create a trait
- Go to the Traits page and click Create -> New Trait.
- Select a parent model.
- Select the calculation method.
- Select the related model from which you're aggregating column values.
- [Optional] Apply any conditions to the calculation method.
- Select the trait type, for example,
SUM
. - Add required configurations for the trait type. For
SUM
, for instance, you need to select which column to sum.
- Give the trait a descriptive Name, for example, "Lifetime Value."
- Click Save.
The trait is now part of the parent model, and you can use it when creating audiences. It will automatically be available to sync for any audience that belongs to this parent model.
Create a trait template
Alternatively, you can also create a Trait Template. Unlike Traits, Trait Templates can't have any conditions applied to it. However, you can then build traits off the template and apply any conditions you desire. Trait Templates allow you to easily reuse your trait configuration without having to start from scratch each time.
- Go to the Traits page and click Create -> New template.
- Go through the trait creation steps just like you would for a regular trait.
Once you have created a template, it will be available to all audiences under the same parent model. You can use the template as a filter for creating audiences or use it to create trait enrichments for syncing data.
Updating a trait template will also update its underlying traits. For
instance, if you were to change the trait calculation type of the template
from SUM
to COUNT
, all of its underlying traits will also use the COUNT
aggregation.
Create a trait from a template
After you create a template, you can use it as a base to create traits.
- Go to the Traits page and click Create -> Start with a template.
- Select a template and click Choose template.
- [Optional] Add any conditions to the trait.
- Give the trait a descriptive Name, for example, "Lifetime Value."
- Click Save.
Create audiences with traits
Once you've created a trait, you can use it for filtering within your audiences. Traits filters are under Custom traits in the filters dropdown.
There are three kinds of traits you can use in your audience filter:
- Trait templates
- Traits
- Custom traits
Using trait templates in the audience
- Click Add filter
- Navigate to Custom traits and select a trait template. For example, if you created an LTV trait, you can use it to filter for "All users that have spent more than $100."
- [Optional] You can also add filters to apply before Hightouch calculates trait values. For example, you can restrict the LTV calculation to purchases where the
Brand
was Nike directly in the audience builder.
- [Optional] You can save the trait filter as a new trait enrichment. To do so, click the actions button and "Save trait enrichment"
Using traits in the audience
- Click Add filter
- Navigate to Custom traits and select a trait
- [Optional] You can edit the trait configuration by clicking Edit. Updating these filters will not affect the original trait.
- [Optional] If you edit the trait and want to save it as a new trait, click the actions button and "Save trait."
Creating a custom trait within the audience
Maybe you don't have a suitable trait or trait template to act as a filter. Or, maybe you just want to experiment with a trait filter without necessarily creating one for the parent model. You can create a custom trait inline within the audience query builder.
- Click Add filter
- Navigate to Custom traits and click Create a custom trait
- Select a related model
- Select the configuration for your trait
- [Optional] If you decide that this custom trait is useful enough to persist it for the entire parent model, click the actions button and "Save trait." Doing so converts it into a new trait that can be synced.
Enrich audiences with traits
Traits defined on the parent model are automatically available for syncing to destinations. Alternatively, you can create trait enrichments which are traits that are specific to an audience.
Trait enrichments are based on a parent trait which are the trait templates you've defined on the parent model.
- Go to the Traits tab of the audience you want to add enrichments to.
- Click Create trait.
- Enter a Name and select the Parent trait.
- [Optional] Add conditions to apply on top of the parent trait.
Once created, these enrichment traits appear in the Audience preview and sync configuration like any other field.
Event traits
In addition to defining traits on parent models, you can also apply traits to events in the visual audience builder. Event traits automatically become trait enrichments, meaning you can view them in the preview and sync their values. One common use case for event traits is to capture information about abandoned carts.
- To create a new event trait, click Add trait on an event condition in the audience builder.
You can only access the Add trait option from an event filter once you've saved the audience.
- Give the event trait a descriptive Name.
- Select the aggregation you want to use, for example, Last.
- Select the information you want to capture about the event. For example, you may want to capture the
Product_ID
,SKU
, orBrand
of the final product a user added to their cart before abandoning it.
Custom SQL traits
Custom SQL traits provide a powerful escape hatch for custom aggregations that the default aggregations don't cover. To build a SQL trait, create a trait and follow these additional instructions:
- Select SQL as the Aggregation type.
- Enter a raw SQL aggregation. For example, to create a
SUM
trait with just SQL, you would enterSUM({{ column "price" }})
.
{{column "<COLUMN_NAME>"}}
. Column names are case-sensitive. - Enter a default value for when the SQL returns no rows.
- Define the Property type of the SQL aggregation result.
See the section on how traits work for more information on how Hightouch calculates and joins custom SQL traits to a parent model.
JSON aggregations
JSON aggregations are a helpful way to aggregate the raw data in a related model. For example, imagine you want to get a list of all product IDs users have purchased. You can do this with the following SQL trait:
ARRAY_AGG(DISTINCT {{column "product_id"}})
CASE statements
CASE
statements are a useful way to create friendly options for aggregations. For example, imagine you want to bucket customers into low
, medium
, and high
LTV. You can do this with the following SQL trait:
CASE
WHEN SUM( {{column "price"}} ) > 100 THEN 'high'
WHEN SUM( {{column "price"}} ) > 50 THEN 'medium'
ELSE 'low'
END
Formula traits
Formula traits allow you to reference parent model columns, merged columns, and other traits to build inline transformations. Unlike Custom SQL Traits, there is no aggregation against a single related model. Instead, you can reference columns from a multitude of sources. This unlocks a powerful and flexible way to compose columns all within Hightouch.
- Select Formula as the Aggregation type.
- Enter raw SQL. To reference a column or trait, type the name for the autocompletion dropdown to show up. Then, select it to populate the editor as shown above. Here are a few examples of SQL queries that can be done using formula traits:
- Combine multiple columns into one:
CONCAT({{"first_name"}}, ' ', {{"last_name"}})
. - Use a string column to create a boolean flag:
CASE WHEN {{"merged.pets.animal"}} LIKE 'dog' THEN true ELSE false END
- Reference other traits:
CASE WHEN {{"trait.lifetime_total_value"}} > 1000 THEN 'high' ELSE 'low' END
.
Column references in formula traits use special syntax. Please use the SQL editor's autocompletion feature to write the column references.
References to non-existant columns or traits will be shown with a red pill.
- Define the Property type of the SQL aggregation result.
Trait value suggestions
Most Frequent, First, Last, Custom SQL, and Formula traits that result in a string type support trait value suggestions. When enabled this provides suggested values for the visual audience builder. For example, if you're creating an audience you want to filter on a "Most Recent City" trait, turning on suggestions populates a dropdown with values—San Francisco, Los Angeles, etc.—found in the dataset.
Enabling suggestions
Trait value suggestions can be enabled when creating or viewing a trait.