Tawk_API = Tawk_API || {};
Tawk_API.onStatusChange = function(status){
//place your code here
};
Tawk_API = Tawk_API || {};
Tawk_API.onOfflineSubmit = function(data){
//place your code here
};
Object used to set the visitor name and email.
Do not place this object in a function as the values needs to be available before the widget script is downloaded.
Setting or changing the values after the widget script has been downloaded will not send the values to the dashboard.
If the name and email will not be available on load time (eg single page app, ajax login), then use the setAttributes function instead.
Tawk_API = Tawk_API || {};
Tawk_API.visitor = {
name : 'Name',
email : '[email protected]'
};
Tawk_API.getStatus();
//Example
Tawk_API.onLoad = function(){
var pageStatus = Tawk_API.getStatus();
if(pageStatus === 'online'){
// do something for online
}else if(pageStatus === 'away'){
//do something for away
}else{
// do something for offline
}
};
Set custom metadata regarding this chat / visitor.
This function takes in two values; attribute and callback;
The attribute value is of Object data type which is a key value pair.
The key is of the string data type and can contain only alphanumeric characters and '-' (dash)
You can also use this function to set the visitor name and email however you will need to enable the secure mode first and supply the calculated hash value in this function too.
Refer to the secure mode section below on how to do this.
The reason it needs to be in secure mode is to ensure data integrity.
To ensure that the value sent from the widget to the dashboard
is the truth and has not been tampered with.
The callback which is a function will be invoked to notify whether the save failed.
Errors message returned :
Tawk_API.setAttributes(attributes, callback);
//Example
Tawk_API.onLoad = function(){
Tawk_API.setAttributes({
'id' : 'A1234',
'store' : 'Midvalley'
}, function(error){});
};
//Example for setting name and email
Tawk_API.onLoad = function(){
Tawk_API.setAttributes({
'name' : 'Name',
'email' : '[email protected]',
'hash' : 'hash value'
}, function(error){});
}
Tawk_API.addEvent(eventName, metadata, callback);
//Example
Tawk_API.onLoad = function(){
Tawk_API.addEvent('requested-quotation', function(error){});
Tawk_API.addEvent('product-add-to-cart', {
'sku' : 'A0012',
'name' : 'Jeans',
'price' :'50'
}, function(error){});
};
Tawk_API.addTags(tags, callback);
//Example
Tawk_API.onLoad = function(){
Tawk_API.addTags(['hello', 'world'], function(error){});
};
Tawk_API.removeTags(tags, callback);
//Example
Tawk_API.onLoad = function(){
Tawk_API.removeTags(['hello', 'world'], function(error){});
};
Tawk_API = Tawk_API || {};
Tawk_API.visitor = {
name : 'Name',
email : '[email protected]',
hash : '<calculate-hash>'
};
// Here is an example how you could do it using PHP
Tawk_API = Tawk_API || {};
Tawk_API.visitor = {
name : '<?php echo $user->name; ?>',
email : '<?php echo $user->email; ?>',
hash : '<?php echo hash_hmac("sha256", $user->email, "<API-KEY>"); ?>'
};