How to use Segment events to power Knock

This guide covers using Segment as a Knock source to bring track and identify event data from Segment into Knock to power your notifications.

Knock also provides a separate Segment extension for sending Knock notification data into Segment for use in your downstream tools.

Getting started

When using Segment as a Knock source, you also need to configure Knock as a Destination within Segment. This means you can use events coming through Segment to power actions in Knock, such as triggering a workflow.

You can start routing your Segment events to Knock by creating a source of type "Segment" in the Knock dashboard. From here, you'll be taken to the environment configuration page for the source which will give you unique URLs for each environment you have configured in Knock.

Configure a Knock destination in Segment

Use webhooks to connect to Knock. Knock does not have a first-party integration with Segment, so you will not find us in Segment's destination catalog. Instead, you'll configure the connection to Knock via a webhook destination as described below.

In your Segment workspace, navigate to the "Destinations" tab and click "Add Destination". From here, you'll find a "Webhooks" option under "Raw Data"; this is the destination type we'll use for Knock.

Once you're in the Webhooks main page, you can go to "Configure Webhooks" and select the data source that will be populating it. Give it a name like "Knock" and choose "Fill in settings manually".

In the Knock webhook you'll see "Connection Settings". Click on this and you'll see the form to paste in the URL you copied from the Knock dashboard for the desired source environment. There's no need to add headers.

Once you've done this, save the webhook and go into the "Event Tester" tab where you can send a test event to Knock to make sure it works.

Viewing Segment track events in Knock

Once your Segment destination is set up all events you trigger from the Segment source will be forwarded to Knock. Unique events will appear in your list of events under the Source so that you can set up actions to trigger your workflows.

From the source environment configuration page click the "View in environment" button on one of the source environments. You'll be taken to the Segment source in the environment you selected and you should see events sent. If you don't, try clicking the refresh button on the top of the list to refetch any incoming events.

Connecting an event to an action

Once you have an event in your source's environment you can click into it to show the list of actions it's connected to. To create a new one, click "Create action", which will bring up a selector showing your available workflows. Choose one that will be triggered when Knock receives this event.

Now you'll be able to map the properties of the incoming Segment event to the fields of the workflow. Knock will automatically key Recipients and Actor to be the incoming userId from the event payload, but you can change this to be any key under the properties field from the Segment event. Similarly, you can set the Tenant and Cancellation key to be any of these fields as well.

Using properties. To use any of the properties fields, you can access them with dot-syntax by prefixing them with data.. For example, if your payload looks like this:
and you wanted the commenter from the action to appear as the Actor in the workflow, then in the Actor field you would write data.commenter.id to supply their ID as the actor.

Committing the event action configuration

Event action configurations are stored in the commit history, just like workflows and email layouts. Once you're happy with the mapping, save it and commit it to your development environment right from the action page or from the commit page. When you're ready you can publish this event action configuration to your other environments.

Committing actions that trigger workflows. Keep in mind that when you commit your workflows to development and publish them to other environments, you'll have to do the same with your actions to make them trigger that workflow in those environments as well.

Disabling an action

Actions are automatically enabled when you create them. If you want to stop an event from triggering an action, you can go to the action page and toggle its status to "Inactive". Keep in mind that this will disable that action for the current environment only. When you're ready to trigger the action again, you can set it back to "Active".

Enabling Identify events

When Segment sends identify events, Knock will create and update user information accordingly. Knock will correctly map the id, email, phone, avatar, name, and any other custom properties over.

To enable handling of identify events, open the settings for the source in the environment. You can then enable or disable handling identify events accordingly.

A screenshot of how to toggle Knock handling Segment identify calls

Video walkthrough