Skip to main content
Segment

Sync your Segment groups, users, and product events to Vitally in real time with our Segment integration

Ray avatar
Written by Ray
Updated over 3 months ago

Segment Overview

Vitally's Segment integration can be used to sync the following Segment data into Vitally in real time:

  • Groups - Vitally imports your Segment groups into Vitally as accounts. The entire group object, including all your Segment traits, will be attached to your Vitally account profiles.

  • Users - Vitally imports your Segment users (i.e. your identify API calls) into Vitally as users. The entire user object, including all your Segment traits, will be attached to your Vitally user profiles.

  • Tracks - Vitally imports your Segment tracks into Vitally as product events. The entire track object, including any event properties, will be imported.

Enabling the Segment integration

To enable the Segment integration, navigate to Settings (⚙️) by selecting your Account Logo on the top left and under Operations select Integrations. Then select Segment (or via Quick Jump Mac: ⌘ + j Windows: Alt + j) to enable. When there, simply click the Connect a Segment Source button. That will redirect you to Segment, where you'll be able to select the Segment source to connect to Vitally.

Once your source is submitted, Segment will redirect you back to Vitally, where you'll see a message like this:

Before you can complete the Segment integration process in Vitally, we must receive at least 1 Segment message from your connected source. This can take a few minutes after you connect your source, even if you know messages are being sent. This occurs because Segment's CDN needs to propagate your new connection throughout its infrastructure before they route your messages to Vitally. That propagation can take several minutes to complete.

Once we receive a single Segment message, you'll see the below and will be able to configure the rest of the integration.

Creating Accounts from Segment

As Vitally is geared towards B2B companies, we must be able to associate each user to the account/customer they belong to. Segment provides 2 different APIs to achieve this result.

Default behavior

By default, if you do not use any of the options below (Group API vs Identify API), Vitally will associate the track to the account the user was last associated to. This typically works fine for customers, especially if you send a group call for the user each time they login to their account or start a session (as a group call establishes the association between the user and account).

Option #1: Group API (recommended)

The Group API enables you to identify what account or organization your users are part of. There are two IDs that are relevant in a Group call: the userId, which belongs and refers to the user, and the groupId, which belongs and refers to the specific group. Here’s the payload of a typical Group call, with Segment's most common fields removed:

{ 
"type": "group",
"groupId": "0e8c78ea9d97a7b8185e8632",
"traits": {
"name": "Initech",
"industry": "Technology",
"employees": 329,
"plan": "enterprise",
"total billed": 830
}
}

The userId is the external ID in Vitally.

And here’s the corresponding JavaScript event that would generate the above payload:

analytics.group("0e8c78ea9d97a7b8185e8632", { 
name: "Initech",
industry: "Technology",
employees: 329,
plan: "enterprise",
"total billed": 830
});

Based on the library you use, the syntax in the examples might be different. You can find library-specific documentation on the Segment's Sources Overview page.

If you use the Group API, then the only other requirement is to ensure your Group API calls have a name trait attached to them.

Using the Group API to create accounts is strongly recommended. This API is your best option for creating accounts in Vitally, as it allows you to directly define your account data in Vitally. For example, the sample API call above would provide access to the industry, employees, plan, and totalBilled traits for the account in Vitally. Additionally, any future traits your engineers add to a group API call will be automatically attached to your accounts in Vitally.

Option #2: Identify API

This is a dedicated API Segment provides that directly identifies your users. Since this API is meant to identify individual users of your product, and not necessarily the account the user belongs to, it is not recommended to use this API. The Group API is always a better option, but if you don't use the Group API, your Identify API calls must send along certain traits that specify the account.

  • Account name trait - A trait that identifies the (readable) name of the account the user belongs to (e.g. "Visa")

  • Account ID trait - A trait that specifies a unique ID for your accounts. Ideally, this value never changes for the account (e.g. "visa.com", "ed8fcc72-dbe5-4a9c-9d03-59e456462626"). This trait should pretty much always be different than yournametrait. If at all possible, the trait you select here should be the unique ID given to your accounts by your database.

  • Other account traits - Any traits attached to Identify API calls that actually relate to the account the user belongs to (e.g. the account's plan, subscription cost, industry). These traits will be attached to accounts in Vitally, allowing you to use them when analyzing accounts.

The Account ID trait you select here is very important to unifying your account data in Vitally. If you leverage our other integrations to track other customer data (e.g. Stripe), the ID you select here will also need to exist in those other tools in order for Vitally to properly unify your data under the right account.

Unlinking a user from an account in Vitally

You can disassociate a user from a company by passing in a field inside the company trait with remove: true in your identify calls.

analytics.identify({
userId: '1',
traits: {
company: {
id: 12345,
remove: true
}
}
});

Associating Tracks to Specific Accounts

If your users can belong to multiple accounts, you may have a need to specifically associate that user's tracks to the account they are logged in to. To do so, you have 3 options:

Use Context

Segment's context option supports setting groupId, and Segment's B2B SaaS spec recommends setting this for specific tracks. If you set the groupId field in your track context, Vitally will automatically associate the track to the account the groupId value references.

Use a Track Property to Reference the Account

Similar to using Segment's context, you can also specify the group ID that a track belongs to in the track's properties.

Here’s the payload of a typical Track call (using an accountId property) with Segment's most common fields removed:

{ 
"type": "track",
"event": "User Registered",
"properties": {
"plan": "Pro Annual",
"accountType" : "Facebook",
"accountId": 'ACCOUNT_EXTERNAL_ID'
}
}

And here’s the corresponding JavaScript event that would generate the above payload:

analytics.track("User Registered", { 
plan: "Pro Annual",
accountType: "Facebook",
accountId: 'ACCOUNT_EXTERNAL_ID'
});

Unlike using context, Vitally will not automatically detect the track property you use to point to the account the track belongs to, so if you head down this route, you will need to contact our support team to let us know which property you're using. We'll configure your integration to use the property you select.

Ignore Events

Segment may send many events to Vitally, some of which may not be relevant. For this reason, you will want to "ignore" any events you don't want to track in Vitally.

There are two benefits to "Ignoring" an event:

  1. Keeps your event list cleaner in the UI as there will be fewer data to sift through.

  2. This enables us to process your data as quickly as possible as we are not processing data that is not relevant to you.

To update an Event Status go to: Settings > Events > Status column

FAQs

Q: Does my historical Segment data sync to Vitally when I enable the Segment integration?

A: Unfortunately not, but simply because Segment offers no APIs for integration partners to extract your historical data from Segment. However, for those on advanced plan tiers for Segment, Segment does offer a feature to "replay" your historical data to a connected destination. If you have access to that feature, you can use it to push your historical data from Segment to Vitally.

Q: When creating Users in Vitally from Segment, should I pass the name in two separate traits as first name and last name or one full name trait?

A: We recommend sending us the User's name from Segment as full name instead of two separate traits.

Did this answer your question?