---
schema_version: "1"
id: a3c8e3afd08261cd7fc21680ad7983ae032d083c3c28183806683d122e417c0c
title: User Data
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/interactions-sdk/guides/c360a-api-user-data.md
canonical_url: https://developer.salesforce.com/docs/data/salesforce-interactions-sdk/guide/c360a-api-user-data.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4c041da7331999c31ef5e7ce73c3b4e12a0e702f5d481167cd740beac442cdfd
products:
  - Salesforce Interactions SDK
  - Data 360 Developer Documentation
---
# User Data

User data represents an individual visitor's profile. You use the `user` object to track profile information for a visitor, whether they are anonymous or known (logged-in).

The primary goal of sending user data is to enrich the visitor's profile with descriptive information.

## User Object Structure

The `user` object is included within the event payload sent to the Salesforce Interactions SDK. It contains fields for profile attributes.

| Field                          | Type   | Required | Description                                                                                                                                                                                                                      |
| ------------------------------ | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `user.attributes`              | object | Yes      | User-supplied values that contain descriptive data used to enrich the user's profile (for example, `firstName`, `lastName`, `city`).                                                                                             |
| `user.attributes.eventType`    | string | Yes      | Identifies the type of profile event. Must begin with a letter (a-zA-Z), can only contain alphanumeric characters and underscores, and can't end with or have consecutive underscores. Maximum 80 characters. |

This structure shows the `user` object with user-supplied attributes:

```nolang
{
   user: {
        attributes: {
            eventType: 'identity',
            firstName: 'Joe',
            lastName: 'Smith',
            email: 'joe.smith@domain.com'
        }
   }
}
```

## Examples of Capturing and Sending User Data

You only need to send the `user` object when the visitor's attributes are first discovered or updated (such as, after login, during registration, or upon form submission).

### Capture User Data Without Interaction

This example captures the user's attributes immediately upon login or when their details are known, without an associated interaction.

```javascript
SalesforceInteractions.sendEvent({
  user: {
    attributes: {
      eventType: "identity",
      firstName: "Joe",
      lastName: "Smith",
      email: "joe.smith@domain.com",
    },
  },
});
```

### Capture User Data with an Interaction

You can send both an engagement event and a profile event in a single request. The `interaction` section is the source of the engagement event, and the `user` section is the source of the profile event.

```javascript
SalesforceInteractions.sendEvent({
  // The specific action the user performed
  interaction: {
    name: "View Catalog Object",
    catalogObject: {
      type: "Product",
      id: "product-xyz",
      attributes: {
        /* ... */
      },
    },
  },
  // The user's profile data
  user: {
    attributes: {
      eventType: "identity",
      firstName: "Joe",
      lastName: "Smith",
      email: "joe.smith@domain.com",
    },
  },
});
```

### Capture User Data Using the Sitemap

Use the SDK's `global.onActionEvent` handler to consistently inject user information across all events.

This example shows how to automatically attach a known email address (if available in a global variable like `window.user_info`) as a user attribute to every event.

```javascript
SalesforceInteractions.init().then(() => {
  const sitemapConfig = {
    global: {
      // This function executes before every event is sent
      onActionEvent: (event) => {
        const email = window.user_info && window.user_info.email; // Source the email from a global site variable

        if (email) {
          // Initialize the user and attribute objects if they don't exist
          event.user = event.user || {};
          event.user.attributes = event.user.attributes || {};

          // Attach the email to the attributes object
          event.user.attributes.emailAddress = email;
          event.user.attributes.eventType = "contactPointEmail";
        }
        return event; // Always return the modified event
      },
    },
    pageTypes: [
      /* ... other page types */
    ],
  };
  SalesforceInteractions.initSitemap(sitemapConfig);
});
```

## Automatic Anonymous Identity Events

The SDK automatically sends an anonymous identity event to Data Cloud when a new anonymous ID is detected. This event ensures a profile record exists for the visitor's device so that engagement events can be linked to an identity, even before the visitor is known.

The automatic event is generated when both conditions are true:

- **The anonymous ID changed.** This occurs when the SDK generates a new anonymous ID on the visitor's first page load, when `SalesforceInteractions.setAnonymousId(id)` is called with a new value, or when `SalesforceInteractions.resetAnonymousId()` generates a fresh ID. If `setAnonymousId` is called with the same ID that's already stored, no event is triggered.
- **The first action event after the ID change carries no profile data.** If that action event already contains `user.attributes` with an `eventType`, the SDK skips the automatic event and uses the real profile data instead.

The automatic event is a minimal identity profile event with `isAnonymous: true`. It fires on the first `onEventSend` batch after the ID change, not at the moment the anonymous ID is set. If the visitor leaves the site before any action event fires, no identity event is sent. The anonymous profile record can be merged or overwritten when a real identity is established.

**See Also**

- [Translation of SDK Events to Web Connector Schemas](https://developer.salesforce.com/docs/data/salesforce-interactions-sdk/guide/c360a-api-translating-sdk-events-to-web-connector-schemas.md)
- [Custom Events](https://developer.salesforce.com/docs/data/salesforce-interactions-sdk/guide/c360a-api-custom-events.md)
