User Identification

Getting Started

One of the best ways to make Drift more conversational is to use identification methods to tell the chat exactly who is engaging with it as they land on your application, or web pages.

Sometimes you may find it useful to send Drift additional information about a visitor on your site.
This information is commonly represented as attributes on the contact record and can help give your sales and support teams additional context about a visitor during a conversation. These attributes can also be used to create dynamic segments for campaigns or chat targeting.

There are currently two methods when it comes to passing in visitor information with Drift:

Want Drift in your application or product? Let's identify your users!

drift.identify('userId', {userAttributes:'data'});

Drift uses cookies to identify site visitors who return to your website so we can maintain their identity. This means that if the end user clears their cookies or goes to a different device, we'll lose the connection to the previous history.

But if people are already logged into your application, then you know exactly who they are!

When you know the identity of who is on the website, you can explicitly tell Drift which user this is. This way, no matter which device or browser they are using, Drift will treat them the same.

You can do this with just a few lines of code.

All you need is a unique user ID that your platform uses to identify whoever is on your website.

If you use unguessable IDs, you can set this up with just a single line of JavaScript. Just make sure that signed identities are not required in your widget security settings.

If your IDs are guessable (for instance, you use incremental IDs or email addresses), you will need to use our Signed Identities feature to ensure your identification process is secure.

📘

A note on the user id in drift.identify

This ID might be numerical, or an email address, or a random string of characters. Just be sure to use distinct ID values for distinct users. A call to drift.identify with a new ID value not recognized by Drift will register this contact.

❗️

Use caution leveraging drift.identify

An improper implementation of this function can lead to site visitors being able to see the chat history of each other if you're issuing non-unique external identifiers. Signed identities (https://devdocs.drift.com/docs/securing-drift-on-your-site-using-signed-identities) is REQUIRED for any use of drift.identify where visitor privacy and personal information are a consideration.

Here's a code example:

You can pass more information as attributes in as the second argument to the `drift.identify` function, and we can use this information in the Drift platform.

In this example, the userId is `f2c611e9-ee43-42d4-ab56-66d5c0153ee9` . Since this is an unguessable UUID, we don't have to worry about signed identities. For code examples with signed identities, please refer to securing Drift on your site with signed identities

drift.identify('f2c611e9-ee43-42d4-ab56-66d5c0153ee9', {
  email: '[email protected]',
  numberOfLogins: 5,
  phone_number: '222-3333-4444'
});

🚧

Important

Please ensure that identify is called as soon as possible on the page (generally before drift.load('xxxxxxxxx')) - this will ensure that the site visitor is updated with the information provided when we authenticate them.

Typically the identify method can be used in tandem with a login flow - when you become aware of the current visitor's identity or email, or to merge users identified in Drift with the same identification system that your app uses (by using your unique user id value).

👍

Don't want to create a new user, but want to set properties?

You can set attributes on users that haven't even been created in drift yet by using drift.api.setUserAttributes with an object with key value pairs of the attributes. This is described in more detail in the later section: Sending Information into Drift

!-- Start of Async Drift 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';

// Identify your user before loading Drift
drift.identify("1101-d4r4-24rd", {
        email: "[email protected]",
        first_name: "John",
        last_name: "Doe",
        phone_number: "222-333-4444",
      });

// Load Drift after your users have been identified
drift.load('xxxxxxxxxx'); // Replace 'x' with your embed ID
</script>
<!-- End of Async Drift Code -->

Identification Data Object

KeyData Type
userIdstring/numberThe unique user ID in your company’s user table for the user.
attributesobject (optional)A dictionary of attributes you know about this user, such as their email, name, company.

Note: The attributes object must be a flat object.
See this doc about the different data types available to you.

Removing Identification when your users log out

❗️

Important!

Make sure you're not calling drift.reset() before the loading of the widget or before your identity call. This method re-initializes the widget with a 'ready' event and will prevent Drift from loading if not used correctly.

When your users are done using your services and log-out of your application, it's important to clear Drift's memory of this user so the next person using the computer doesn't see any previous history.

In order to do this, just use drift.reset() to completely clear Drift's tracking cookies. To Drift, this is a brand new person now.