The drift documentation provides a different method, but it requires code level changes to your site. Drift is already sending custom events to Google Tag Managers dataLayer
, so these JavaScript event handlers are not necessary anymore. It’s likely that Drift will likely update their documentation to reflect this approach if they haven’t already.
The approach I use allows you to track all Drift events in Google Tag Manager with a single tag. It’s straight forward, easy to understand, and simple to setup. It’s also very stable when it comes to change management.
Drift Event Category
VariableCreate a new variable with the following properties:
Data Layer Variable
Drift Event Category
eventModel.event_category
This will capture any eventModel.event_category
values in the dataLayer when a custom event fires. We’ll use this to identify any custom events categorized as a “Drift Widget”.
Drift Event
TriggerAdd a new custom trigger with the following properties:
Custom Event
Drift Event
.*
Check the Use regex matching
option to match all event names. Next, set the “This trigger fires on” option to be Some Custom Events
and enter the following criteria: Drift Event Category
equals Drift Widget
.
This will fire on all custom events with “Drift Widget” set as eventModel.event_category
in the dataLayer.
dataLayer
The following events are pushed into Google Tag Manager dataLayer
automatically by Drift.
When the user clicks on a button in chat as a response to a question. As an example, you could use this for custom event tracking in an external system or triggering a particular event on your website in response to a button press with certain text during a conversation.
dataLayer.push({
event: "Button Clicked",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});
Fires for the first site visitor message in each unique conversation thread, or each distinct conversation ID.
dataLayer.push({
event: "First Interaction",
eventModel: {
event_category: "Drift Widget",
event_label: "undefined",
non_interaction: false
}
});
When the user interacts with a playbook from a greeting by clicking on the message or the widget button.
dataLayer.push({
event: "Playbook Clicked",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});
Whenever a leadbot playbook fires to a site visitor.
dataLayer.push({
event: "Playbook Fired",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: true
}
});
When the user dismisses a message from a playbook by clicking on the close button next to the message.
dataLayer.push({
event: "Playbook Dismissed",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});
When the user receives a message from a team member.
dataLayer.push({
event: "Message Received",
eventModel: {
event_category: "Drift Widget",
event_label: "Conversation: {ID}",
non_interaction: true
}
});
When the user replies to a conversation.
dataLayer.push({
event: "Message Sent",
eventModel: {
event_category: "Drift Widget",
event_label: "Conversation: {ID}",
non_interaction: false
}
});
When the user starts a new chat.
dataLayer.push({
event: "Chat Started",
eventModel: {
event_category: "Drift Widget",
event_label: "Conversation: {ID}",
non_interaction: false
}
});
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.
dataLayer.push({
event: "Email Captured",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});
Whenever a user provides a phone number in chat. Currently, it only works for US phone numbers.
dataLayer.push({
event: "Phone Number Captured",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});
When the user books a meeting with a member of your team.
dataLayer.push({
event: "Meeting Booked",
eventModel: {
event_category: "Drift Widget",
event_label: "Playbook ID: {ID}",
non_interaction: false
}
});