Load a new chatbot for repeating visitors

Load a new chatbot for repeating visitors

Using the following script, you can show a new chatbot to your visitor, if that visitor has already had a conversation with the first chatbot. This is useful to welcome back a user who is showing interest and collect data from them in a different approach.

Here is a demo of the same. You can reload the page after having a complete conversation with the first bot. Then you will see a different chatbot.

Snippet Code

/* Function to read cookies by name */
function readCookie(name) {
    return (name = new RegExp('(?:^|;\\s*)' + ('' + name).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + '=([^;]*)').exec(document.cookie)) && name[1];
}
/* collect_chat_completed is a cookie that stores the number of times the bot has been closed*/
if (readCookie("collect_chat_completed") <= 0){
  /* Add the snippet code of your first chatbot to displayed here */
  (function(w, d) { w.CollectId = "5c92216ff57f226e435591fd"; 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);
} else {
  /* Add the snippet code the second chatbot to be displayed here */
  (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);
}

Code Explained

This works using the cookie - collect_chat_completed. When visitor completes the conversation with the first chatbot, the count of this cookie is incremented by 1. So we use this logic to load the second chatbot. You simply have to replace the snippet codes of the first and second chatbot with ones that you want to use in the above code.

Add the above code snippet to the webpages (or even your WordPress plugin) where you want this functionality.

Note

The method suggested here requires a small amount of developer knowledge and we urge you take assistance of someone from your team, incase you are unable to follow the above.



Still need help?

Contact us

Customize