https://www.youtube.com/watch?v=CCNPEF9a8ts

This is a supplementary instruction to go along with the video for those of better understanding for written guides.

Before proceeding please make sure to delete LiveChat tracking code if you already have it on your website or in case of installation via one of our plugins, please uninstall the plugin. Here’s an example of a script that will limit access to the chat for any IP’s whose origin is India.

<script>
var countryCode='';
function getCountryCode(data) {

countryCode = data.countryCode;
 
if(countryCode == 'IN')
{
console.log("You're from a forbidden country.");
}
 
else
{
window.__lc = window.__lc || {};
window.__lc.license = XXXXXXXX;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
}
 
 
}
</script>
<script src="<https://extreme-ip-lookup.com/json/?callback=getCountryCode>"></script>

first - please replace the following code:

window.__lc = window.__lc || {};
window.__lc.license = XXXXXXXX;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '[cdn.livechatinc.com/tracking.js](<http://cdn.livechatinc.com/tracking.js>)';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})()

with your tracking code (without the script tags), here’s an example of tracking code without <script> tags:

window.__lc = window.__lc || {};
    window.__lc.license = XXXXXXX;
    ;(function(n,t,c){function i(n){return e._h?e._h.apply(null,n):e._q.push(n)}var e={_q:[],_h:null,_v:"2.0",on:function(){i(["on",c.call(arguments)])},once:function(){i(["once",c.call(arguments)])},off:function(){i(["off",c.call(arguments)])},get:function(){if(!e._h)throw new Error("[LiveChatWidget] You can't use getters before load.");return i(["get",c.call(arguments)])},call:function(){i(["call",c.call(arguments)])},init:function(){var n=t.createElement("script");n.async=!0,n.type="text/javascript",n.src="<https://cdn.livechatinc.com/tracking.js>",t.head.appendChild(n)}};!n.__lc.asyncInit&&e.init(),n.LiveChatWidget=n.LiveChatWidget||e}(window,document,[].slice))
}

Tracking code can be found in this section: https://my.livechatinc.com/settings/code after selecting “Install LiveChat code manually”.

To change which country has no access to your chat please modify the following line:

if(countryCode == 'IN')

IN is an ISO1366 Alpha 2 code for India - you can replace it with code for any other country, for example:

if(countryCode == 'TN')

if you’d like to block Tunisian IP’s from accessing the chat.

Full list of country codes can be found here: List of ISO 3166 country codes If you’d like to restrict multiple countries from accessing the chat - you can replace above line from the example with following:

if(countryCode == ['TN' || 'AT' || 'AZ' || 'BD' || 'BJ'])

In some scenarios it’s more efficient to define which countries should be able to access the chat instead of choosing which ones can’t access it, if you’d like to do that please swap places of this part of our snippet:

console.log("You're from a forbidden country.");

with the tracking code:

window.__lc = window.__lc || {};
window.__lc.license = XXXXXXXX;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '[cdn.livechatinc.com/tracking.js](<http://cdn.livechatinc.com/tracking.js>)';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();