# Identity Management

Salesforce Interactions SDK manages user tracking using a first-party cookie to assign and maintain an identity, regardless of whether the user is logged in or anonymous. The SDK identifies new and returning users with a first-party cookie named `__sfid_${domainHash}_`. The `_domainHash_` is generated by running your website’s domain through a hashing function.

This cookie stores a unique, randomly generated `anonymousId`. When a new customer visits, this ID is created for them. When they return, the SDK recognizes them using the existing `anonymousId` from the cookie, allowing for consistent tracking across sessions.

## Sharing a Cookie Across Multiple Domains

If you must share cookies across multiple domains, configure the Salesforce Interactions Web SDK with the shared domain name. This can be done through either configuration passed to `SalesforceInteractions.init` or in a function call to `SalesforceInteractions.setCookieDomain`.

For example, to share a cookie between the domains `abc.domain.com` and `xyz.domain.com`, configure the cookie domain with:

```javascript
SalesforceInteractions.init({
  cookieDomain: "domain.com",
});
```

You can also set the cookie domain using the `setCookieDomain` function.

## Identity Management Methods

### getCookieDomain()

Returns the value of the cookie domain currently used to generate the first-party cookie. The first party cookie stores the `anonymousId`.

```javascript
SalesforceInteractions.getCookieDomain();
// => "domain.com"
```

### setCookieDomain(newDomain:string): void

Sets the value of the cookie domain used to generate the first-party cookie. The first party cookie stores the `anonymousId`.

```javascript
SalesforceInteractions.setCookieDomain("domain.com");
```

:::note
Setting the cookie via the `setCookieDomain` function doesn’t take effect if the Salesforce Interactions SDK is already initialized. Ideally, this function call happens before initialization. However, you can call `SalesforceInteractions.reinit()` to force the cookie changes to take effect.
:::

### getAnonymousId()

Returns the value of the `anonymousId` persisted in the first-party cookie.

```javascript
SalesforceInteractions.getAnonymousId();
// => "efc9953d6515dc7f"
```

### setAnonymousId(newAnonymousId:string): void

Manually sets the value of the `anonymousId` persisted in the first-party cookie.

```javascript
// Example: Setting a new ID based on a time stamp
SalesforceInteractions.setAnonymousId(`id_${Date.now()}`);
```

### resetAnonymousId()

Removes the existing first-party cookie and generates a new cookie with a newly generated, unique `anonymousId`. This effectively starts a new session for the user.

```javascript
SalesforceInteractions.resetAnonymousId();
```
