Action Destinations are the new way to build streaming destinations on Segment.
Action Destinations were launched in December 2021 to enable customers with a customizable framework to map Segment event sources to their favorite 3rd party tools like Google Analytics.
This repository contains the Action Destination Definitions as well as a CLI to generate the scaffolding for new destinations and run unit tests. If you'd like to contribute, please review the Contributing Guide.
To begin, follow the instructions in Get Started below.
For more detailed instruction, see the following READMEs:
- Contributing Document
- Create a Destination Action
- Build & Test Cloud Destinations
- Troubleshooting
- Authentication
- Mapping Kit
- Destination Kit
- Error Handling
- Get Started
- Actions CLI
- Example Destination
- Input Fields
- Default Values
- perform function
- Batching Requests
- HTTP Requests
- Support
This is a monorepo with multiple packages leveraging lerna
with Yarn Workspaces:
packages/ajv-human-errors
- a wrapper around AJV errors to produce more friendly validation messagespackages/browser-destinations
- destination definitions that run on device via Analytics 2.0packages/cli
- a set of command line tools for interacting with the repopackages/core
- the core runtime engine for actions, including mapping-kit transformspackages/destinations-actions
- destination definitions and their actionspackages/destinations-subscriptions
- validates events against an action's subscription AST
You'll need to have some tools installed locally to build and test action destinations.
- Yarn 1.x
- Node 18.12 (latest LTS, we recommand using
nvm
for managing Node versions)
If you are a Segment employee you can directly git clone
the repository locally. Otherwise you'll want to fork this repository for your organization to submit Pull Requests against the main Segment repository. Once you've got a fork, you can git clone
that locally.
# Clone the repo locally
git clone <your fork or https://github.com/segmentio/action-destinations.git>
cd action-destinations
npm login
yarn login
# Requires node 18.12.1, optionally: nvm use 18.12.1
yarn --ignore-optional
yarn bootstrap
yarn build
yarn install
# Run unit tests to ensure things are working! For partners who don't have access to internal packages, you can run:
yarn test-partners
# For segment employees, you can run:
yarn test
In order to run the CLI (./bin/run
), your current working directory needs to be the root of the action-destinations
repository.
# see what's supported by the CLI
./bin/run --help
# scaffold a new destination
./bin/run init
# scaffold a new action within a destination
./bin/run generate:action <ACTION_NAME> <browser|server>
# generates TypeScript definitions for an integration
./bin/run generate:types
# start local development server
./bin/run serve
For specific information about each CLI command, please refer to this README.
For instructions on how to create a new integration, see the Create a new Destination Action docs.
If a CLI command fails to work properly, run the command with DEBUG=*
at the beginning (e.g. DEBUG=* ./bin/run serve
). This will produce a verbose debugging output, providing hints as to why something isn't working as expected. All of the CLI commands are also in the ./packages/cli/src/commands
directory if you need to inspect them further.
Refer here for more information about testing your destination actions.
Pass the Node flag --inspect
when you run the local server, and then you can attach a debugger from your IDE. The serve
command will pass any extra args/flags to the underlying Node process.
Action destinations are configured using a single Destination setting (subscriptions
) that should contain a JSON blob of all subscriptions for the destination. The format should look like this:
[
{
"subscribe": "<fql query>",
"partnerAction": "<actionSlug>",
// See ./packages/core/src/mapping-kit/README.md for documentation. The keys in this object should match the `action.fields`
"mapping": { ... }
}
]
Here's a full example:
[
{
"subscribe": "type = 'track'",
"partnerAction": "postToChannel",
"mapping": {
"text": {
"@template": "Tracked! event={{event}}, {{properties.text}}"
},
"url": "https://hooks.slack.com/services/0HL7TC62R/0T276CRHL/8WvI6gEiE9ZqD47kWqYbfIhZ",
"channel": "test-channel"
}
},
{
"subscribe": "type = 'identify'",
"partnerAction": "postToChannel",
"mapping": {
"text": {
"@template": "User identified! email={{email}}"
},
"url": "https://hooks.slack.com/services/0HL7TC62R/0T276CRHL/8WvI6gEiE9ZqD47kWqYbfIhZ",
"channel": "test-channel"
}
}
]
In your destination’s folder, you should see this general structure. The index.ts
file (with the asterisk) is the entry point to your destination - the CLI expects you to export a destination definition there.
$ tree packages/destination-actions/src/destinations/slack
packages/destination-actions/src/destinations/slack
├── generated-types.ts
├── index.ts (*)
└── postToChannel
├── generated-types.ts
└── index.ts