Using AnalyticsJS with Drift

Andrew Sawusch Updated by Andrew Sawusch

Tracking your Drift interactions inside of the CaliberMind Platform is possible using our AnalyticsJS. After inserting just a few lines of code, anytime a web visitor provides their email address in a Drift conversation, the interaction will be recorded as an event that is viewable in your organization's my.CaliberMind reports.

Getting Started

A pre-requisite is that you must already have the AnalyticsJS installed on your website to ensure that the analytics.identify call is processed correctly.

Once the AnalyticsJS is on your website, find out where your Drift JavaScript code is located on your company's website. Some customers decide to place this directly into the site header, others use Google Tag Manager, while others on specific CMS systems utilize the Drift app.

Immediately after the Drift JavaScript code, place the following lines of code:

<script>
drift.on('ready',function(api, payload) {
drift.on("emailCapture", function(payload) {
var data = payload.data;
analytics.identify(data.email, { email: data.email });
});
});
</script>

Once this has been added, your full lines of code should look something like this (with the "XXXXXXXXXXXX" being your Drift account's unique account-specific code):

<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';
drift.load('XXXXXXXXXXXX');

</script>

<script>
drift.on('ready',function(api, payload) {
drift.on("emailCapture", function(payload) {
var data = payload.data;
analytics.identify(data.email, { email: data.email });
});
});
</script>

Now that this code has been added, you will be able to fire the AnalyticsJS "Identify" any time that a website visitor enters their email address within your Drift bot.

How did we do?

Google Tag Manager (GTM) Ad Blockers

How to check your AnalyticsJS implementation

Contact