[SalesForce] Live agent pre chat custom detail

I'm trying to push some custom data to the chat console from pre chat from but without success. I've tried hidden form elements like this:

<input type="hidden" name="liveagent.prechat:Username" value="Anonymous" />

And also tried JavaScript API

liveagent.addCustomDetail('Username', "Anonymous", true);

But the agent sees only most recently viewed pages when hovering over "Accept" chat button. Also no custom variables are displayed after chat is initialized.

The pre-chat form is embedded on a client site. To submit the form I just use this code:

<a href="javascript://Chat" onClick="liveagent.startChat('XXXX')">START CHAT</a>

How can I debug this? What is the correct way to pass this custom data?

Best Answer

You are using the deployment API which is different to the tags that must be used in the pre-chat form.

Here is an example on how to create a case with some information pre-populated that will also show in the console for the agent, you can do the same without creating a record, this should give you an idea.

<input type='hidden' name='liveagent.prechat:caseorigin' value='Chat'/>
<input type='hidden' name='liveagent.prechat:caseContactId' value='{!$User.ContactId}'/>
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseorigin;ContactId,caseContactId;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;ContactId,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="Case" />
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" />

The section you care about if all you want is to show the details on the console would be this

<input type='hidden' name='liveagent.prechat:caseContactId' value='{!$User.ContactId}'/>

in combination with this value

<input type= "hidden" name= "liveagent.prechat.findorcreate.displayToAgent:caseContactId" value= "true" />

With that, you are assigning a value to a custom chat detail that will be shown to the agent that gets the chat assigned.