Skip to main content

Segment integration with Ory Actions

Segment is a customer data platform that helps businesses unify their customer data from multiple sources into one centralized location. It provides a unified API for collecting, storing, and routing customer data to other tools, such as analytics and marketing platforms.

To integrate Segment using Ory Actions, you must complete these steps:

  1. Create a Segment account and set up the necessary sources for your customer data.
  2. Configure a destination for Ory Actions in the Segment Workspace.
  3. Get a Segment Write Key.
  4. In your Ory Network project, set up an Ory Action trigger that will send data to the Segment destination whenever a specific event occurs, for example on successful registration.
  5. Test the integration to ensure that data is correctly routed from your application to Segment.

By integrating Segment with Ory Actions, you can easily collect and route customer data to other tools, helping you to gain a better understanding of your customers and make data-driven decisions.

Configuration

In the following example, you set up an action which calls Segment's Identify API during registration to identify the user.

info

Not sure what Jsonnet is? Read the Ory Actions webhook guide.

  1. First, create a Jsonnet file. It transforms the identity data from Ory to a format Segment understands:

    ./segment_identify.jsonnet
    function(ctx) {
    userId: ctx.identity.id,
    traits: {
    email: ctx.identity.traits.email,
    name: ctx.identity.traits.name,
    newsletterConsent: ctx.identity.traits.consent.newsletter,
    },
    }
  2. To use this Jsonnet snippet, encode it to Base64 and save it to the clipboard:

    cat segment_identify.jsonnet | base64 | pbcopy
  3. Next, define the Ory Action as a JSON Object. Remember to replace the placeholders with your data.

    ./webhook-action.json
    {
    "hook": "web_hook",
    "config": {
    "auth": {
    "type": "basic_auth",
    "config": {
    "user": "$YOUR_SEGMENT_WRITE_KEY",
    "password": ""
    }
    },
    "url": "https://api.segment.io/v1/identify",
    "method": "POST",
    "body": "base64://{JSONNET_FROM_CLIPBOARD}"
    }
    }
  4. Finally, add this action to your Ory Network Project using the Ory CLI.

  • You can trigger this webhook after successful registration:

    ory patch identity-config --project <project-id> --workspace <workspace-id> \
    --add "/selfservice/flows/registration/after/hooks/0=$(cat webhook-action.json)" \
    --format yaml
  • Alternatively, you can trigger this action only when the user signs up with a password or social sign-in:

    ory patch identity-config --project <project-id> --workspace <workspace-id> \
    --add "/selfservice/flows/registration/after/password/hooks/0=$(cat webhook-action.json)" \
    --format yaml