Post-Chat Code Sample

Test and preview how post-chat pages work for your agents and customers using this code sample.

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.

You can customize your post-chat page by including the variables you want to be displayed.

If the post-chat page is hosted on a site that requires an active session, long-running chats can lead to session timeout. If the customer is on the post-chat page and is redirected to a login page, the post-chat context variables are lost.

Possible VariablesDescription
requestTimeThe timestamp when the system received the chat request.
startTimeThe timestamp when the agent accepted the chat.
deploymentIdThe ID of the deployment.
buttonIdThe Id of the button that originated the chat.
chatKeyThe unique chat key.
lastVisitedPageThe last visited page value sent to the agent.
originalReferrerThe first page the customer visited containing the deployment code.
latitudeGeo location latitude of the chat visitor.
longitudeGeo location longitude of the chat visitor.
cityGeo location city of the chat visitor.
regionGeo location region of the chat visitor.
countryGeo location country of the chat visitor.
organizationSalesforce organization ID that hosted the chat.
disconnectedByReason for ending the chat. Possible values:
  • agent - the agent terminated the chat
  • client - the chat visitor terminated the chat
  • error - the system encountered an error that disconnected the chat
  • clientIdleTimeout - the chat visitor didn’t answer within the allotted time (must have Idle Timeout configured)
  • agentsUnavailable - there are no agents available to receive the chat or there is no room in the queue
windowLanguageLanguage of the window as configured in the chat button.
chatDetailsA JSON representation of the chat data.
transcriptA plain text copy of the transcript.
attachedRecordsA list of IDs attached to the chat session in JSON array format.
errorDescription of any errors that occurred during the chat.

This code sample creates a post-chat page that includes basic information about the chat.

This code results in the following post-chat page for the agent:

Post-chat page

This message shows if the chat is abandoned:

Post-chat when chat is abandoned