Installation and User Identification

The Javascript SDK is an easy way to install Drift, while also identifying users and tracking events if you’re installing it in your app.

Not yet using Drift?

Sign up here!

Installing

If you’re still creating your account, copy and paste the code snippet inside your webpage’s, or web app’s, <head> block. If you already have account, get the Drift code at the bottom left of this page.

To make life easy for you, this JS snippet will never change… after installing this you’ll never have to touch it again no matter how many new features we release.

Using Wordpress, Shopify, Segment, or Google Tag Manager?

You can easily install Drift with any of these platforms. Connect Drift to your service in app or see this helpdoc for Google Tag Manager

You're all set!

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

Drift uses cookies to identify site visitors who return to your website so we can maintain their identify. 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're using Drift will treat them the same.

You can do this with a single line JavaScript. All you need to know is the unique user ID that your platform uses toidentify whoever is on your website.

This ID might be numerical, or an email address, or a random string of characters.

Here's a code example

In this example, the userId is USER-142

<!-- html webpage -->
<script>
drift.identify('USER-142');
</script>

Know more information about this person?

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

<!-- html webpage -->
<script>
drift.identify('USER-142', {
  email: 'user142email@gmail.com',
  numberOfLogins: 5,
  phone_number: '222-3333-4444'
});
</script>

userId
string/number

The unique user ID in your company’s user table for the user.

attributes
Object
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. Nested objects or arrays will not work.

Installation and User Identification