• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL
CLOSE
launchdarkly.com

EDIT ON GITHUB

Segment

Read time: 2 minutes
Last edited: May 29, 2020

Overview

This topic explains how to create and test a Segment destination for data export.

Prerequisites

There are two prerequisites to configure the Segment integration:

  • You must add the LaunchDarkly Source in Segment
  • You must find the Write Key for your Segment account

First, add the LaunchDarkly Source in Segment. To add the source, read Segment's documentation.

Next, configure the Segment integration in LaunchDarkly. To do this, you need the Write Key from your Segment account.

To find the write key:

  1. Log into Segment and navigate to your project
  2. Navigate to Sources and select your LaunchDarkly source
  3. Select API Keys on the Source integration's menu bar
  4. Copy the Write Key as shown in the text box

The API Keys section of Segment's UI.
The API Keys section of Segment's UI.

Creating a Segment destination in LaunchDarkly

To create the Segment destination:

  1. Navigate to the Integrations screen.
  2. Click on the Segment icon or, if this is not your first destination, click the Add Destination drop down.
  3. Choose Segment from the dropdown. The "Create a destination" screen appears.
  4. (Optional) Give your integration a human-readable Name.
  5. Choose an Environment for this integration to apply to.
  6. Enter the Segment Write key.
  7. Click Save Destination. The new integration appears in the list of integrations.

The "Create a Destination" screen.
The "Create a Destination" screen.

Testing a Segment destination

After you create a Segment destination for data export, you can confirm that it's working correctly in the "Edit destination screen."

To test the Segment destination:

  1. Navigate to the Integrations screen.
  2. Find the Segment destination and click Edit. The "Edit destination" screen opens.
  3. Click Send Event in the "Send a test event" section.

The Send a test event section of the Edit destination screen.
The Send a test event section of the Edit destination screen.

  1. Verify the event appears in the Segment Debugger.

Example events

These example events display the structure of the events LaunchDarkly sends to Segment.

LaunchDarkly sends events in the following formats:

1{
2 "event": "feature",
3 "integrations": {},
4 "messageId": "c2f7a2d1-0a1b-456f-8e9a-16756e7a6db5",
5 "originalTimestamp": "2019-09-13T21:20:18.114Z",
6 "properties": {
7 "default": "true",
8 "environment": "5d4b12345d2a2806bd2cc6eb",
9 "eventId": "5d7c12345a51a0006e16ae5",
10 "flagVersion": 42,
11 "key": "EXAMPLE-FLAG-KEY",
12 "prereqOf": "EXAMPLE-PARENT-FLAG",
13 "project": "5744c12345c9900708000001",
14 "reasonKind": "FALLTHROUGH",
15 "value": "EXAMPLE-FLAG-VALUE",
16 "version": 1
17 },
18 "receivedAt": "2019-09-13T21:20:19.406Z",
19 "sentAt": "2019-09-13T21:20:19.366Z",
20 "timestamp": "2019-09-13T21:20:18.153Z",
21 "type": "track",
22 "userId": "EXAMPLE-USER-ID",
23}
1{
2 "event": "click",
3 "integrations": {},
4 "messageId": "18925338-0a1b-4521-a36a-c8e9839e4593",
5 "originalTimestamp": "2019-09-13T21:21:43.114Z",
6 "properties": {
7 "environment": "5d4b12345d2a2806bd2cc6eb",
8 "eventId": "5d7c123a86f26000065862da",
9 "key": "EXAMPLE-FLAG-KEY",
10 "project": "5744c98765c9900708000001",
11 "selector": "btn",
12 "url": "http://example.com",
13 "version": 1
14 },
15 "receivedAt": "2019-09-13T21:21:46.415Z",
16 "sentAt": "2019-09-13T21:21:46.375Z",
17 "timestamp": "2019-09-13T21:21:43.154Z",
18 "type": "track",
19 "userId": "EXAMPLE-USER-ID",
20}
1{
2 "event": "custom",
3 "integrations": {},
4 "messageId": "d747a382-0a1b-41d5-b9a6-7ae9b93925bc",
5 "originalTimestamp": "2019-09-13T21:21:58.114Z",
6 "properties": {
7 "environment": "5d4b12345d2a2806bd2cc6eb",
8 "eventId": "5d7c123452db400061b14dd",
9 "key": "EXAMPLE-EVENT-KEY",
10 "project": "5744c12345c9900708000001",
11 "version": 1
12 },
13 "receivedAt": "2019-09-13T21:22:00.673Z",
14 "sentAt": "2019-09-13T21:22:00.393Z",
15 "timestamp": "2019-09-13T21:21:58.393Z",
16 "type": "track",
17 "userId": "EXAMPLE-USER-ID",
18}
1{
2 "integrations": {},
3 "messageId": "8c235148-0a1b-4428-a4de-00b90adf2833",
4 "originalTimestamp": "2019-09-13T21:19:43.114Z",
5 "properties": {
6 "environment": "5d123454d2a2806bd2cc6eb",
7 "eventId": "5d7c12345db400061b14c1",
8 "key": "EXAMPLE-FLAG-KEY",
9 "project": "5744c123459900708000001",
10 "url": "http://example.com",
11 "version": 1
12 },
13 "receivedAt": "2019-09-13T21:19:45.371Z",
14 "sentAt": "2019-09-13T21:19:45.331Z",
15 "timestamp": "2019-09-13T21:19:43.154Z",
16 "type": "page",
17 "userId": "EXAMPLE-USER-ID",
18}

Enabling data export for flags and environments

After you create a data export destination, you must start sending flag or environment event data to it. You can enable data export for individual flags, or for all the flags in an environment.

To learn more about exporting event data from flags and environments, read Exporting event data for flags and environments.

Deleting a Segment destination

You can delete a data export destination from the Integrations screen.

To delete a destination:

  1. Navigate to the Integrations screen.
  2. Find the destination you wish to delete and click Edit. The "Create a destination" screen opens.
  3. Click Delete Destination.

The Delete destination section.
The Delete destination section.