Sending Information into Drift

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.

Create your attributes first

We recommend setting up your custom attributes first before using the below methods.

See the following page: https://devdocs.drift.com/docs/data-types-in-drift

drift.identify(userId, attributes)

The most common use case for identify is to externally sync the identity of a contact or site visitor currently on your website with Drift.

If you're already tracking users on your website with a unique identifier from your own system (i.e. a user id for an email in response to a log in event) you can use the drift.identify() method to pass this information along with additional contact properties for that user. If you wish to use identify, we recommend using this method with a unique and consistent, email/userId pair for a given user.

identify will create a new contact record in your account if the id has not been seen before - email is not a unique identifier in drift. If the id has been seen before,- then we'll simply update that contact record in Drift.

Example usage of identify coupled with a login flow callback.

yourapp.login(...).then(yourUserObject => {
  drift.identify(yourUserObject.id, { // assuming your DB identifier could be something like a GUID or other unique ID.
    email: yourUserObject.email,
    name: yourUserObject.name,
    age: yourUserObject.age,
    // ...              
  })
})

// Your user object may have different fields that you want to pass into drift. You can add those here as well.

Make sure the drift object is initialized

You should ensure that drift.on('ready',...) has been fired before calling identify - though typically timing isn't an issue if identify is called well after page load.

drift.api.setUserAttributes(attributes)

If you're not identifying users, or if want to pass contact properties without worrying about the user's identity, you can use the drift.api.setUserAttributes() method instead. You'll need to wait for the ready event before the API is ready to be called.

drift.on('ready', function() {
  drift.api.setUserAttributes({
    email: 'abcd@example.com',
    nickname: 'John Doe',
    age: 21
  })
})

A warning on assigning attributes

Attributes will automatically be created if they haven't been declared.

For example, if you call setUserAttributes({"my_custom_property": 123}) and my_custom_property hasn't been previously created in Drift, we will automatically create and infer the type of the attribute (in this case numeric).

We recommend creating the attributes beforehand in Drift that you intend to use:
https://devdocs.drift.com/docs/data-types-in-drift

`identify` vs. `setUserAttributes`

We recommend using setUserAttributes over identify unless you want to use your own custom ID values for contacts created in Drift.

setUserAttributes is useful if you'd like to specify custom properties after the user has been identified, or if you want to set properties on the site visitor without necessarily knowing his or her email.

You aren't just limited to text and numbers for attributes! Find out about Drift data types here!

drift.track

Did the site visitor view some content? Enroll in a new course or product on your website? Send these one-time events into Drift and we can use this information inside of our messaging.

drift.track('enrolled in service', {
  firstTime: false,
  newService: true
});

// or

drift.track('Exported', {exportedObject:'2015_users'});
driftt.track('Shared Content', { contentId: 1, contentName: 'Proposal', contentType: 'document', method: 'Email' });

event
string

This is the name of the type of event. You should try to reuse the same events with different properties to describe similar actions such as Share or Link Clicked

attributes
object, optional

A dictionary of attributes about this type of event, such as shareType or linkUrl.
Note: the attributes object must be a flat object. Nested objects or arrays will not work

drift.page

Use drift.page to manually tell Drift that the page has changed so our targeting can adjust accordingly. This will send a page event to Driftt. It takes an optional pageName and then sends info about the current page that the user is on such as the url and title.

This could also be applied for updating the page label on single page apps where the browser page url behaves differently.

drift.page('Main Content Page') // driftt.page(pageName)

// or

drift.page() // generic page event including both the url and title of the current page.

name
string, optional

This is the name that you want to be able to easily be able to identify this call by, it will get stored in a track event under the attribute pageName

Drift Privacy Policy

Drift respects privacy rights and data protection laws. You may only share other people's personal information with Drift, whether directly or through third-party integrations, if you are permitted to do so under applicable law. Drift Privacy Policy

Sending Information into Drift


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.