Segment is a customer data platform (CDP) that helps you collect, clean, and control your customer data. Drift’s chat experience is all about helping businesses connect with the customers who are ready to buy. While there isn’t currently a direct integration between Segment and Drift, we can still leverage Segment’s valuable data through Drift’s browser-side API as well as inform Segment about what’s going on in Drift!
Billing Plan:
Using Drift's API is available for all Drift plans
Intended Audience:
In this Article, we'll go over:
- Getting data from Segment into Drift
- Getting data from Drift into Segment
Getting data from Segment into Drift
Through Segment’s Analytics.js javascript source, you can access data about known visitors and make it available to be ingested by other software on your website.
Segment allows you to identify users and gather data about their actions and the information they provide to you on your site. Segment’s identify calls can provide valuable insights on your customer, from core identifying information like user ID, email, phone, or name to information more specific to your business.
We can get this information into Drift to help enhance the chat experience through two core methods:
- drift.identify
- drift.setUserAttributes
Both are useful tools for giving Drift access to information on your visitors, but they have distinct timing and intended uses.
drift.identify
The drift.identify function is intended for logged-in use cases and is invoked before Drift is fully loaded.
If you’re using Drift and Segment in your own application, this is a good way to make sure both platforms have a good understanding of your end-user. With this function, you can pass an externalId to Drift upon login, so your end-user develops a more robust contact in Drift than we would see with a traditional marketing website approach. This opens up the chance for more nuanced segmentation in Drift based on attributes you gather and events you track within your app.
Here’s an example drift.identify call:
yourapp.login(...).then(yourUserObject => {
drift.identify(yourUserObject.id, { // assuming your DB
identifier could be something like a GUID or other unique ID.
email: yourUserObject.email,
name: yourUserObject.name,
age: yourUserObject.age,
// ...
})
})
With Segment, your user object will be provided by their analytics.js.
With a unique identifier + traits sourced from Segment, you can provide a robust contact to Drift that can be used to inform things like targeting and conditional branching in Drift, allowing you to personalize your messaging more specifically than you can with anonymized visitors.
In the vein of Spider-man’s Uncle Ben, "with great power comes great responsibility." Identifying your visitors programmatically leaves room for improper identification or even malicious impersonation of users. To that end, we have two requirements for using drift.Identify:
- Secure your identify calls with Signed Identities.
- Use a unique identifier
When you
secure your identify calls with Signed Identities, Drift will provide a signing key within your account that you can use to create JSON Web Tokens to prove the identify call is coming from your site. Make note to also use a unique identifier, (preferably unguessable), when passing an
externalId into Drift. That way, you can prevent accidental collision of user identities.
drift.setUserAttributes
The drift.setUserAttributes is a lighter touch and is less dependent on passing a consistent external user ID into Drift. This function is good for adding information to a Drift contact as they engage with Drift. Usually used for passing in marketing attribution information or other browser-side insights about the visitor, and is called after Drift is loaded. Here’s an example setUserAttributes call:
drift.on('ready', function() {
drift.api.setUserAttributes({
email: 'abcd@example.com',
nickname: 'John Doe',
age: 21
})
})
In this function, we’re triggering off Drift’s ‘ready’ event so we can know Drift is ready to take attributes on the visitor in the current browser session. We can pass as many attributes as we like with this call and with Segment, you can source these events from the traits you get in your analytics.identify call.
Getting data from Drift into Segment
Drift has a number of conversation events that you may want to share with Segment. From tracking conversions to understanding a history of what playbooks your customer has engaged with, these events can be easily passed to Segment via their track api call. Here’s an example:
<script>
window.drift.on("conversation:playbookFired", function(data) {
analytics.track("Playbook Fired:" + data.playbookId)
});
</script>
In the above script, we’re waiting for the playbookFired event, which indicates a playbook was shown to the visitor. In that event’s payload, we can get more specific data like the ID of the playbook and feed that into Segment. As you collect these events in Segment, you can start interacting with your customers based on what they’ve seen or done in Drift!
This article just scratches the surface on what you can pass to Drift. To discuss a potential integration strategy, reach out to your Customer Success Manager and we can help scope out the work needed and the playbook design we can use to level up your engagements!