Computed traits allow you to quickly create new traits for a user or profile based on that user's tracked interactions. Using the events and event properties that you send through page and track calls, Segment will calculate and keep up-to-date, over time, the value for your defined computed trait. These can be computations like the total number of orders a customer has completed, the lifetime revenue of a customer, the most frequent user to determine which user is most active in an account, or the unique visitors count to assess how many visitors from a single domain.
Note: The Computed Traits API is currently in a Private Beta. If you are interested in joining the Private Beta, then please reach out to your customer success manager.
Note that when using a unique list computed trait, Segment limits the number of Event Properties that can be added to the specific trait to 10,000. If your computed trait exceeds this limit, Segment will not persist any new Event Properties and will drop new trait keys and corresponding values.
Creates a Computed Trait
• This endpoint is in Alpha testing. Please submit any feedback by sending an email to friends@segment.com.
• In order to successfully call this endpoint, the specified Workspace needs to have the Computed Trait feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Computed Trait Created
event in the audit trail.
Note: The definition for a Computed Trait created using the API is not editable through the Segment App.
The rate limit for this endpoint is 10 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
OK
Resource not found
Validation failure
Too many requests
{- "name": "name",
- "description": "description",
- "enabled": false,
- "definition": {
- "query": "event('Shoes Bought').count() >= 1",
- "type": "USERS"
}, - "options": {
- "includeAnonymousUsers": true,
- "includeHistoricalData": true
}
}
{- "data": {
- "computedTrait": {
- "id": "id",
- "spaceId": "spaceId",
- "name": "name",
- "description": "description",
- "key": "key",
- "definition": {
- "query": "event('Shoes Bought').where(property('price') >= 100).count()",
- "type": "USERS"
}, - "status": "Live",
- "enabled": false,
- "createdBy": "createdBy",
- "updatedBy": "updatedBy",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Returns Computed Traits by spaceId.
• This endpoint is in Alpha testing. Please submit any feedback by sending an email to friends@segment.com.
• In order to successfully call this endpoint, the specified Workspace needs to have the Computed Trait feature enabled. Please reach out to your customer success manager for more information.
The rate limit for this endpoint is 25 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
object (PaginationInput) Information about the pagination of this response. See pagination for more info. This parameter exists in alpha. Example: pagination=pagination.count=1 |
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.computedTraits.listComputedTraits('spaceId')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "computedTraits": [
- {
- "id": "id",
- "spaceId": "spaceId",
- "name": "name",
- "description": "description",
- "key": "key",
- "definition": {
- "query": "event('Shoes Bought').where(property('price') >= 100).count()",
- "type": "USERS"
}, - "status": "Live",
- "enabled": false,
- "createdBy": "createdBy",
- "updatedBy": "updatedBy",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
], - "pagination": {
- "current": "MA==",
- "totalEntries": 2
}
}
}
Returns the Computed Trait by id and spaceId
• This endpoint is in Alpha testing. Please submit any feedback by sending an email to friends@segment.com.
• In order to successfully call this endpoint, the specified Workspace needs to have the Computed Trait feature enabled. Please reach out to your customer success manager for more information.
The rate limit for this endpoint is 100 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.computedTraits.getComputedTrait('spaceId', 'id')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "computedTrait": {
- "id": "id",
- "spaceId": "spaceId",
- "name": "name",
- "description": "description",
- "key": "key",
- "definition": {
- "query": "event('Shoes Bought').where(property('price') >= 100).count()",
- "type": "USERS"
}, - "status": "Live",
- "enabled": false,
- "createdBy": "createdBy",
- "updatedBy": "updatedBy",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Deletes a Computed Trait by id and spaceId.
• This endpoint is in Alpha testing. Please submit any feedback by sending an email to friends@segment.com.
• In order to successfully call this endpoint, the specified Workspace needs to have the Computed Trait feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Computed Trait Deleted
event in the audit trail.
The rate limit for this endpoint is 20 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.computedTraits.removeComputedTraitFromSpace('spaceId', 'id')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Updates the enabled status for a computed trait.
• This endpoint is in Alpha testing. Please submit any feedback by sending an email to friends@segment.com.
• In order to successfully call this endpoint, the specified Workspace needs to have the Computed Trait feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Computed Trait Modified
event in the audit trail.
• Note that when a Computed Trait is updated, the Computed Trait will be locked from future edits until the changes have been incorporated. You can find more information in the Segment docs. Note: The definition for a Computed Trait updated using the API is not editable through the Segment App.
The rate limit for this endpoint is 10 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
OK
Resource not found
Validation failure
Too many requests
{- "enabled": false
}
{- "data": {
- "computedTrait": {
- "id": "id",
- "spaceId": "spaceId",
- "name": "name",
- "description": "description",
- "key": "key",
- "definition": {
- "query": "event('Shoes Bought').where(property('price') >= 100).count()",
- "type": "USERS"
}, - "status": "Live",
- "enabled": false,
- "createdBy": "createdBy",
- "updatedBy": "updatedBy",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}