Newer Version Available

This content describes an older version of this product. View Latest

Deployment API Code Sample

Test and preview how the Deployment API can help you customize your deployments.

The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to Messaging for In-App and Web before that date. Messaging offers many of the chat features that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in Help.

Important

Chat Window

This code sample creates a chat window that uses the following Deployment API methods:
  • startChat
  • showWhenOnline
  • showWhenOffline
  • addCustomDetail
  • setName
  • map
  • setChatWindowWidth
  • setChatWindowHeight
  • doKnowledgeSearch

Details added via the Deployment API are associated with the Visitor. When a chat is launched, the Chasitor is associated with the initial visitor. A subsequent request is a new Chasitor associated with the same visitor. To create details associated with only one Chasitor, the Prechat API must be used instead.

Warning

This code results in the following view for agents using the Console.
Live Agent in the Console

The name of the customer (Jane Doe for this example) appears in the Console from setName (1). When you call addCustomDetail.doKnowledgeSearch, the search automatically appears in the Knowledge widget (2).

When the agent receives a chat, the set Custom Details appear in a hover window.
Incoming chat with Custom Details hover.

Optional Cookies

You can use your consent manager to provide users the ability to opt in or opt out of optional cookies. If they choose to opt in you can pass true to the fourth parameter in liveagent.init() to enable tracking optional cookies. Otherwise, if they choose to opt out, pass false. Omitting the fourth parameter is the same as passing true.

The ability to provide opt-out from optional cookies is supported in version 52.0 and later of the Deployment API.

Note

If the user opts out, you can also call liveagent.disableOptionalCookies(). This deletes and stops tracking the optional cookies. This is the same as passing false to liveagent.init() except that it takes higher order of precedence than liveagent.init() with the value true. For example, if you call liveagent.disableOptionalCookies() first and then pass true to liveagent.init(), optional cookies are still disabled. Unlike liveagent.init(), liveagent.disableOptionalCookies() can also be called anytime after the page is loaded.

If the user opts back in to optional cookies after opting out, pass true to liveagent.init() on the next page load.