General
  • 26 Jul 2022
  • 2 Minutes to read
  • Dark
    Light

General

  • Dark
    Light

Article Summary

General

Site ID

You can use API to get ID of your site, example is shown below:

/** @type {number} */
const siteId = Comm100API.get('livechat.siteId');

All Campaign ID

You can use API to get all IDs of campaign used on current page. Notice that the API returns an
array of IDs as you might have multiple campaigns installed on current page.

/** @type {Array<string>} */
const campaignIds = Comm100API.get('livechat.campaignIds');

Dynamic Campaign

Get

You can use API to determine whether dynamic campaign feature is enabled on current page.

/** @type {boolean} */
const isDynamicCampaign = Comm100API.get('livechat.isDynamicCampaign');

Event

When dynamic campaign is enabled, the campaign used on your page might vary due to condition changes.
You could register a callback to listen to such changes, as shown below:

/**
 * @param {string} currentCampaignId - Current Campaign ID
 */
function subscribe(currentCampaignId) {
  // do stuff here
}
const unsubscribe = Comm100API.on('livechat.dynamicCampaign.change', subscribe);

Please notice that this API will return an unregistration function, which can be used to stop
listening to this event.

Mobile

You can use API to determine if current visitor is using Mobile device to browse your website.
Notice that Comm100 Live Chat will have different behavior for mobile devices. This API will tell
you whether these behavior for mobile has been enabled or not.

/** @type {boolean} */
const isMobile = Comm100API.get('livechat.isMobile');

Custom Variable

You can use API to manually set custom variables. To do this, you need to provide an array of custom
variables that you wish to set. Each element inside array should be an object containing name and
value attribute, where name should be the name of custom variable you defined in Control Panel,
and value is it's current value.

Please notice that value should be a string, otherwise to will be converted to string using built-in
toString(). Also, if undefined is assigned to value, it will be ignored and will not update this
custom variable.

Example is shown below:

const values = [
  {
    name: 'custom variable 1',
    value: 'current value',
  },
  {
    name: 'non-existant custom variable',
    value: 'current value',
  },
  {
    name: 'ignored custom variable',
  },
];
Comm100API.set('livechat.customVariables', values);

In example above, custom variable custom variable 1 will be updated using value current value,
while non-existant custom variable will not be updated if it's not defined in Control Panel. Also,
custom variable ignored custom variable will not be updated as it's value is undefined.

Visitor

You can use API to get the GUID (Globally Unique Identifier) of current visitor. The GUID is ensured
to be different for each visitor.

/** @type {string} */
const guid = Comm100API.get('livechat.visitor.guid');

Was this article helpful?

What's Next