The Destination Filters API provides fine-grained controls that allow you to conditionally prevent data delivery to specific destinations. 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
.
Use Destination Filters to:
Destination Filters are available to all Business customers and support cloud-based (server-side) and web device-mode destinations. Mobile device-mode destinations are in beta and only support Swift, Kotlin, and React Native 2.0 libraries. S3 and Warehouse Destinations are not yet supported.
There are three filters that can be applied to events:
Type | Action |
---|---|
drop | Do not send the event to the destination |
sample | Send only a percentage of events through to the destination. You can optionally sample based on a field. For example, you can sample 10% of users by sampling on userId instead of a random 10% of all events, which is the default. |
allow_properties | 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 destination. |
drop_properties | 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 destination. |
The allow_properties
and drop_properties
filters may only filter fields inside the following top-level fields of Segment events:
properties
context
traits
Filters are applied in the following order for each event:
drop
sample
allow_properties
drop_properties
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 destination, you can supply an "if" statement of "all". All actions in that filter will be applied to events before being delivered to that destination.
Destination 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 | |
---|---|---|---|
name | string | The URL path of this filter. | read-only |
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 | required |
actions | []action | The filtering action to take on events that match the "if" statement. Must be one of: "drop", "sample", "allow_properties", or "drop_properties". | required |
The drop
action will cause the event to be dropped and not sent to the destination if the "if" statement evaluates to true.
Attribute | Type | Description | |
---|---|---|---|
type | string | The action name. For the drop action, this must be "drop". | required |
The sample
action will allow only a percentage of events through. It can sample randomly or, if given a path attribute, it can sample a percentage of events based on the contents of a field. This is useful for sampling all events for a percentage of users rather than a percentage of all events for all users.
Attribute | Type | Description | |
---|---|---|---|
type | string | The action name. For the sample action, this must be "sample". | required |
percent | float | A percentage in the range [0.0, 1.0] that determines the percent of events to allow through. 0.0 will allow no events and 1.0 will allow all events. The default is 0.0. | required |
path | string | If non-empty, events will be sampled based on the value at this path. For example, if path is userId, a percentage of users will have their events allowed through to the destination. |
The allow_properties action takes a list of nested objects (for example, context
, properties.orderDetails
) and a list of fields for each object that should be allowed, with all other fields in those objects dropped.
Attribute | Type | Description | |
---|---|---|---|
type | string | The action name. For the allow properties action, this must be "allow_properties". | required |
fields | map of string → list of string | A map of nested JSON objects that should have their properties filtered. The map key is the path to the nested JSON object (for example, context.ip, properties, etc.) and the value is a list of string that specifies which fields within the object to allow. Nested JSON objects not specified in this map will be untouched by this filter | required |
The drop_properties action takes a list of nested objects (for example, context
, properties.orderDetails
) and a list of fields for each object that should be dropped, with all other fields in those objects untouched.
Attribute | Type | Description | |
---|---|---|---|
type | string | The action name. For the drop properties action, this must be "drop_properties". | required |
fields | map of string → list of string | A map of nested JSON objects that should have their properties filtered. The map key is the path to the nested JSON object (for example, context.ip, properties, etc.) and the value is a list of string that specifies which fields within the object to drop. Nested JSON objects not specified in this map will be untouched by this filter | required |
Config API field | Public API counterpart |
---|---|
name | Use the id field instead |
enabled | enabled |
title | title |
description | description |
if | if |
actions | actions |
Config API | Public API counterpart |
---|---|
drop_event | drop |
sample_event | sample |
whitelist_fields | allow_properties |
blacklist_fields | drop_properties |
The type of fields
property has been changed:
Config API | Public API counterpart |
---|---|
map of string → Field List (see below) | map of string → list of string |
Attribute | Type | Description |
---|---|---|
fields | []string | One or more JSON object field names. Nested fields (that is, dot-separated field names) are not supported. |
To migrate, replace any usages of the Config API endpoints with the Segment Public API counterparts, using the field mappings in the table above.
Creates a filter in a Destination.
• When called, this endpoint may generate the Destination Filter Created
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
{- "sourceId": "rh5BDZp6QDHvXFCkibm1pR",
- "title": "Filter \"Identify\" events",
- "description": "Drop Identify tracking from this destination",
- "if": "type = \"identify\"",
- "actions": [
- {
- "type": "DROP"
}
], - "enabled": true
}
{- "data": {
- "filter": {
- "id": "2c0vbh2htbJmSvPJSeDypz3CjVg",
- "sourceId": "rh5BDZp6QDHvXFCkibm1pR",
- "destinationId": "fP7qoQw2HTWt9WdMr718gn",
- "if": "type = \"identify\"",
- "actions": [
- {
- "type": "DROP"
}
], - "title": "Filter \"Identify\" events",
- "description": "Drop Identify tracking from this destination",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Lists filters for a Destination.
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.destinationFilters.listFiltersFromDestination('qtiZHLLqqsHmpvLXNtP5du')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "filters": [
- {
- "id": "py8vAgox9DyyJfgYcWY8Bd",
- "sourceId": "rh5BDZp6QDHvXFCkibm1pR",
- "destinationId": "qtiZHLLqqsHmpvLXNtP5du",
- "if": "!(type = \"track\")",
- "actions": [
- {
- "type": "DROP"
}
], - "title": "Allow Track",
- "description": "Allows track calls through to the destination.",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
], - "pagination": {
- "current": "MA==",
- "totalEntries": 1
}
}
}
Gets a Destination filter by id.
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.destinationFilters.getFilterInDestination('fP7qoQw2HTWt9WdMr718gn', 'xx6AySGeFExzdv2Gw2EuhV')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "filter": {
- "id": "xx6AySGeFExzdv2Gw2EuhV",
- "sourceId": "rh5BDZp6QDHvXFCkibm1pR",
- "destinationId": "fP7qoQw2HTWt9WdMr718gn",
- "if": "!(type = \"track\")",
- "actions": [
- {
- "type": "DROP"
}
], - "title": "Allow Track",
- "description": "Allows track calls through to the destination.",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Deletes a Destination filter.
• When called, this endpoint may generate the Destination 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.destinationFilters.removeFilterFromDestination('fP7qoQw2HTWt9WdMr718gn', '2c0vbGYWOBwbKszg0F0CoLSS01b')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Updates a filter in a Destination.
• When called, this endpoint may generate one or more of the following audit trail events:* Destination Filter Enabled
OK
Resource not found
Validation failure
Too many requests
{- "if": "!(type = \"track\")",
- "actions": [
- {
- "type": "DROP"
}
], - "title": "Allow Track",
- "description": "Allows track calls through to the destination.",
- "enabled": true
}
{- "data": {
- "filter": {
- "id": "xx6AySGeFExzdv2Gw2EuhV",
- "sourceId": "rh5BDZp6QDHvXFCkibm1pR",
- "destinationId": "fP7qoQw2HTWt9WdMr718gn",
- "if": "!(type = \"track\")",
- "actions": [
- {
- "type": "DROP"
}
], - "title": "Allow Track",
- "description": "Allows track calls through to the destination.",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z"
}
}
}
Simulates the application of a Destination filter to a provided JSON payload.
required | object (filter) The filter to preview. |
required | object (payload) The JSON payload to apply the filter to. |
OK
Resource not found
Validation failure
Too many requests
{- "filter": {
- "if": "type = \"track\" AND event = \"Order Completed\"",
- "actions": [
- {
- "type": "ALLOW_PROPERTIES",
- "fields": {
- "product": [
- "event",
- "requestedFrom"
]
}
}
]
}, - "payload": {
- "type": "track",
- "event": "Order Completed",
- "product": {
- "name": "Fake mustache",
- "requestedFrom": "/products/123/checkout",
- "referrer": "www.example.com"
}
}
}
{- "data": {
- "inputPayload": {
- "type": "track",
- "event": "Order Completed",
- "product": {
- "name": "Fake mustache",
- "requestedFrom": "/products/123/checkout",
- "referrer": "www.example.com"
}
}, - "result": {
- "event": "Order Completed",
- "product": {
- "requestedFrom": "/products/123/checkout"
}, - "type": "track"
}
}
}