Set visitor specific values with javascript

These functions are useful when you already have some info about the visitor who is for example logged in to your e-shop or intranet and you want to set their user details (i.e. name, email, phone number or custom field values). If you integrate this javascript call by a simple change in any widget integration code, you will be able to see the visitor's name in the list of online visitors in Chats > Chats overview and when they start a chat or open LiveAgent contact form their details will be pre-filled.

Supported javascript functions:

//Set all customer data with one call
LiveAgent.setUserDetails(email, firstName, lastName, phone);

//Set just specific customer value - supported keys: email, firstname, lastname, phone
LiveAgent.addUserDetail(key, value);

//Add custom field value to Contact (customer field has to be defined in your LiveAgent>Configuration>System>Contact fields)
LiveAgent.addContactField(key, value);

//Add custom field value to Ticket (ticket field has to be defined in your LiveAgent>Configuration>System>Ticket fields)
LiveAgent.addTicketField(key, value);

Typical use is to call the function in widget integration code before the widget is created:

<script type="text/javascript">
(function(d, src, c) { var t=d.scripts[d.scripts.length - 1],s=d.createElement('script');s.id='la_x2s6df8d';s.async=true;s.src=src;s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs&&(rs!='complete')&&(rs!='loaded')){return;}c(this);};t.parentElement.insertBefore(s,t.nextSibling);})(document,
'//localhost.lc/LiveAgent/LiveAgent/server/scripts/track.js',
function(e){ 
  LiveAgent.setUserDetails('customer@email.com', 'First name', 'Last name', '00123987654');
  LiveAgent.addTicketField('orderid', 'ORD123456');
  LiveAgent.addContactField('customer_type', 'VIP');
  LiveAgent.createButton('70735e08', e); 
});
</script>

Hint: You can use it as tracking code only i.e. without showing any contact widget if you omit the line LiveAgent.createButton(...) You will see all online visitors in the Chats > Chats overview screen and if you have any invitations set up, you'll be able to manually invite them to chat.


Before you can set custom ticket fields using function addTicketField, you need to have these fields defined in the LiveAgent menu Configuration -> System -> Ticket fields
Before you set custom contact fields using javascript function addContactField, don't forget to define those fields in the LiveAgent menu Configuration -> System -> Contact fields


Once the contact or chat is started by the visitor, these custom parameters will be passed to created ticket/chat and your agents will be able to see them in ticket details section.

If you are using fields for these custom parameters also directly in your contact or pre-chat form, values defined via addTicketField function will be pre-filled for the visitor and he can change them manually before submitting the form.

If you don't want the values passed in custom ticket fields to be visible by the visitor just don't use these fields directly in the contact or pre-chat forms(Ticket fields still needs to be defined in your LiveAgent). This way these ticket fields are still going to contain the passed value in the button code, but the actual value won't be visible to the visitor anywhere.