Space Filters

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.

Availability

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

Permissions

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

Types of filters

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

Conditional filters

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.

Universal filters

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.

Limits

Filters currently have the following limits:

  • Each Space may have no more than 10 filters.

If you would like any of these limits lifted, please reach out to Segment at friends@segment.com.

API models

Filter

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.

Preview Filter

To simulate the application of a Space filter to a provided JSON payload, please use the Preview Destination Filter endpoint.

Create Filter for Space

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.

Securitytoken
Request
Request Body schema:
required
integrationId
required
string (integrationId)

The Space id to filter on.

enabled
boolean (enabled)

Whether the filter is enabled.

name
required
string (name)

The name of the filter.

description
string (description)

The description of the filter.

if
required
string (if)

The "if" statement for a filter.

drop
boolean (drop)

Whether the event is dropped.

dropProperties
Array of strings (dropProperties)

Describes the properties to be dropped on events that match the "if" statement.

allowProperties
Array of strings (allowProperties)

Describes the properties allowed on events that match the "if" statement.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

post/filters
Request samples
{
  • "integrationId": "<id>",
  • "name": "Test filter",
  • "if": "type = \"track\""
}
Response samples
{
  • "data": {
    }
}

List Filters for Space

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.

Securitytoken
Request
query Parameters
integrationId
required
string (integrationId)

The Space Id for which to fetch filters

This parameter exists in beta.

Example: integrationId=<id>
object (ListFiltersPaginationInput)

Pagination parameters.

This parameter exists in beta.

Example: pagination=pagination.count=3
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/filters
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Delete Filter By Id

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.

Securitytoken
Request
path Parameters
id
required
string [ 1 .. 255 ]
Example: <id>
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

delete/filters/{id}
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Get Filter By Id

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.

Securitytoken
Request
path Parameters
id
required
string [ 1 .. 255 ]
Example: <id>
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/filters/{id}
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Update Filter By Id

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.

Securitytoken
Request
path Parameters
id
required
string [ 1 .. 255 ]
Example: <id>
Request Body schema:
required
integrationId
required
string (integrationId)

The Integration id of the resource.

enabled
boolean (enabled)

Whether the filter is enabled.

name
string (name)

The name of the filter.

description
string (description)

The description of the filter.

if
string (if)

The "if" statement for a filter.

drop
boolean (drop)

Whether the event is dropped.

dropProperties
Array of strings (dropProperties)

Describes the properties to be dropped on events that match the "if" statement.

allowProperties
Array of strings (allowProperties)

Describes the properties allowed on events that match the "if" statement.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

patch/filters/{id}
Request samples
{
  • "integrationId": "<id>",
  • "if": "!(type = \"track\")",
  • "name": "Test name",
  • "enabled": true,
  • "description": "Changed description"
}
Response samples
{
  • "data": {
    }
}