Slack Destination

Slack is a team collaboration tool where work flows. It’s where the people you need, the information you share, and the tools you use come together to get things done.

This document was last updated on January 25, 2018. If you notice any gaps, out-dated information or simply want to leave some feedback to help us improve our documentation, please let us know!

Getting Started

The first step is to make sure Slack supports the source type and connection mode you’ve chosen to implement. You can learn more about what dictates the connection modes we support here.

WebMobileServer
📱 Device-based
☁️ Cloud-based
  1. From your Segment UI’s Destinations page click on “Add Destination”.
  2. Search for “Slack” within the Destinations Catalog and confirm the Source you’d like to connect to.
  3. In your Slack custom integration settings, create a new Incoming Webhook URL by selecting a Slack channel associated with your account.
  4. Enter this in your Segment UI settings under ‘Incoming Webhook URL’. The Slack channel you selected will be the default channel which will receive events.

Identify

If you haven’t had a chance to review our spec, please take a look to understand what the Identify method does. An example call would look like:

analytics.identify('userId123', {
  name: 'John Doe',
  email: 'john.doe@segment.com'
});

Whitelisted 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 within the Segment UI under “Whitelisted Traits”, then the identify call must contain all of them in order to be sent into your Slack. Following the code example above, we can whitelist the trait names of name and email.

Identify Template

Once you’ve saved your whitelisted traits, you can now use them alongside Handlebars expressions syntax within a template. Make sure you reference the spec for the Identify method and common object. 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

Using the above code example, you can create the following template:

The user  has an email of

Which would result in the following message within your Slack channel:

The user John Doe has an email of john.doe@segment.com

Track

If you haven’t had a chance to review our spec, please take a look to understand what the Track method does. An example call would look like:

analytics.track('Email Opened', {
  name: 'John Doe',
  email: 'john.doe@segment.com'
});

Event Channels

By default, all track events are sent to the default Slack channel configured in the Segment UI when getting started. To prevent events from sending you will need to modify your track call to use selective integrations. Business Tier customers also have the option to filter the events within the “Schema” section of the Segment UI.

If you would like to have specific events be sent to a particular channel (#channel) or user (@user) via a direct message, you can specify this in the “Events Channels” settings within the Segment UI.

Event Templates

Event templates also utilize Handlebars expressions syntax. Make sure you reference the spec for the Track method and common object. 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.

The basic Track structure:

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

Using the above code example, you can enter the event name:

Email Opened

and create the following template:

 opened an email from  ()

Which would result in the following message within your Slack channel depending on how “name” was set:

Jane opened an email from John Doe (john.doe@gmail.com)

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. An example which captures all event names in both lower and upper case ending in “-ing” would look like:

/[a-zA-Z]+ing$/g

More information on regex can be found here.

Troubleshooting

Page, Identify, Group calls are not showing up

The Slack Destination does not support page or group calls. Only track events are supported by default. Remember that track.properties object is an open dictionary and may include any data you choose.

In order for identify events to work, please make sure you whitelist the traits.

I’m seeing [object Object] in my Slack message

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).


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!