# Custom Events

Interactions SDK provides recommended interaction data models like Cart Interaction, Catalog Interaction, and Order Interaction that help you leverage the unified data model across Salesforce. In addition to these standard models, you can also define Custom Events to capture proprietary or highly specific user actions.

Custom Events ensure that unique behavioral data relevant to your business is also ingested into the unified data model in Data 360.

## Define a Custom Event

Unlike standard interactions, Custom Events require a two-step definition process: setting up the schema in Data 360 and then instrumenting the SDK call.

### Define the Schema in Data 360

Before sending the event, you must modify your Web Connector schema in Data 360 to define the event's unique name and it's expected custom fields.

- Once your custom schema is created and deployed, you can't make changes (deletions or edits) to its structure.
- The SDK automatically converts custom event fields that aren't already in standard format to camel-case for Data 360 ingestion. For example, a field labelled `Developer NAME` in the schema will be correctly mapped to `developerName` when processed.

This example illustrates how to define a custom event names `myCustomEvent`:

:::important
This example schema is provided for illustrative purposes only. Don't use it without modification in your Web Connector, as it may not align with all implementation goals.
:::

```json
{
  "records": [
    {
      "developerName": "myCustomEvent",
      "masterLabel": "My Custom Event",
      "category": "Engagement",
      "externalDataTranFields": [
        {
          "masterLabel": "My Custom Field",
          "dataType": "Text",
          "developerName": "myCustomField",
          "isDataRequired": true
        },
        {
          "masterLabel": "My Custom Num Attribute",
          "dataType": "Number",
          "developerName": "attributesMyCustomNum",
          "isDataRequired": true
        },
        {
          "masterLabel": "My Custom Text Attribute",
          "dataType": "Text",
          "developerName": "attributesMyCustomText",
          "isDataRequired": true
        },
        {
          "masterLabel": "eventId",
          "dataType": "Text",
          "developerName": "eventId",
          "isDataRequired": true,
          "primaryIndexOrder": 1
        },
        {
          "masterLabel": "category",
          "dataType": "Text",
          "developerName": "category",
          "isDataRequired": true
        },
        {
          "masterLabel": "dateTime",
          "dataType": "DateTime",
          "developerName": "dateTime",
          "isDataRequired": true
        },
        {
          "masterLabel": "deviceId",
          "dataType": "Text",
          "developerName": "deviceId",
          "isDataRequired": true
        },
        {
          "masterLabel": "eventType",
          "dataType": "Text",
          "developerName": "eventType",
          "isDataRequired": true
        },
        {
          "masterLabel": "sessionId",
          "dataType": "Text",
          "developerName": "sessionId",
          "isDataRequired": true
        }
      ]
    }
  ]
}
```

### Capture the Event with the SDK

To capture and send the custom event from your website, use the `SalesforceInteractions.sendEvent()` function and specify the `eventType` or `name` field, and required fields that aren’t set via [Automatic Population of Required Data 360 Fields](/docs/data/salesforce-interactions-sdk/guide/c360a-api-translating-sdk-events-to-web-connector-schemas.md#automatic-population-of-required-data-cloud-fields) to capture this event.

```javascript
SalesforceInteractions.sendEvent({
  interaction: {
    name: "myCustomEvent",
    eventType: "myCustomEvent",
    myCustomField: "some value",
    attributes: {
      myCustomNum: 1234,
      myCustomText: "abcd",
    },
  },
});
```

The SDK combines your data with the automatically populated fields and transforms the field names to match your Web Connector schema before sending it to Data 360.

```json
{
  "events": [
    {
      "eventType": "myCustomEvent",
      "myCustomField": "some value",
      "attributesMyCustomNum": 1234,
      "attributesMyCustomText": "abcd",
      "eventId": "100d237b-e464-44df-9556-7481bbf52685",
      "dateTime": "2022-10-18T18:25:26.680Z",
      "sessionId": "6b6c33bfcfee93f4",
      "deviceId": "6b6c33bfcfee93f4",
      "interactionName": "myCustomEvent",
      "sourceUrl": "https://{my site}",
      "sourceUrlReferrer": "https://{my site}",
      "sourceChannel": "Web",
      "sourcePageType": "test",
      "category": "Engagement"
    }
  ]
}
```

:::note
If the `eventType` isn’t explicitly provided, but `name` is, the SDK automatically sets its value to match the value of `name`.
:::
