Segment is a simple analytics API that transforms business analytics data and routes it to other analytics services, such as Google Analytics, Mixpanel, KissMetrics, and Librato.

Segment Set-up

To get started with Segment create an account and follow the set up instructions. To activate the Librato integration you will need a token:

Create an API token

We recommend creating a Record Only API token specifically for this service. You can learn how in the knowledge base article about Librato API Tokens.

Copy the new API token and paste it into the appropriate field in the Librato integration.

Tracking Metrics


When you toggle on Librato in Segment, their CDN is updated within 5-10 minutes with their custom Librato provider inside analytics.js.

Since Librato only records custom events, no metrics will appear in Librato until you start using the API as outlined in their docs.

Librato supports their track method for both client-side and server-side.

For more configuration details such as API methods and how to override the source dimension, check out the Librato Integration page on Segment’s site.

NOTE: Some of the code examples on Segment’s page are incorrect. You can post multiple values in the property such as

properties: {value: 2, revenue: 14.99}

but anything other than value will be ignored. Also, to include the source dimension, use context as a parameter (Librato for Python).


Here’s some example code that uses the ruby gem that Segment provides:

require 'analytics-ruby'

Analytics = AnalyticsRuby # Alias for convenience
segment_token = 'asdfasdf' # The secret write key for my project

    secret: segment_token,
    on_error: { |status, msg| print msg }  # Optional error handler

while true
    Analytics.track(user_id: 123, writeKey: segment_token, event: 'segment.librato',
        properties: { value: rand(100) }, context: { source:'web-server-10' })
    Analytics.track(user_id: 234, writeKey: segment_token, event: 'segment.librato',
        properties: { value: rand(100) }, context: { source:'web-server-11' })
    Analytics.track(user_id: 456, writeKey: segment_token, event: 'segment.librato',
        properties: { value: rand(100) }, context: { source:'web-server-12' })
    Analytics.track(user_id: 789, writeKey: segment_token, event: 'segment.librato',
        properties: { value: rand(100) }, context: { source:'web-server-13' })
sleep (30)

This will generate a graph for one metric (segment.librato) with four sources (web-server-10...13).


You will notice that the Segment integration switches on Service-Side Aggregation (SSA) by default.

Here’s an example using Python:

userID = '12345'
analytics.track(userID, 'event', {
      'value': 1
 }, {
      'Librato': {
           'source': userID

Here’s an example using CURL:

curl \
    -d userId=123 \
    -d writeKey=segment_token \
    -d event=segment.librato \
    -d properties[value]=2 \
    -d context[source]=web-server-

Here’s an example using JavaScript:

    { value: 2 },
    { context: { source: 'custom_source' }}