Configure a Segment.com integration (server-side)

Who can use this feature?

Segment.com libraries (sources) generate messages about what’s happening in your site or app, and send them to the Segment.com servers. Segment then translates the content of those messages into different formats for use by other tools (destinations), and sends the translated messages to those tools.

Segment.com supports most programming languages and software stacks; please reference their source catalog for more information on building an implementation that is compatible with your application stack.

This article provides code snippets in both Python and NodeJS for a server source type.

Full code samples for both Python and NodeJS are attached to the bottom of this article.

Configure a Segment.com source

First you will need to configure your application source within Segment. If you have already done this step, feel free to skip to the next section.

  1. Click on the Sources tab in the left menu and then click the Add Source button on the top right.
    mceclip1.png
  2. Search for the source that matches the language your application is written in.  This example uses a NodeJS app.
    mceclip2.png
  3. Give the source a name and click Add Source.
    mceclip3.png

Your source is now configured in Segment and ready to receive data. Copy your Write Key somewhere as you will be using this later to send data from your application.

Configure a Segment destination

Before setting up the Totango destination in Segment, you will first want to locate your Totango Service ID. Your Service ID follows a format similar to SP-12345-01. Take note of this ID; it will be used later in this section.

  1. Navigate to the Destinations tab and click Add Destination in the upper right corner.
    mceclip5.png
  2. Search for and select Totango, and then click Configure Totango.
    mceclip6.png
  3. Select the data source you configured earlier, and click Next.
    mceclip7.png
  4. Name the destination and, if prompted, select Fill in settings manually.
    mceclip9.png
  5. Click Region, and select either US or EU then enter your Totango Service ID retrieved earlier into the Service ID field.
    mceclip10.png

Remember to enable the connection by clicking on the switch next to the Destination’s name.mceclip11.png

Send data to Totango via Segment

As part of the setup, remember that every pagetrack and identify call that you want to show up in Totango must be tied to a groupId (defined in Totango as the Account ID). This is done via the group call. You must include context.groupId in every call you want to be sent through to Totango so our system can link the groupId in a call made to Segment with the associated account in Totango.

For server-side/back-end/session-less and mobile libraries, you only need to call group or identify once per session, as we will cache it and attach it to future calls to other methods for the same account. Please note that if the user and/or both the user and account change, you will need to update the userId and context.groupId via the identify and group calls again.

  • Sending Account data is done via the group call and pushes account attribute data to Totango.
  • Sending Usage data requires an identify and group call before sending the usage data to Totango via a track or page call. 

The following examples use NodeJS and Python. You are free to set this up in whatever language/environment your application uses.

See Segment’s documentation for examples using other languages.

These samples were built using the following language/library versions:

node 17.6.9
analytics-node 6.0.0

python 3.9.10
analytics-python 1.4.0

Dependencies

Start by including the Segment libraries in your application.

NodeJS

npm install --save analytics-node

Python

pip install analytics-python

Within your application, include and instantiate the Segment library. Replace the hashed (######) string with the Write Key supplied by Segment for your source.

NodeJS

var Analytics = require('analytics-node');
var analytics = new Analytics('##############');

Python

import analytics    
analytics.write_key = '###########'

Users

Segment tracks users using the Identify function. At a minimum, this function should include the following data to ensure data flows properly into Totango:

  • User ID: This data should match the User ID used to identify the user in Totango. Often times this is the user’s email address or the Salesforce contact id.
  • Name: The first and last name of the user.
  • Email: The user’s email address
  • Group ID: The Totango Account ID that the user belongs to. This field must match the Account ID used in Totango.

NodeJS

analytics.identify({
 userId: 'Batman', 
 traits: {
   name: 'Bruce Wayne',
   email: 'bwayne@gotham.city'
 },
 context: {
   groupId: 'WayneEnt'
 }
});

Python

analytics.identify(
   'Batman',
   {
       'name': 'Bruce Wayne',
       'email': 'bwayne@gotham.city'
   },
   {
       'groupId': 'WayneEnt'
   }
)

Accounts (Groups)

Groups within Segment are analogous to Accounts in Totango. The Group function is also used to add users to groups (customers to accounts).

  • User ID: This data should match the User ID used to identify the user in Totango. Often times this is the user’s email address or the Salesforce Contact ID.
  • Group ID: The Totango Account ID that the user belongs to.  This field must match the Account ID used in Totango.
  • Name: The full name of the account.

NodeJS

analytics.group({
 userId: 'Batman',
 groupId: 'WayneEnt',
 traits: {
   name: 'Wayne Enterprises'
 }
});

Python

analytics.group(
   'Batman',
   'WayneEnt',
   {
       'name': 'Wayne Enterprises'
   }
)

Usage data

Now that users and accounts are defined, you can generate a tracking request and start populating usage data. Segment offers several different types of events; for this example, let’s focus on the Track event which most closely represents a standard piece of usage data.

  • User ID: This data should match the User ID used to identify the user in Totango. Often times this is the user’s email address or the Salesforce Contact ID.
  • Event: The Activity performed by the user.
  • Category:  The module where the user performed the action.
  • Group ID: The Totango Account ID that the user belongs to. This field must match the Account ID used in Totango.

NodeJS

analytics.track({
 userId: 'Batman',
 event: 'Viewed',
 properties: {
   category: 'PoliceReport'
 },
 context: {
   groupId: 'WayneEnt'
 }
});

Python

analytics.track(
   'Batman', 
   'Viewed',
   {
       'category': 'PoliceReport'
   },
   {
       'groupId': 'WayneEnt'
   }
)

FAQs

Question: Does Segment.com support both US and EU servers?

Answer: Yes. Set up your Totango service datacenter using the Region option


Question: Where can I monitor usage data sent from Segment to Totango?

Answer: Refer to Totango's Developer Console.


 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request