Show bot based on country


#1

Hi, I saw your article to NOT SHOW the bot when the user comes from specific countries
https://help.collect.chat/article/show/87549-show-bot-based-on-country

Can you please write to code, but in the other way, TO SHOW the bot when user comes from a specific country?
thanks in advance
regards
Octavio
PA. Congratulations, lovely software


#2

Hi Ocatvio,

For that you just need to change the condition. Here you go:

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
/* 
List of countries where you want the bot to be loaded.
Modify this list as per your need.
*/
var list = {
  "IN": "India",
  "GB": "United Kingdom"
};
$.get("https://ipinfo.io", function(response) {
   /* Check if response.country is in list */
   if(JSON.stringify(list).indexOf(response.country) >= 0) {
       /* The country of visitor is not in blocked_list, so you can load the chatbot snippet code */
       (function(w, d) { w.CollectId = "5c75363c7744836a0231a583"; var h = d.head || d.getElementsByTagName("head")[0]; var s = d.createElement("script"); s.setAttribute("type", "text/javascript"); s.setAttribute("src", "https://collectcdn.com/launcher.js"); h.appendChild(s); })(window, document);
   }
}, "jsonp")
</script>

Try this. It should work


#3

Hi Aslam,
Yes, I inserted the code in wordpress.
Changed the w.CollectId and inserted the country “ES”, I believe it’s for spain, also included india.
It worked perfect !! :heart_eyes:
thanks
Octavio


#4

Dear Aslam,
I’ve news with the country allowed. This is part of the code I’m using now


List of countries where you want the bot to be loaded.
Modify this list as per your need.
*/
var list = {
“IN”: “India”,
“ES”: “Spain”
};

And it works for Spain perfect !!
Happen that yesterday was talking with a person from Chile, and she was able to see the chatbot.
I only allowed “ES” = Spain (http://country.io/spain/ )
https://ipinfo.io/developers/full-country-names
How can is ir possible?
Thanks in advance
Octavio


#5

Hi there,

The method I shared is not error-proof. The following scenarios could have happened.

  • She was using a VPN service or an IP changing service on her browser
  • Her browser may have plugins that blocked the site ipinfo
  • The site ipinfo may not have send and received the request in time

The code we shared is just a sample code to guide you in the right direction. It can be further optimized and there are alternate methods to do the same as well.

This is something you will have to discuss with the developers in your team and resolve it. We can only help you with the chatbot that you made on Collect.chat. We cannot be of much help when it comes to over-the-top tweaks like these.

Thanks for understanding,
Aslam from Collect.chat


#6

Yes, it’s ok for me
thanks