The Space Filters API provides fine-grained controls that allow you to conditionally prevent data delivery to spaces to ensure only relevant events and profile data are processed, stored and activated on. A space filter applies to events coming from all sources connected to a space. You can filter entire events (for example, selectively drop them) or block/allow individual fields in events before you send them. You can conditionally apply filters to each event based on the contents of that event’s payload. For example, you could apply a filter to Track events with a plan
property equal to Professional
, or you could apply a filter to events with a user email address that does not match *@example.com
.
Space Filters API are available to all Unify and Engage customers.
Note: The Filters API is currently in a Private Beta. If you are interested in joining the Private Beta, please reach out to your customer success manager or friends@segment.com
Either an “Identity admin” or “Profiles and Engage admin” role is required to be able to create, update and delete filters. “Profiles and Engage Read-only” and “Profiles Read-only, Engage User” roles are restricted to preview, get and list filters operations. For more details, see the Segment Roles Documentation
There are three filters that can be applied to events:
Type | Action |
---|---|
drop | Do not send the event to the space. |
allowProperties | Allow properties in the event by specifying nested JSON objects (for example, context , properties.productDetails , etc.) and a list of fields that should be retained in that nested object, with all others dropped before the event is sent to the space. |
dropProperties | Drop properties in the event by specifying nested JSON objects (for example, context , properties.productDetails , etc.) and a list of fields to drop from those nested objects before the event is sent to the space. |
The allowProperties
and dropProperties
filters may only filter fields inside the following top-level fields of Segment events:
properties
context
traits
Filters can optionally be applied to an event by writing an "if"
statement using Filter Query Language ("FQL"), Segment’s simple query language for streaming JSON. FQL statements evaluate to true or false based on the contents of each event, allowing you to only apply filters to specific events.
For example, given the following event payload:
{
"event": "Button Clicked",
"type": "track",
"context": {
"library": {
"name": "analytics.js",
"version": "1.0",
}
}
}
The following FQL statements will evaluate to "true"
, causing the filter to be applied:
event = 'Button Clicked'
event = 'Button Clicked' and type = 'track'
match(context.library.version, '1.*')
type = 'identify' or type = 'track'
And the following FQL statements will evaluate to "false"
, causing the filter to be skipped:
event = 'Screen Tapped'
context.path.path = '/login'
match (context.library.version, '2.*')
For more detailed documentation including a list of all operators and functions, see the FQL Documentation.
To apply a filter to all events going to a space, you can supply an "if"
statement of "all"
. All actions in that filter will be applied to events before being delivered to that space.
Filters currently have the following limits:
If you would like any of these limits lifted, please reach out to Segment at friends@segment.com.
Attribute | Type | Description |
---|---|---|
id | string | The unique identifier of this filter. |
workspaceId | string | The workspace id of this filter. |
integrationId | string | The space id of this filter. |
name | string | The name of this filter. |
enabled | boolean | Whether or not this filter should be active. |
title | string | A human-readable title for this filter. |
description | string | A longer human-readable description of this filter. |
if | string | A FQL statement that causes this filter’s action to be applied if it evaluates to true. "all" will cause the filter to be applied to all events |
drop | boolean | The drop action will cause the event to be dropped and not sent to the space if the "if" statement evaluates to true. |
dropProperties | list of string | The dropProperties action takes a list of fields for each object that should be allowed, with all other fields in those objects dropped. |
allowProperties | list of string | The allowProperties action takes a list of fields for each object that should be dropped, with all other fields in those objects untouched. |
To simulate the application of a Space filter to a provided JSON payload, please use the Preview Destination Filter endpoint.
Creates a filter for a space. A space filter applies to events coming from all Sources connected to a space.
• This endpoint is in Beta 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 Space Filters feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Filter Created
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
{- "integrationId": "<id>",
- "name": "Test filter",
- "if": "type = \"track\""
}
{- "data": {
- "filter": {
- "id": "<id>",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "integrationId": "9aQ1Lj62S4bomZKLF4DPqW",
- "name": "test",
- "if": "all",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Lists filters for a space.
• This endpoint is in Beta 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 Space Filters feature enabled. Please reach out to your customer success manager 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.spaceFilters.listFiltersForSpace('<id>')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "filters": [
- {
- "id": "test",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "integrationId": "9aQ1Lj62S4bomZKLF4DPqW",
- "name": "Test filter",
- "if": "type = 'track'",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
]
}
}
Deletes a filter by id.
• This endpoint is in Beta 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 Space Filters feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Filter Deleted
event in the audit trail.
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.spaceFilters.deleteFilterById('<id>')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Gets a filter by id.
• This endpoint is in Beta 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 Space Filters feature enabled. Please reach out to your customer success manager 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.spaceFilters.getFilterById('<id>')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "filter": {
- "id": "<id>",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "integrationId": "9aQ1Lj62S4bomZKLF4DPqW",
- "name": "Test filter",
- "if": "type = 'track'",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Updates a filter by id and replaces the existing filter.
• This endpoint is in Beta 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 Space Filters feature enabled. Please reach out to your customer success manager for more information.
• When called, this endpoint may generate the Filter Updated
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
{- "integrationId": "<id>",
- "if": "!(type = \"track\")",
- "name": "Test name",
- "enabled": true,
- "description": "Changed description"
}
{- "data": {
- "filter": {
- "id": "<id>",
- "integrationId": "<id>",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "if": "!(type = \"track\")",
- "name": "Test name",
- "enabled": true,
- "description": "Changed description",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}