• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Sending Segment events to experiments

    Read time: 2 minutes
    Last edited: Jan 04, 2023

    Overview

    This topic explains how to configure your existing Segment account to send events to LaunchDarkly experiments.

    This lets you use Segment events as custom metric events in LaunchDarkly experiments, so you can measure results immediately, without any instrumentation, code, or delays.

    After you connect LaunchDarkly and Segment, you can use the name of the existing Segment event when you create a custom metric to include it in your experiment immediately.

    Not using Segment?

    If you want to use metric events from another source, consider using our metric import API.

    Here is an image of the custom metric panel:

    A LaunchDarkly experiment custom metric with a unique name.
    A LaunchDarkly experiment custom metric with a unique name.

    Setting up the Segment Experimentation integration

    To set up the integration, you must have access to your Segment and LaunchDarkly accounts. You will need them both to connect them to each other.

    Copying your LaunchDarkly client-side ID

    To copy your LaunchDarkly client-side ID:

    1. Navigate to the Account settings page.
    2. Click the Projects tab.
    3. Click the name of the project you would like to receive events from Segment from. The Environments tab appears.
    4. Click the environment's client-side ID to copy it to your clipboard.

    Connecting Segment to LaunchDarkly

    To connect Segment to LaunchDarkly:

    1. Navigate to the Segment app's Destinations page.
    2. Click Add Destination.
    3. Find LaunchDarkly (Actions) in the Destinations Catalog.
    4. Click Configure LaunchDarkly (Actions).
    5. Choose which Segment Source should send data to the LaunchDarkly destination.
    6. Click Next.
    7. Fill in the Destination name field with the name of your choice.
    8. Click Save.
    9. Paste the client-side ID from the previous procedure into the LaunchDarkly client-side ID field.
    10. Click Save Changes.
    11. Click the Enable Destination radio button.
    12. Click Save Changes.
    13. Navigate to the Mappings tab.
    14. Click New Mapping.
    15. Click Track Event.
    16. The Edit: Track Event page guides you through the process of mapping Segment Track events to LaunchDarkly experimentation events. The default settings should be acceptable for most customers.
    17. Click Save.
    18. Repeat steps 13-17, to configure the Alias Event mapping. The default settings are acceptable for most customers.
    19. On the Mappings tab, click the radio buttons associated with the Track Event and Alias User mappings to begin sending events to LaunchDarkly.

    How the integration works

    After you connect Segment and LaunchDarkly, events from the source you choose can appear as custom metric events in LaunchDarkly experiments. This process fails if LaunchDarkly fails to recognize events Segment sends to it as Experimentation events.

    LaunchDarkly correlates the metric events sent from Segment with LaunchDarkly user keys. This correlation uses the Segment user ID, if it is present. Otherwise, the correlation uses the Segment anonymous ID.

    To register events from Segment in a LaunchDarkly experiment, you must meet the following criteria:

    • The name of the Segment event is identical to the name of the custom metric in your LaunchDarkly experiment. When the Segment event and LaunchDarkly metric have identical names, events from Segment will appear as events in the LaunchDarkly experiment with which the metric is associated.
    • The LaunchDarkly metric must be attached to a flag and the experiment must be recording. To learn how to create metrics in LaunchDarkly, read Creating metrics.

    You can associate the track event as a custom event at the time you set up a new metric. To learn more about track events, read Segment's documentation.