Below are some situations where using a `customerSessionId` might be beneficial:

1. You already have a session/transaction identifier you want to link to the data collected by Socure.
2. There are size/token requirements on the identifiers used on your end that the existing session token does not satisfy.
3. You want to track a user journey by maintaining the same identifier across multiple sessions/pages/tabs etc. In this case you can think of the provided identifier as something that links multiple pieces of data into one.

## Usage

The `customerSessionId` can be provided in two places:

1. Using the configuration provided at initialization:

### TypeScript

```typescript
interface SigmaDeviceOptions {
  sdkKey: string;
  ...
  customerSessionId?:string;
}
```

The `customerSessionId` or `data-customer-session-id`(when using a script tag) can be used to provide the customer defined id. When used at initialization, the Socure Web SDK will immediately associate all the data collected by the SDK including device, network, behavioral etc. to the provided identifier.

Note that providing the same identifier across multiple initialization calls results in the SDK linking all the data across the initialization calls to the same identifier. It is the customer's responsibility to ensure the `customerSessionId` is correctly tied to the session and is unique. Socure does not prevent the reuse of `customerSessionId`s in places where the Socure SDK would typically use a new `session-token` in order to allow customers to define a session as they see fit.

2. Using the `setCustomerSessionId()` method:

### JavaScript

```javascript
SigmaDeviceManager.setCustomerSessionId("19aaed56-ffbd-48ca-bd6d-e4d9f8f01348")
```

In situations where you do not want to provide the identifier at initialization or you want to change the `customerSessionId` that is currently set(for e.g. new transaction, log-out etc.), you can make use of the `setCustomerSessionId()` method. In this case, if there was no `customerSessionId` previously set then the SDK will associate all the data collected since initialization to the provided identifier. If there was already an identifier set(via initialization or a previous `setCustomerSessionId()` call) then the SDK will stop the existing session, create a new session and associate data going forward with the newly provided identifier.

## Accessing the data

When using the `customerSessionId`, you can access the data associated with the identifier by simply providing the identifier wherever you make a request to the RiskOS™ services. For e.g. this identifier can be used in place of `di_session_token` when making RiskOS™ API calls.

Below are some examples:

1. RiskOS™ Evaluation

### JSON

```json
POST /api/evaluation {
  "data": {
    "individual": {
      "di_session_token": "19aaed56-ffbd-48ca-bd6d-e4d9f8f01348"
    },
  "id": "onb-12345",
  "timestamp": "2023-12-01T08:15:30.456Z",
  "workflow": "consumer_onboarding"
}
```

Updated 3 months ago
