The following snippet will detect if the visitor is using a mobile device:
JS

const isMobile = /iPhone|iPad|iPod|Android|Opera Mini|BlackBerry|IEMobile|WPDesktop|Windows Phone|webOS|/i.test(navigator.userAgent);
if (isMobile) {
    console.log('Device is mobile');
}