Source: https://datafa.st/docs/user-identification
Markdown source: https://datafa.st/docs/user-identification.md
Description: Turn visitors into profiles by identifying them with unique user IDs. Track user journeys across browsers and devices.

# User identification

Turn anonymous visitors into persistent and searchable **profiles** along with custom parameters.

![Visitor profile and journey](/user-identification.png)

Profiles track your users with persistent IDs (like `email` or `userId`) and provide several advantages:

- **Cross-platform tracking:** Follow users across browsers and devices
- **Search visitors:** Find specific users and their journeys in your analytics dashboard
- **Persistent tracking:** Maintain user journey even if cookies are reset
- **Better attribution:** Link anonymous traffic to known users

## How to identify a user

Use the `window.datafast()` method to identify a visitor:

```javascript
window?.datafast("identify", {
  user_id: "unique-user-id", // required
  name: "John Wayne", // optional - if present, it will replace the anonymous name in the visitor profile
  image: "https://example.com/avatar.jpg", // optional - profile image URL
  // ... any other custom parameters you want to track
});
```

#### Required parameters

- **`user_id`** (string, required): A unique identifier for the user like _email_ or _userId_

#### Special parameters (optional)

- **`name`** (string): If present, it will replace the anonymous name in the visitor profile
- **`image`** (string, 250 char. max.): A valid URL pointing to a profile image to display in [Journeys](/changelog/goal-tracking) and the [Realtime Map](/changelog/real-time-map). Example: `https://lh3.googleusercontent.com/-WuQbhWk1Xso/AAAAAAAAAAI/AAAAAAAAAAA/ALKGfklNb9VSEpE-xxOXfgy6n9NGIdz-2g/photo.jpg?sz=46`

#### Custom parameters validation rules

- **Property names:** lowercase letters, numbers, underscores (_), and hyphens (-) only. Max 64 characters.
- **Property values:** any string, max 255 characters.
- **Limits:** maximum 10 custom parameters.

### Ensure reliable tracking (recommended)

Add this script to your HTML `<head>` to guarantee identification is captured even when triggered before the main script loads:

```html
<script id="datafast-queue">
  window.datafast = window.datafast || function() {
    window.datafast.q = window.datafast.q || [];
    window.datafast.q.push(arguments);
  };
</script>
```

## Example usage

```jsx
useEffect(() => {
  if (user && user.email) {
    window?.datafast("identify", {
      user_id: user.email,
      name: user.name,
      image: user.profileImage,
      role: user.role,
      plan: user.plan,
    });
  }
}, [user]);
```

  > **Note:** User identification is separate from [custom goals](/docs/custom-goals). Use identify to link users to their accounts, and use custom goals to track specific user actions.

## Special notes

- **Persistent tracking:** You need to identify the visitor each time their cookie changes for persistent tracking. You can call `window.datafast("identify")` every time their session changes.

- **Revenue attribution:** If [revenue attribution](/docs/revenue-attribution-guide) is present, we automatically identify the customer using data from the payment provider.
