$zopim.livechat

Zopim Live Chat API

Some aspects of the Zopim widget can be customized.  For example, you can generate Javascript to set a visitor’s name and email after logging in.  If our language auto-detection is not accurate, you can override it with setLanguage.

Most API functions return the API object itself so you can chain multiple calls together.

IMPORTANT: The only 2 calls you can make safely after the given Zopim script are

  • $zopim(function() { ...  })
  • $zopim.set({ ....  })

All other API calls should be wrapped inside a $zopim(function() { ...  }).

Also, see the component specific classes, $zopim.livechat.bubble and $zopim.livechat.window.

Examples

<script>

  $zopim(function() {
    $zopim.livechat.setName('Logged in name');
    $zopim.livechat.setEmail('user@somewhere.com');
  });

</script>
<script>

  $zopim(function() {
    $zopim.livechat.set({
      language: 'fr',
      name: 'Visitor',
      email: 'visitor@site.com',
      onStatus: function(s) { alert(s) }
    });
  });

</script>
Summary
$zopim.livechatZopim Live Chat API
Functions
setA convenience function to set more than 1 setting.
sayMake the visitor say something.
setNameSet the visitor’s name
setEmailSet the visitor’s email
setNotesSet the visitor’s notes, which will show up on the Dashboard.
setLanguageShows the interface in the language specified.
setGreetingsSets greeting messages
setOnStatusAdds a callback function that’s called with the status whenever the online status changes.
setOnGreetingAdds a callback function that’s called with the greeting whenever the online status changes.
setStatusSets visitor status to ‘active’ or ‘idle’.

Functions

set

function set(hash)

A convenience function to set more than 1 setting.  Accepts a hash of settings.

Parameters

hashAn object of <setting_name> => <value> pairs

say

function say(something,
suggestion)

Make the visitor say something.  If the 2nd parameter is true, it’ll only be a suggestion :)

Examples

<table width="100%" style="font-family: Arial" cellspacing="0" cellpadding="0">
  <tr>
    <th>Product</th>
    <th>Price</th>
  </tr>
  <tr>
    <td><img src="/images/sesame.jpg"> Sesame </td>
    <td>20,000 raisins</td>
  </tr>
  <tr>
    <td><img src="/images/pistachio.jpg"> Pistachio </td>
    <td><a href="javascript:void($zopim.livechat.say('I\'d like a quote for Pistachio!'))">ask!</a></td>
  </tr>
</table>

setName

function setName(name)

Set the visitor’s name

Parameters

nameThe visitor’s name

setEmail

function setEmail(email)

Set the visitor’s email

Parameters

emailThe visitor’s email

setNotes

function setNotes(notes)

Set the visitor’s notes, which will show up on the Dashboard.

Parameters

notesNotes, maximum 2048 UTF-8 characters.  Newlines are allowed.

Examples

Chinchillas:
<a href="javascript:void($zopim.livechat.setNotes('Added white chinchilla to basket'))">Add White to Basket</a>
<a href="javascript:void($zopim.livechat.setNotes('Added standard grey chinchilla to basket'))">Add Standard Grey to Basket</a>

setLanguage

function setLanguage(lang)

Shows the interface in the language specified.  Please visit http://translate.zopim.com/ to see the list of supported languages.

Parameters

subtagLanguage code listed at http://www.iana.org/assignments/language-subtag-registry

Examples

Pick a language:
<a href="javascript:void($zopim.livechat.setLanguage('en'))">English</a>
<a href="javascript:void($zopim.livechat.setLanguage('pt'))">Portuguese</a>
<a href="javascript:void($zopim.livechat.setLanguage('sv'))">Swedish</a>
<a href="javascript:void($zopim.livechat.setLanguage('zh_CN'))">Chinese</a>

setGreetings

function setGreetings(g)

Sets greeting messages

Parameters

greetingsHash of <status> => [<short msg>, <long msg>]

Examples

$zopim(function() {
  $zopim.livechat.setGreetings({
    'online':  ['online short message',  'online long message'],
    'offline': ['offline short message', 'offline long message'],
    'away':    ['away short message',    'away long message']
  });
});

setOnStatus

var last_known_status; api.on(
    'status',
   function(s) { last_known_status = s }
); function setOnStatus(f)

Adds a callback function that’s called with the status whenever the online status changes.  Remember to put your script after the Zopim script.

setOnGreeting

function setOnGreeting(f)

Adds a callback function that’s called with the greeting whenever the online status changes.  The callback function will be called with an object with 2 properties: bar & window, corresponding to the appropriate greeting.  Remember to put your script after the Zopim script.

Example

Livechat is: <b id="chat_status">checking...</b><br/>
Bar: <i id="chat_greeting_bar"></i><br/>
Window: <i id="chat_greeting_window"></i><br/>
<script>
  function updateStatus(s) {
    document.getElementById('chat_status').innerHTML = s;
  }

  function updateGreeting(g) {
    document.getElementById('chat_greeting_bar').innerHTML = g.bar;
    document.getElementById('chat_greeting_window').innerHTML = g.window;
  }

  $zopim(function() {
    $zopim.livechat
      .setOnStatus(updateStatus)
      .setOnGreeting(updateGreeting);
  });
</script>

setStatus

function setStatus(s)

Sets visitor status to ‘active’ or ‘idle’.

function set(hash)
A convenience function to set more than 1 setting.
function say(something,
suggestion)
Make the visitor say something.
function setName(name)
Set the visitor’s name
function setEmail(email)
Set the visitor’s email
function setNotes(notes)
Set the visitor’s notes, which will show up on the Dashboard.
function setLanguage(lang)
Shows the interface in the language specified.
function setGreetings(g)
Sets greeting messages
var last_known_status; api.on(
    'status',
   function(s) { last_known_status = s }
); function setOnStatus(f)
Adds a callback function that’s called with the status whenever the online status changes.
function setOnGreeting(f)
Adds a callback function that’s called with the greeting whenever the online status changes.
function setStatus(s)
Sets visitor status to ‘active’ or ‘idle’.