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:
- Create a Segment account and set up the necessary sources for your customer data.
- Configure a destination for Ory Actions in the Segment Workspace.
- Get a Segment Write Key.
- 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.
- 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.
Not sure what Jsonnet is? Read the Ory Actions webhook guide.
-
First, create a Jsonnet file. It transforms the identity data from Ory to a format Segment understands:
./segment_identify.jsonnetfunction(ctx) {
userId: ctx.identity.id,
traits: {
email: ctx.identity.traits.email,
name: ctx.identity.traits.name,
newsletterConsent: ctx.identity.traits.consent.newsletter,
},
} -
To use this Jsonnet snippet, encode it to Base64 and save it to the clipboard:
cat segment_identify.jsonnet | base64 | pbcopy
-
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}"
}
} -
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-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-id} \
--add "/selfservice/flows/registration/after/password/hooks/0=$(cat webhook-action.json)" \
--format yaml