Hidden Pre-Chat in Messaging for Web
To learn about and set up hidden pre-chat, see Customize Pre-Chat for Messaging for In-App and Web.
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.
- Before you initialize the API from the code snippet that we provide, add an event listener for
onEmbeddedMessagingReady
. This method notifies you when the API is ready for requests. - At some point after the
onEmbeddedMessagingReady
event is dispatched, pass hidden pre-chat fields to Salesforce by usingsetHiddenPrechatFields
andremoveHiddenPrechatFields
.
This sample code illustrates how you can implement the key steps of this sequence.
The Messaging for Web reference documentation describes these methods in detail.
If your Messaging for Web 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 a Messaging for Web Deployment in an Experience Builder Site in Salesforce Help.