Tips & Tricks: JavaScript Callbacks

JavaScript callbacks are custom JavaScript code that can be processed for various chat icon and chat window actions. If your webpage contains these callbacks, the PHP Live! system will call those functions. Include your custom code inside the callback functions. The following callbacks are available:
Chat icon has loaded
When the chat icon has loaded on the page, this function will be called if it exists on the page:
phplive_callback_loaded( department_id, online_offline_status )
    Function Parameters
  • department_id = the department ID the chat icon references
  • online_offline_status = the chat icon status (1 is online, 0 is offline)
Example:
function phplive_callback_loaded( department_id, online_offline_status )
{
	var status = ( online_offline_status == 1 ) ? "online" : "offline" ;
	alert( "Chat icon has been loaded for department ID " + department_id + " and the status is " + status ) ;
}
Chat icon has been clicked
When the chat icon is clicked, this function will be called if it exists on the page:
phplive_callback_launchchat( online_offline_status, department_id )
    Function Parameters
  • online_offline_status = the chat icon status (1 is online, 0 is offline)
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_launchchat( online_offline_status, department_id )
{
	var status = ( online_offline_status == 1 ) ? "online" : "offline" ;
	alert( "Chat icon has been clicked for department ID " + department_id + " and the status is " + status ) ;
}
The visitor starts a chat session
This callback was included in v.4.8.6
When the visitor clicks the "Start Chat" button to start the chat session, this function will be called if it exists on the page:
phplive_callback_chat_start( department_id )
    Function Parameters
  • department_id = the department ID of the department the visitor is trying to reach
Example:
function phplive_callback_chat_start( department_id )
{
	alert( "Visitor clicked the 'Start Chat' button.  Chat has started." ) ;
}
The chat request has been accepted
This callback was included in v.4.9.16
When the chat request has been accepted by an operator, this function will be called if it exists on the page:
phplive_callback_chat_accepted( department_id )
    Function Parameters
  • department_id = the department ID of the chat request
Example:
function phplive_callback_chat_accepted( department_id )
{
	alert( "The chat request was accepted for department ID " + department_id ) ;
}
The chat request was not accepted
This callback was included in v.4.9.16
If the visitor cancels the chat request or the chat request completes the routing cycle without an operator accepting the chat, this function will be called if it exists on the page:
phplive_callback_chat_not_accepted( department_id )
    Function Parameters
  • department_id = the department ID of the chat request
Example:
function phplive_callback_chat_not_accepted( department_id )
{
	alert( "The chat request was not accepted for department ID " + department_id ) ;
}
The chat request was cancelled by the visitor
This callback was included in v.4.9.16
If the visitor cancels the chat request (clicks the end chat before the chat request completes the routing cycle), this function will be called if it exists on the page:
phplive_callback_chat_cancelled( department_id )
    Function Parameters
  • department_id = the department ID of the chat request
Example:
function phplive_callback_chat_cancelled( department_id )
{
	alert( "The visitor cancelled the chat request for department ID " + department_id ) ;
}
An active chat session that was accepted by an operator, has ended.
This callback was included in v.4.9.16
If the chat request was accept by and operator and the chat ends (operator or the visitor ends the chat), this function will be called if it exists on the page:
phplive_callback_chat_end( department_id )
    Function Parameters
  • department_id = the department ID of the chat request
Example:
function phplive_callback_chat_end( department_id )
{
	alert( "The chat session has ended for department ID " + department_id ) ;
}
The visitor sends an offline message.
This callback was included in v.4.9.16
If the visitor sends an offline email message at the "Leave a message" email form, this function will be called if it exists on the page:
phplive_callback_offline_email_sent( department_id )
    Function Parameters
  • department_id = the department ID of the chat request
Example:
function phplive_callback_offline_email_sent( department_id )
{
	alert( "The visitor has sent an offline message for department ID " + department_id ) ;
}
Chat icon status is online
After the chat icon has loaded and the status is online, this function will be called if it exists on the page:
phplive_callback_online( department_id )
    Function Parameters
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_online( department_id )
{
	alert( "Chat status is ONLINE for department ID " + department_id ) ;
}
Chat icon status is offline
After the chat icon has loaded and the status is offline, this function will be called if it exists on the page:
phplive_callback_offline( department_id )
    Function Parameters
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_offline( department_id )
{
	alert( "Chat status is OFFLINE for department ID " + department_id ) ;
}
The visitor minimizes the chat window (embed chat)
When the embed chat window is minimized, this function will be called if it exists on the page:
phplive_callback_minimize()
    Function Parameters
  • none
Example:
function phplive_callback_minimize()
{
	alert( "Embed chat has been minimzed." ) ;
}
Note: If chat window is minimized and the visitor navigates to another page, this function will be called on the next page because the chat window has been loaded, in minimized state.
The visitor maximizes the chat window (embed chat)
When the embed chat window is maximized, this function will be called if it exists on the page:
phplive_callback_maximize()
    Function Parameters
  • none
Example:
function phplive_callback_maximize()
{
	alert( "Embed chat has been maximized." ) ;
}
Note: If chat window is maximized and the visitor navigates to another page, this function will be called on the next page because the chat window has been loaded, in maximized state.
The visitor closes the chat window (embed chat)
When the embed chat window is closed, this function will be called if it exists on the page:
phplive_callback_close()
    Function Parameters
  • none
Example:
function phplive_callback_close()
{
	alert( "Embed chat has been closed." ) ;
}
Tips & Tricks
  • CSS Open Chat - Reference the open chat function using CSS class within the span, div or link.
  • Custom Variables - Pre-populate the name, email and question or send your custom variables to the chat request window.
  • Transcript Action - When the chat session ends, process your custom PHP code to performan your custom actions.
  • Custom Console - Inject custom code to the operator console to add your custom widgets, actions and more.