Slack Destination

Segment makes it easy to send your data to Slack (and lots of other destinations). Once you've tracked your data through our open source libraries we'll translate and route your data to Slack in the format they understand. Learn more about how to use Slack with Segment.

Getting Started

Enabling Slack in Segment, you’ll be able to send event data from mobile, web and server sources to any specified channel in Slack. Using handlebars.js templating, you can control and populate the messages with data from a Track event.


Incoming Webhooks URL

In Slack app mangament, create a new Incoming Webhooks url and enter this in your settings.

Whitelist Identify Traits

By default, your .identify() calls will not be sent through to Slack unless you have whitelisted a trait and the .identify() call contains that trait. If you whitelist multiple traits, then the .identify() call must contain all of them in order to be sent into your Slack.

Identify Template

Identify events that contain the whitelisted traits will appear as a Slack message with the following default template:

Identified user {{name}}. \n{{traits}}

where “name” is the first found of the following:

  • context.traits.name
  • context.traits.firstName + context.traits.lastName
  • context.traits.username
  • properties.email
  • context.traits.email
  • User + userId
  • Anonymous user + anonymousId

When constructing a template, reference the spec for the Identify payload and common object.

Event Channels

By default, events are sent to the Slack channel selected when creating the new Incoming Webhooks in Slack.

You can override specific events to a post in a channel (#channel) or DM a user (@user).

For example, the following will post “Order Completed” events in the #orders-completed channel and Drake will be notified when the clubs are going up:

event-channel-example-1 event-channel-example-2

Track Event Templates

Note: If you’re trying to stop an event from reaching Slack, use selective integrations. Segment Business customers may optionally use UI Filtering as well.

Track events will trigger a Slack message with the following default template:

'{{name}} did {{event}}.'

where “event” is the event name and “name” is found with the same logic as that of the “name” in the Identify template.

Constructing templates

Templates follow Handlebars expressions syntax. When constructing a template, reference the spec for Track payload and common object.

The basic Track structure:

{
  "type": "track",
  "event": "Email Opened",
  "properties": {
    "plan": "Pro Annual",
    "custom" : "Bay Area",
    "name": "Peter Reinhardt"
  }
}

As an example, consider the analytics.js Track event:

analytics.track('Song Played', {
  title: 'T Shirt',
  author: 'Migos'
});

The template:

segment-slack-template

will produce:

Regex Matching

In addition to exact event names, you can also enter regex patterns for channels and templates to map multiple events to a single channel or template rather than creating a mapping for each individual event. More information on regex can be found here.

Forbidden Characters

Event names with . and properties with space character will throw silent errors in the templating engine. This may result in the default template being used or may result in the event failing to reach Slack at all.

Troubleshooting

Page, Identify, Group calls are not showing up!

Only Track events are supported by the destination at the moment. Remember that track.properties object is an open dictionary and may include any data you choose!

[object Object]

If you try to print an object (eg., {{properties}}), you will see [object Object] in Slack. Drill down to a primitive type value (eg., properties.plan).


Supported Sources and Connection Modes

WebMobileServer
📱 Device-based
☁️ Cloud-based

To learn more about about Connection Modes and what dictates which we support, see here.

Settings

Segment lets you change these destination settings via your Segment dashboard without having to touch any code.

Incoming Webhook URL

Your Slack incoming webhook URL.

Whitelisted Traits

List the traits you want to forward to Slack. If you do not list any traits, we will not forward any .identify() calls! Whitelist the traits you want catch and foward to Slack.

Event Channels

Use these fields to map your Segment event names to Nanigans event names. We’ll only send Nanigans the conversion events you specify.

Identify Template

Use “handlebarsjs” templating to format messages sent to Slack. The default template is “Identified {{name}}. {{traits}}”. You do not need to append ‘traits’, as this template is specific to .identify() calls only and thus is assumed. Make sure whatever trait you try to use in your template, you send as a trait in your .identify() calls, otherwise we will reject the message.

Event Templates

Use these fields to map your Segment event names to Slack event names. We’ll only send Slack the conversion events you specify.


If you have any questions or see anywhere we can improve our documentation, please let us know or kick off a conversation in the Segment Community!