Drift Events

If you'd like to send Drift events to an outside platform or customize Drift using specific events, you can use our Widget API.

Here is what we'll be covering:

First, initialize your Drift Widget

The ready event indicates that Drift widget is ready for use. It contains a single argument which is the actual API object that can then be acted upon.

<script>
drift.on('ready',function(api, payload) {
 // your code goes here
})
</script>
<script>
analytics.ready(function(){
    //interact with the api here
})
</script>

Here's a code sample, showing how to track an event using our Widget API

Let's say, you want to track that a user started a conversation & the corresponding conversation ID.
You'd want to use the startConversation event, which returns an object like this:

{
  conversationId, // the ID for the conversation
  inboxId,        // the ID for the inbox for this conversation
}

If you wanted to send this event to a platform like Google Analytics, you would need to add the Google Analytics tracking call. It would look something like the following:

drift.on('ready', function (api) {
  drift.on('startConversation', function (event) {
    // Enter Google Analytics function here
    ga('send', 'event', {
      eventCategory: 'Drift Conversations',
      eventAction: 'Started Conversation',
      eventLabel: event.conversationId,
    });
  })
})

More info on sending events to Google Analytics here.

OR integrate with GA with one click here.

Sidebar Events

sidebarOpen is the event that fires when the sidebar opens.
sidebarClose is the event that fires when the sidebar closes.

The event argument contains the same UI flags as the message event.

Event attributes:

event.data.sidebarOpen is true if the sidebar is in the open state. false if it's closed.
event.data.widgetVisible is true if the widget is visible. false if it's hidden.
event.data.isOnline is true if your organization is currently online.

The following shows an example: when the sidebarClose event is triggered, if the widget is visible, we call the hide() method.

<script> 
drift.on('ready',function(api){
  drift.on('sidebarClose',function(e){
    if(e.data.widgetVisible){
      api.widget.hide()
    }
  })
})
</script>
Conversation Sidebar

Conversation Sidebar

Welcome Message Events

welcomeMessage:open is the event that fires when the welcome message is open.
welcomeMessage:close fires when the welcome message is closed.

<script>
drift.on('welcomeMessage:open', function() {
  console.log('Welcome Message is open 🌞')
})
drift.on('welcomeMessage:close', function() {
  console.log('Welcome Message is closed 🌞')
})
</script>
Welcome Message

Welcome Message

Away Message Events

awayMessage:open is the event fired when an away message opens.
awayMessage:close is the event fired when an away message closes.

<script> 
drift.on('awayMessage:open', function() {
  console.log('Away Message is open 🌝')
})
drift.on('awayMessage:close', function() {
  console.log('Away Message is closed 🌝')
})
</script>

Playbook Events

We fire events for the campaign interactions that you see in your Playbook Reports. Your Playbooks are your targeted messages. They differ from your welcome message, which is the catch-all message that you've customized in your settings.

campaign:open fires when campaign begins.
campaign:dismiss fires when a user closes a campaign message.
campaign:click fires when a CTA is clicked.
campaign:submit fires when a user starts a chat or submits an email capture.

window.drift.on("campaign:open", function(data) {
  console.log("User opened campaign");
});

Slider Message Events

Slider Message Close- sliderMessage:close

Slider Message Close

the sliderMessage:close event fires when the slider message is closed

window.drift.on("sliderMessage:close", function(data) {
  console.log("User closed slider the slider");
});

Your event handler will receive an object with this shape:

{
  botMessage,                     // if the message closed was a bot message
  userInteractedWithConversation, // if the user has interacted with the conversation the slider message is coming from
}

Conversation Events

Conversation Started- startConversation
Message Sent - message:sent
Message Received - message
Email Captured- emailCapture
Meeting Request Sent- scheduling:requestMeeting
Meeting Booked- scheduling:meetingBooked

Conversation Started

the startConversation event fires when the user starts a new chat.

window.drift.on("startConversation", function(data) {
  console.log("User started a new conversation " + data.conversationId);
});

Your event handler will receive an object with this shape:

{
  conversationId, // the ID for the conversation
  inboxId,        // the ID for this conversation's inbox
}

User Sent a Message

The message:sent event fires when the user replies to a conversation

window.drift.on("message:sent", function(data) {
  console.log("User replied to conversation " + data.conversationId);
});

Your event handler will receive an object with this shape:

{
  conversationId, // the ID for the conversation
  inboxId,        // the ID for this conversation's inbox
}

User Received a Message

the message event fires when the user receives a message from a team member.

window.drift.on("message", function(data) {
  console.log("User received a message from ' + data.teamMember.name + ' in conversation " + data.conversationId);
});

Your event handler will receive an object with this shape:

{
  conversationId, // the ID for the conversation
  inboxId,        // the ID for this conversation's inbox
  teamMember: {   // the team member that messaged the user
    id,           // the team member's Drift ID
    name,         // the team member's name
  }
}

Email Captured

The emailCapture event fires when the user identifies through an Email Capture Campaign, completes an email capture form inside the Widget, or if they simply type their email into a message.

window.drift.on("emailCapture", function(e) {
  console.log("user identified as: " + e.data.email);
});

Meeting Request Sent

The scheduling:requestMeeting event fires when the Schedule Meeting card is pushed to a conversation. This can happen when you call the api.scheduleMeeting method, when the user tries to book a meeting through a Drift Profile, or when a member of your team shares a calendar to a conversation.

window.drift.on("scheduling:requestMeeting", function(data) {
  console.log("user wants to schedule a meeting with " + data.teamMember.name);
});

Your function will receive an object with the following shape:

{
  teamMember: {  // the team member the user wants to schedule a meeting with
    id,          // your team member's Drift ID
    name,        // your team member's name
  }
}

Meeting Booked

the scheduling:meetingBooked event fires when the user books a meeting with a member of your team.

window.drift.on("scheduling:meetingBooked", function(data) {
  console.log("user booked a meeting with " + data.teamMember.name);
});

Your function will receive an object with the following shape:

{
  teamMember: {  // the team member the user booked a meeting with
    id,          // your team member's Drift ID
    name,        // your team member's name
  },
  meeting: {
    time,        // the meeting's start time as a <a href="http://www.unixtimestamp.com/" target="_blank">UNIX timestamp</a>
    duration,    // the meeting duration in minutes
    timeZone,    // the timezone for the meeting's start time
  },
}

Drift Events