Direct Destinations

With a Direct destination, Segment will forward all of the incoming data for our mutual customers to your service’s HTTPS endpoint in realtime.

A Direct destination gives you complete control over how you want to store, transform and process the data. It means that our mutual customers can immediately start sending you data from any one of Segment’s sources, including a web browser, mobile apps, or from our mutual customer’s servers — with no added work. Segment Enterprise customers can also replay historical data, which means you can demonstrate the value of your tool rapidly.

Becoming a Direct Partner is a quick five-step process. By starting or continuing this process, you agree to the Segment Platform Partners Agreement.

Five-step Process:

  1. Complete the destination survey.
  2. Build an endpoint to receive customer data.
  3. Test your destination.
  4. Submit your technical survey for review.
  5. Private Beta.

1. Complete the destination survey

Complete a destination survey so we know you’re building an destination and can support you.

Please do not move forward in the process until you hear back from our Partners team.

2. Build an endpoint to receive customer data

The following sections outline what kind of requests and data we send to you, and what we expect in return.

Accepting Segment Data

In order to receive data from Segment, you will need a server ready to accept HTTPS requests. You’ll give us a static endpoint to send data to, and that endpoint must:

  • Accept POST requests. Segment will send customer data to the endpoint you designate in POST requests.
  • Accept JSON data. This is the format Segment sends data to you in.
  • Use HTTPS. Segment transmits potentially sensitive data on behalf of customers, and using HTTPS goes a long way toward making sure their data stays safe.

Authorization

Segment will send your user’s API key with requests, which you can then use to authenticate requests. Note: This is the API key you give to your users; it is not a Segment API key.

Segment will send the key in the Authorization header using the Basic authentication type. It will be Base64 encoded, with your user’s API key as the username and an empty password.

For example, if your user’s API key was segment, Segment would Base64 encode the string 'segment:' and prepend the string 'Basic '.

Note: The colon is always present, even when the password is absent.

This would result in a final string of 'Basic c2VnbWVudDo='. This is what is contained in the Authorization header. You will need to decode the string when you receive it, just like any Authorization header.

See the headers section for more details.

Headers

Segment will send you the following HTTP headers with all requests:

HeaderDescriptionExample
AcceptSegment accepts any content type, but ignores responses unless this header is set to application/json.Accept: */*
AuthorizationSegment will send you your user’s API token in this header, with the Basic authentication type.Authorization: Basic c2VnbWVudDo=
Cache-ControlEach request Segment sends you is a new event, and so Segment expects you to not implement caching on your end.Cache-Control: no-cache
ConnectionSegment uses HTTP/1.1’s keep-alive functionality whenever possible (but you don’t have to).Connection: Keep-Alive
Content-LengthSegment will always send you the length of the request in bytes.Content-Length: 348
Content-TypeSegment indicates the type of data sent to you (this will always be JSON), along with Segment’s vendor type.Content-Type: application/json
User-AgentSegment will send you this field every time. You can count on us!User-Agent: Segment

Request Body

Segment’s spec standardizes the data that you can expect from Segment. You can choose to implement four types types of calls:

  • Who is this? .identify(userId, traits)
  • What are they doing? .track(userId, event, properties)
  • Where are they doing it? .page(userId, pageName, properties)
  • What group are they part of? .group(userId, groupId, groupTraits)

For example, you may want to implement the .identify(userId, traits) call to create contacts in an email marketing application. You can expect the following customer information as a JSON object in the call body

{
  "anonymous_id": "1234",
  "context": {
    "ip": "8.8.8.8",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36"
  },
  "message_id": "022bb90c-bbac-11e4-8dfc-aa07a5b093db",
  "received_at": "2015-02-23T22:28:55.387Z",
  "sent_at": "2015-02-23T22:28:55.111Z",
  "traits": {
    "name": "John Doe",
    "email": "john.doe@email.com",
    "plan": "premium",
    "logins": 5
  },
  "type": "identify",
  "user_id": "5678",
  "version": "1.1"
}

To learn more about these four API calls we support, and the semantic fields and event names we recognize, please follow the Segment spec for all contributions.

Formatting

Segment allows users to send their data formatted using the conventions of their host language; in a user’s Ruby code, they can use snake_case, while in their JavaScript code they can use camelCase.

To make integrating with Segment easy, we send you all keys in snake_case. For example, when a user sends us this JSON:

{
  "address": {
    "city": "Newport Coast",
    "postalCode": "92606",
    "state": "CA",
    "street": "1 Lucille Lane"
  },
  "CreatedAt": "1967-12-14T08:00:00.000Z",
  "NAME": "Michael Bluth",
  "user_id": 12345
}

We will send you:

{
  "address": {
    "city": "Newport Coast",
    "postal_code": "92606",
    "state": "CA",
    "street": "1 Lucille Lane"
  },
  "created_at": "1967-12-14T08:00:00.000Z",
  "name": "Michael Bluth",
  "user_id": 12345
}

Responding to Segment

This section defines how you should respond to Segment requests.

Status Code

Segment uses standard HTTP status code conventions to help us diagnose problems quickly and give better insight into how the destination is working.

Upon receiving data, your endpoint should reply with one of the following status codes:

CodeReason
200You’ve accepted and successfully processed the message.
202You’ve accepted the message, but have not yet processed it.
400The message is malformed, or otherwise contains an error that is the client’s fault.
401The client’s API key is malformed, or has expired or is otherwise no longer valid.
403The client’s API key is valid but has been rejected due to inadequate permissions.
500If you encounter an internal error when processing the message, reply with this code. (Hopefully you don’t have to send too many of these.)
501If Segment sends you a call type (indicated by the type property included on all messages) you don’t support, reply with this code. Read more about the API call types Segment supports here.
503Send Segment this code when your endpoint is temporarily down for maintenance or otherwise not accepting messages. This will help Segment avoid dropping users’ messages during your downtime.

Response Body

You can normally send back an empty body, but when sending back a 4xx- or 5xx-class error, you may optionally send Segment a diagnostic message that explains the error. This message will be displayed to the user in the Segment debugger.

Be sure to send JSON (and set your Content-Type header to application/json), and send your message in the message property.

Here’s an example of a 401 response that would help a user track down why their calls aren’t appearing in your tool’s UI:

{
  "message": "API token expired"
}

Or, if your tool requires an email address in order to accept calls, this 400 reply:

{
  "message": "Missing email address"
}

3. Test your destination

Once you’ve understood the Segment data spec and the requirements above, you’re ready to start testing your destination!

The good news is Segment provides test data. You can ping spec.segment.com and tell Segment which type of test call you want.

To retrieve a test identify call for example:

curl -H "Accept: application/json; version=2.0" \
     https://spec.segment.com/generate/identify?pretty=true

You can then send this data directly to your endpoint (be sure to replace YOUR_API_KEY with test credentials for your API):

curl -H "Accept: application/json; version=2.0" \
     https://spec.segment.com/generate/identify | \
curl -X POST \
     --user "YOUR_API_KEY:" \
     -H "Content-Type: application/json" \
     -d @- \
     http://api.your-endpoint.com/segment

4. Submit your technical survey for review

Once you’ve tested your endpoint successfully, complete the Direct Destination Application. This is a short application that helps Segment gather the essentials to get you onto our platform.

Due to the high volume of requests, it may take up to a week for Segment to review your application.

5. Private Beta

After the Segment team has reviewed and approved your application and destination, you will be placed in Private Beta. The purpose of Private Beta is to test the destination with at least 10 mutual customers or more than 20MM events. You will remain in Private Beta until you have fulfilled this criteria.

When you have completed the requirements of Private Beta, you will be launched onto the platform in Public Beta. From this point on, you will be visible to all Segment customers in the dashboard!

FAQ

How do customers collect data?

A mutual customer will use analytics.js (our client-side javascript library), a server-side library, or one of our mobile SDK’s to implement our api methods. For more information on Segment libraries, you can refer to our source documentation.

Does Segment automatically collect any data?

Only our analytics.js and mobile SDK’s collect contextual information from the device. Our server-side libraries do not collect contextual information, and a user is responsible for sending additional context themselves.

For more info on our automatically collected fields, please refer to this document.

How does Segment handle unique users?

For known users, a Segment customer will implement an identify method to collect info on the user. This can be a moment in the user flow where a user logs in, registers, updates their info, or provides any type of identifiable information. A known user will have a userId, which is up to the customer to create and send.

For unknown users, Segment will handle generating a unique anonymousId via our client-side libraries: analytics.js, analytics-android and analytics-ios, and pass this in through all of Segment’s api calls. This value is determined by the client cookie on our analytics.js library, and via the deviceId in our mobile SDKs.

Segment handles cacheing these values on our mobile SDKs and client-side analytics.js library and sending the values on subsequent calls. Our server-side libraries rely on the customer creating either the anonymousId or userId and passing this in on each call.

Read more about our unique Id’s here.

Do you have semantic events?

Yes!

To start, a Segment customer will track their user actions using our track method. Segment has industry specs to define semantic naming to follow, so when sending events in for a particular event flow, such as Ecommerce, Live Chat, Video and Email events, Segment can translate these semantic event names into other downstream tools.

It is essential that the destination follows the relevant industry specs when translating a Segment event into how the destination tool understands the event. That way, customers can enable any new integration and specced events, such as “Order Completed”, and it will automatically work with the new downstream destination.

What if the partner API does not merge known and unknown users?

If a downstream partner does not have the ability to merge known and unknown users, a Segment user will need to mark the moment a user becomes known with an alias method. This method accepts a previousID and userID so Segment can tell the downstream tool to merge the two identities.

Please note that this is an advanced call, and we generally try to stay away from having our mutual customers implement this.

Are the events guaranteed to send in order?

No. Since Segment queues events, Segment cannot guarantee the order in which the event is delivered to your endpoint.

Does Segment de-dupe messages?

Yes! Segment de-dupes messages by messageId.

Segment maintains a sliding window of all messageIds received for each source, only allowing messageIds through that do not already appear within the window.

Segment guarantees this window to be at least 24 hours of messages (meaning any message sent twice within 24 hours will be de-duped), but in practice, this window is significantly larger(currently sitting at around 170 days).

You can read more here.

What is a replay?

Segment stores a backup for our Enterprise clients in order to give them the ability to replay data into downstream destinations.

Generally, the conditions required to replay data are:

  1. The partner API accepts a concept of a timestamp.
  2. Order of events does not matter.
  3. The API does not rate-limit events.
  4. Any other potential caveats to receiving historical events.

Be sure to let us know if you are able to accept replays.

What are Segment’s deliverabilty guarantees?

Segment provides excellent data deliverability by employing API layer scalability and durability, data backup and replay, partner API monitoring, and library and integration cloud retries. Segment’s API processes 170B+ billion calls per month across over a billion of monthly tracked users, is rate performant (avg. load 100,000 msg/sec), fully automated and scalable, can tolerate massive data spikes.

Segment monitors hundreds of partner APIs for 500s, success rate, and end-to-end latency to help our customers proactively achieve the best data deliverability possible.

You can subscribe to updates here.

Does Segment retry data?

Segment retries nine times over the course of four hours. This will increase the number of attempts for messages, so we’ll try and re-deliver them another 4 times after some backoff.

We don’t retry anywhere which is the sign of an expired API key or failed payment. However, if we push bad code that results in a malformed payload and a 400 or 422 response from an endpoint, we also won’t retry given that the call would not ever succeed.


If you have any questions or see anywhere we can improve our documentation, please let us know or kick off a conversation in the Segment Community!