Detect if a visitor is on Mobile or Desktop

To suit a better experience or a different solution depending on the device the user is browsing with, we can set up a "detector" and a condition to redirect the user one way or another. Also we can keep this information for later use.

Check this link if you want to see it in action: Detect Mobile

We are going to use an external Javascript Library, called Mobile Detect JS. This is going to be our flow:

  1. As we want to detect the device used as soon as the bot loaded, we will need to add the following code in the Design / Advanced / Add JS section:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.4.3/mobile-detect.js"></script>
<script>
var detector = new MobileDetect(window.navigator.userAgent);
var mobile;

if (detector.phone() === null){
mobile = "false"
} else {
mobile = "true"
}

Landbot.exec('landbot-custom-data',{"mobile": mobile })
</script>

  1. Right after the Welcome Message, we will have available the value (true or false) in the variable "mobile" that we need to create in Landbot, with the format of a String:

  1. Now, right after the welcome message, add Conditional block as below:

That's it, now you have created 2 flows to redirect users based on their device. Also the variable mobile will be available for you.


How did we do?