Hidden Pre-Chat for iOS

Use hidden pre-chat fields to capture valuable information without asking the customer directly for it.

This feature requires version 1.2.0 or later of the Enhanced In-App Chat SDK.

Important

This article applies to the following implementations:

UI SDKCore SDK

After you set up pre-chat in Salesforce, the UI SDK automatically presents the pre-chat form to the user and passes this information to Salesforce. If you’re not using the UI SDK, the Core SDK documentation describes how to perform this process programmatically. To use hidden pre-chat fields, use the Core SDK. If you want to use this feature with the UI SDK, use the Core SDK with your UI SDK.

This article describes the steps that you must take from your app to send any user data not visible in the pre-chat form. This data is also described as hidden pre-chat fields. To learn about and set up pre-chat, see Customize Pre-Chat for Enhanced Chat.

After you set up hidden pre-chat fields in Salesforce, you can populate these values using the SDK.

  1. Implement the HiddenPreChatDelegate interface. This delegate contains the didRequestPrechatValues method, which the SDK calls when it needs pre-chat values.
  2. Add your delegate to the SDK using the CoreClient.preChatDelegate property. See the CoreClient reference documentation.
Implement hidden pre-chat delegate
1class HiddenPrechatDelegateImplementation: HiddenPreChatDelegate {
2
3  func core(_ core: CoreClient!,
4            conversation: Conversation!,
5            didRequestPrechatValues hiddenPreChatFields: [HiddenPreChatField]!,
6            completionHandler: HiddenPreChatValueCompletion!) {
7
8    // Use the conversation object to inspect info about the conversation
9
10    // Fill in all the hidden pre-chat fields
11    for preChatField in hiddenPreChatFields {
12      // preChatField.label contains the label
13      // preChatField.identifier contains the conversation identifier
14      // preChatField.value is where you populate the field with a value
15
16      preChatField.value = "My hidden pre-chat value"
17    }
18
19    // Pass pre-chat fields back to SDK
20    completionHandler(hiddenPreChatFields)
21  }
22}

This sample code requires the configuration object that you created when setting up the UI SDK or the Core SDK. See Build a UI SDK App or Build a Core SDK App for more information.

Note

Add your delegate to the core client object
1// Create an instance of the hidden pre-chat delegate
2let myPreChatDelegate = HiddenPrechatDelegateImplementation()
3
4// Create a core client from a config
5let coreClient = CoreFactory.create(withConfig: config)
6
7// Assign the hidden pre-chat delegate
8coreClient.preChatDelegate = myPreChatDelegate

After you register your delegate, the SDK automatically calls your didRequestPrechatValues method before a conversation begins.