---
schema_version: "1"
id: 27560505f544033bb661a573a4c2ef7bc5c4a76423e480a6da1bebc5e1ffb6e6
title: Hidden Pre-Chat in Enhanced Web Chat
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/messaging-web/guides/pre-chat.md
canonical_url: https://developer.salesforce.com/docs/service/messaging-web/guide/pre-chat.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a56f95ee9187fe0e499d881763c10c5d214fa57d8f04bed46de25ffccddd5dbe
products:
  - Enhanced Web Chat
  - Service Cloud Developer Content
---
# Hidden Pre-Chat in Enhanced Web Chat

To learn about and set up hidden pre-chat, see [Customize Pre-Chat for Enhanced Chat](https://help.salesforce.com/s/articleView?id=service.miaw_custom_prechat_2.htm).

This section describes the steps you must take from your web client to send user data, also known as hidden pre-chat data, to Salesforce. See the associated documentation for each step of this sequence.

![Hidden pre-chat sequence](https://developer.salesforce.com/docs/media/messaging-web/hidden-pre-chat-sequence.png)

1. Before you initialize the API from the code snippet that we provide, add an event listener for [`onEmbeddedMessagingReady`](/docs/service/messaging-web/guide/event-listeners.html). This method notifies you when the API is ready for requests.
2. At some point after the `onEmbeddedMessagingReady` event is dispatched, pass hidden pre-chat fields to Salesforce by using `setHiddenPrechatFields` and `removeHiddenPrechatFields`.

This sample code illustrates how you can implement the key steps of this sequence.

```javascript
window.addEventListener("onEmbeddedMessagingReady", () => {
    console.log("Received the onEmbeddedMessagingReady event…");

    // Send data to Salesforce
    embeddedservice_bootstrap.prechatAPI.setHiddenPrechatFields({"Order_Number" : "867-5309",
        "Customer_ID" : "11098324"});

    // Remove any items from the previous list that you don't want to send
    embeddedservice_bootstrap.prechatAPI.removeHiddenPrechatFields(["Customer_ID"]);
});

embeddedservice_bootstrap.init(…)
```

The Enhanced Web Chat [reference documentation](/docs/service/messaging-web/references/m4w-reference/prechatAPI.html) describes these methods in detail.

**note:** If your Enhanced Web Chat deployment is on an Experience Cloud site, follow the instructions in _Salesforce Help_ to add JavaScript code to the head markup section of your site. See [Configure an Enhanced Web Chat Deployment in an Experience Builder Site](https://help.salesforce.com/s/articleView?id=service.miaw_deployment_experience_builder.htm) in _Salesforce Help_.

