Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drift Data Layer Events
// Read more on the blog posts: https://trevorfox.com/2019/01/drift-event-tracking-google-tag-manager/
// Data Layer event values to be pushed according to their driftEventName
var driftEvents = [
{driftEventType: 'sidebar', driftEventName: 'sidebarOpen', driftEventDescription: 'sidebar opened'},
{driftEventType: 'sidebar', driftEventName: 'sidebarClose', driftEventDescription: 'sidebar closed'},
{driftEventType: 'welcome message', driftEventName: 'welcomeMessage:open', driftEventDescription: 'welcome message opened'},
{driftEventType: 'welcome message', driftEventName: 'welcomeMessage:close', driftEventDescription: 'welcome message closed'},
{driftEventType: 'away message', driftEventName: 'awayMessage:open', driftEventDescription: 'away message opened'},
{driftEventType: 'away message', driftEventName: 'awayMessage:close', driftEventDescription: 'away message closed'},
{driftEventType: 'campaign', driftEventName: 'campaign:open', driftEventDescription: 'campaign message opened'},
{driftEventType: 'campaign', driftEventName: 'campaign:dismiss', driftEventDescription: 'campaign message closed'},
{driftEventType: 'campaign', driftEventName: 'campaign:click', driftEventDescription: 'CTA clicked'},
{driftEventType: 'campaign', driftEventName: 'campaign:submit', driftEventDescription: 'campaign user started a chat or submitted an email'},
{driftEventType: 'slider message', driftEventName: 'sliderMessage:close', driftEventDescription: 'slider message closed'},
{driftEventType: 'conversation', driftEventName: 'startConversation', driftEventDescription: 'user started a new chat'},
{driftEventType: 'conversation', driftEventName: 'message:sent', driftEventDescription: 'user replied to a conversation'},
{driftEventType: 'conversation', driftEventName: 'message', description : 'user received a message from a team member'},
{driftEventType: 'conversation', driftEventName: 'emailCapture', driftEventDescription: 'user submitted email address'},
{driftEventType: 'conversation', driftEventName: 'scheduling:requestMeeting', driftEventDescription: 'schedule meeting card pushed to a conversation'},
{driftEventType: 'conversation', driftEventName: 'scheduling:meetingBooked', driftEventDescription: 'user booked a meeting'}
]
// Registering callbacks for each Drift event
drift.on('ready', function (api, payload) {
dataLayer.push({event: 'drift', driftEventName: 'driftReady', driftEventDescription: 'drift loaded', driftEventData: payload});
driftEvents.forEach(function (driftEvent) {
drift.on(driftEvent.driftEventName, function (data) {
driftEvent.event = 'drift';
driftEvent.driftEventData = data;
dataLayer.push(driftEvent);
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment