Drift Segment Source Integration

Contents

Description

The Drift Segment Source integration sends Identify and Track calls to your instance of Segment when certain events occur within your instance of Drift. These events include:

  • new_conversation
  • button_clicked
  • conversation_push
  • contact_updated
  • new_meeting
  • meeting_updated
  • conversation_participant_removed
  • conversation_participant_added
  • playbook_goal_met
  • phone_captured

Anonymous Id

All events shared from Drift to Segment will be associated with a Segment anonymousId. The value passed to Segment for the anonymousId is equal to the contact Id created automatically by Drift when a site visitor first begins a conversation in Drift. This Id can be found in the URL of the Drift web app, when viewing a Drift contact’s details such as: https://app.drift.com/contacts/details/21761149107, where 21761149107 is the Drift assigned contactId. Note, this value is different than the externalId used with the client-side drift.identify() method. If using the Drift developer API to retrieve a contact record, either the contactId shown here or the externalId may be used.

Setup

The only requirements to implement this integration are a Drift Admin account and a Segment write key. While logged into your Drift account as an Admin, navigate to the Integrations settings page and find the App tile titled Segment Source. Click on the tile. Authorize the app. In addition to receiving webhooks from your instance of Drift listed above, the app is scoped to allow the reading of Contacts and Conversations. After authorizing the app, enter your Segment write key. If successful, your browser will be redirected to the Drift Integrations settings page where you should have the Drift Source app installed.

Event Details

Each event listed above sends a payload of data to your instance of Segment. The details described below are the data added by the Drift integration in each payload. Default properties included by Segment are not detailed here but more information can be found here.

📘 Editing Payloads

At this time this integration does not allow for the customization of the payloads sent to Segment.

New Conversation

The new_conversation event fires when a site visitor engages with a welcome message type playbook. A Track call to Segment is made with the following additional data:

{
  "anonymousId": "21760538950",
  "event": "Drift Source Event: new_conversation",
  "properties": {
    "contactId": 21760538950,
    "createdAt": 1714419312425,
    "id": 3969707702,
    "inboxId": 642330,
    "relatedPlaybookId": 2750462,
    "status": "open",
    "updatedAt": 1714419312429
  },
}

Button Clicked

The button_clicked event fires when a site visitor clicks on any button in a Drift Chat. A Track call to Segment is made with the following additional data. Note, the body property will contain the string value of the button text from the button clicked by the site visitor.

{
  "anonymousId": "21760538950",
  "event": "Drift Source Event: button_clicked",
  "properties": {
    "body": "Yes please!",
    "contactId": 21727759090,
    "conversationId": 3969705403,
    "href": "https://dpease-test-drift.surge.sh/",
    "ip": "172.112.186.190",
    "locale": "en-US",
    "location": {
      "city": "Los Angeles",
      "country": "US",
      "countryName": "United States",
      "latitude": 34.038,
      "longitude": -118.4544,
      "postalCode": "90025",
      "region": "California"
    }
  }
}

Conversation Push

The conversation_push event fires when a Drift conversation is closed, manually synced, or becomes inactive. A Track call to Segment is made with the following additional data:

{
  "anonymousId": "21760538950",
  "event": "Drift Source Event: conversation_push",
  "properties": {
    "contactId": 21760538950,
    "conversationId": 3969707702,
    "createdAt": 1714419312425,
    "id": 3969707702,
    "inboxId": 642330,
    "participants": [
      2322756
    ],
    "pushedAt": 1714421087350,
    "relatedPlaybookId": 2750462,
    "source": "conversation_manual_push",  //or "conversation_inactive"
    "status": "closed",
    "updatedAt": 1714419467246,
    "userId": 2322756
  }
}

Contact Updated

The contact_updated event fires when a Drift contact attribute is captured or updated. An Identify call to Segment is made with the following additional data.

📘 Segment Traits

The properties included under the “traits” property will include all Drift contact attributes that were updated.

{
  "anonymousId": "21760538950",  
  "traits": {
    "_classification": "Engaged",
    "contactId": 21760538950
  }
}

New Meeting

The new_meeting event fires when a meeting is scheduled through a Drift scheduling interface. A Track call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "properties": {
    "agentId": 2322756,
    "conferenceType": "NONE",
    "contactId": 21760538950,
    "conversationId": 3969707702,
    "eventId": "48maqmxxxxxxxmpefra84",
    "isOrgSlug": false,
    "isPrivate": false,
    "isRecurring": false,
    "meetingSource": "PLAYBOOK_DROP",
    "orgId": 5000883,
    "scheduledAt": 1714422076000,
    "schedulerId": 21760538950,
    "slotEnd": 1714483800000,
    "slotStart": 1714482000000,
    "slug": "Mrgxxxxx80u",
    "status": "ACTIVE",
    "updatedAt": 0
  }
}

Meeting Updated

The meeting_updated event fires when a Drift scheduled meeting is rescheduled or deleted by a meeting host. A Track call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "properties": {
    "agentId": 2322756,
    "contactId": 21760538950,
    "eventId": "48maqmxxxxxxxmpefra84",
    "eventType": "canceled",
    "scheduledAt": 1714422429411,
    "schedulerId": 21760538950,
    "slotEnd": 1714483800000,
    "slotStart": 1714482000000,
    "updatedAt": 0
  }
}

Conversation Participant Removed

The conversation_participant_removed event fires when a participant in a Drift conversation leaves the conversation. A Track call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "properties": {
    "changedAt": 1714422585416,
    "contactId": 21760538950,
    "conversationId": 3969707702,
    "removedParticipants": [
      2322756
    ]
  }
}

Conversation Participant Added

The conversation_participant_added event fires when a Drift agent joins a Drift either manually or via automated routing rules. A Track call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "properties": {
    "addedParticipants": [
      2322756
    ],
    "changedAt": 1714422673598,
    "contactId": 21760538950,
    "conversationId": 3969707702
  }
}

Playbook Goal Met

The playbook_goal_met event fires when a site visitor reaches a Playbook Goal node in their current Drift conversation. A Track call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "properties": {
    "contactEmail": "",
    "contactId": 21761135799,
    "conversationId": 3969735985,
    "goalId": "9c4b20ca-3d55-46bd-8a46-ccdd3982681d",
    "goalName": "Bad Lead",
    "playbookId": 2310900,
    "playbookName": "Your Playbook Name"
  }
}

Phone Captured

The phone_captured event fires when a site visitor or agent provides the site visitor’s telephone number. An Identify call to Segment is made with the following additional data.

{
  "anonymousId": "21760538950",  
  "traits": {
    "contactId": 21761149107,
    "phone": "5555555555"
  }
}

Client Side Events

This integration will automatically subscribe your Segment instance to all of the events listed above. Additional Drift events can be sent to Segment via client-side javascript that must be added to your site in addition to the standard install snippet for the Drift widget. Exact implementation details will depend on your company’s webpage design and infrastructure, however the following is intended to serve as a guide to assist with any custom implementation.

Retrieve the AnonynmousId

In order to provide a consistent method for identifying site visitors when data is passed to Segment, client-side events should rely on the Drift contactId when available. A contactId is first made available when a conversation is started. Once known, this value can be passed to Segment via the analytics.js SDK. Then all subsequent track calls to Segment from the browser will be associated with the same contactId as the one used with the integration events described in the sections above.

analytics.setAnonymousId(data.authorId);

Code Example

A full example of how to include client side event tracking along with your standard Drift installation snippet is included below. Generally, this javascript should be added to the section of your website.

<!--Segment Tracking snippet-->

  <script>
    !function () {
      var analytics = window.analytics = window.analytics || []; if (!analytics.initialize) if (analytics.invoked) window.console && console.error && console.error("Segment snippet included twice."); else {
        analytics.invoked = !0; analytics.methods = ["trackSubmit", "trackClick", "trackLink", "trackForm", "pageview", "identify", "reset", "group", "track", "ready", "alias", "debug", "page", "once", "off", "on", "addSourceMiddleware", "addIntegrationMiddleware", "setAnonymousId", "addDestinationMiddleware"]; analytics.factory = function (e) { return function () { if (window.analytics.initialized) return window.analytics[e].apply(window.analytics, arguments); var i = Array.prototype.slice.call(arguments); i.unshift(e); analytics.push(i); return analytics } }; for (var i = 0; i < analytics.methods.length; i++) { var key = analytics.methods[i]; analytics[key] = analytics.factory(key) } analytics.load = function (key, i) { var t = document.createElement("script"); t.type = "text/javascript"; t.async = !0; t.src = "https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js"; var n = document.getElementsByTagName("script")[0]; n.parentNode.insertBefore(t, n); analytics._loadOptions = i }; analytics._writeKey = "REPLACE_WITH_YOUR_WRITE_KEY";; analytics.SNIPPET_VERSION = "4.16.1";
        analytics.load("REPLACE_WITH_YOUR_LOAD_ID");
        analytics.page();
      }
    }();
  </script>

  <!-- Beginning of Drift Snippet -->

  <script>
    "use strict";

    !function () {
      var t = window.driftt = window.drift = window.driftt || [];
      if (!t.init) {
        if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
        t.invoked = !0, t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"],
          t.factory = function (e) {
            return function () {
              var n = Array.prototype.slice.call(arguments);
              return n.unshift(e), t.push(n), t;
            };
          }, t.methods.forEach(function (e) {
            t[e] = t.factory(e);
          }), t.load = function (t) {
            var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
            o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
            var i = document.getElementsByTagName("script")[0];
            i.parentNode.insertBefore(o, i);
          };
      }
    }();
    drift.SNIPPET_VERSION = '0.3.1';

//wait for Segment to load
    analytics.ready(function () {

	//load Drift with your unique embedId
      drift.load('REPLACE_WITH_YOUR_EMBED_ID');
      drift.on('ready', function (api, payload) {
        console.log("Drift ready.")

        window.drift.on("conversation:firstInteraction", function (data) {
          console.log("conversation:firstInteraction", data);
   //Set the Drift contactId as the Segment anonymousId as soon as possible
          analytics.setAnonymousId(data.authorId);
          analytics.track("Drift Source Event: conversation:firstInteraction", {
            conversationId: data.conversationId,
            playbookId: data.playbookId,
            campaignId: data.campaignId,
            contactId: data.authorId
          });
        })

        window.drift.on("startConversation", function (data) {
          console.log("startConversation", data);
          //Set the Drift contactId as the Segment anonymousId as soon as possible
          analytics.setAnonymousId(data.endUserId);
          analytics.track("Drift Source Event: startConversation", {
            conversationId: data.conversationId,
            inboxId: data.inboxId,
            contactId: data.endUserId,
            email: data.endUserEmail
          });
        })

        window.drift.on("conversation:selected", function (data) {
          console.log("conversation:selected", data);
          analytics.track("Drift Source Event: conversation:selected", {
            driftConversationId: data.conversationId
          });
        })

        window.drift.on("scheduling:requestMeeting", function (data) {
          console.log("scheduling:requestMeeting", data);
          analytics.track("Drift Source Event: scheduling:requestMeeting", {
            driftTeamMemberId: data.teamMember.id,
            driftTeamMemberName: data.teamMember.name
          });
        })

        window.drift.on("conversation:playbookFired", function (data) {
          console.log("conversation:playbookFired", data);
          analytics.track("Drift Source Event: conversation:playbookFired", {
            playbookId: data.playbookId,
            campaignId: data.campaignId
          });
        })

        window.drift.on("conversation:playbookClicked", function (data) {
          console.log("conversation:playbookClicked", data);
          analytics.track("Drift Source Event: conversation:playbookClicked", {
            playbookId: data.playbookId,
            campaignId: data.campaignId
          });
        })

        window.drift.on("conversation:playbookDismissed", function (data) {
          console.log("conversation:playbookDismissed", data);
          analytics.track("Drift Source Event: conversation:playbookDismissed", {
            playbookId: data.playbookId,
            campaignId: data.campaignId
          });
        })


        window.drift.on("campaign:open", function (data) {
          console.log("campaign:open", data);
          analytics.track("Drift Source Event: campaign:open", {
            campaignId: data.campaignId
          });
        })

        window.drift.on("campaign:dismiss", function (data) {
          console.log("campaign:dismiss", data);
          analytics.track("Drift Source Event: campaign:dismiss", {
            campaignId: data.campaignId
          });
        })

        window.drift.on("campaign:click", function (data) {
          console.log("campaign:click", data);
          analytics.track("Drift Source Event: campaign:click", {
            campaignId: data.campaignId
          });
        })

        window.drift.on("campaign:submit", function (data) {
          console.log("campaign:submit", data);
          analytics.track("Drift Source Event: campaign:submit", {
            campaignId: data.campaignId
          });
        })

        window.drift.on("sliderMessage:close", function (data) {
          console.log("sliderMessage:close", data);
          analytics.track("Drift Source Event: sliderMessage:close", {
            campaignId: data.campaignId,
            playbookId: data.playbookId
          });
        })
      })
    })
  </script>