Using the following snippet code, you can show a new form to your visitor if that visitor has already completed the first form. 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. After completing the first form, reload the page to see a different form appear.
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 form 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 form 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 first form, the count of this cookie is incremented by 1. So we use this logic to load the second form.
You simply have to replace the snippet codes of the first and second form 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 in case you are unable to follow the above code logic.
Still need help?
Contact us