Home > How to remove Chat for visitors on mobile devices
Categories: JavaScript API
(Last Updated On: )
About This Article
The purpose of this article is to provide a comprehensive overview of how to remove Chat for visitors on mobile devices.
While a significant amount of website visitors now use mobile devices, you might not want to offer chat to visitors on your website using mobile devices. That is why you have the option to not load SnapEngage on mobile browser pages.
To remove chat from visitors on mobile devices, you would need to wrap your SnapEngage code in a JavaScript “if” statement which should be checking if the visitor is on a mobile browser:
This is how the code block would look on your website:
How to remove Proactive Chat for visitors on mobile
If you want to just deactivate Proactive Chat for visitors on mobile devices but still allow manual chats, you will need to adjust and place elsewhere in the code the above “if” statement.
The code snippet you need to add to your SnapEngage code is:
SnapEngage.allowProactiveChat(false);
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|Android|IEMobile)/)) {
SnapEngage.allowProactiveChat(true);
}
This is how the code block would look on your website:
(function() {
var se = document.createElement('script'); se.type = 'text/javascript'; se.async = true;
se.src = '//storage.googleapis.com/code.snapengage.com/js/xxxx-xxxxx-xxxxx-xxxxx.js';
var done = false;
se.onload = se.onreadystatechange = function() {
if (!done&&(!this.readyState||this.readyState==='loaded'||this.readyState==='complete')) {
done = true;
SnapEngage.allowProactiveChat(false);
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|Android|IEMobile)/)) {
SnapEngage.allowProactiveChat(true);
}
// Place your SnapEngage JS API code below
// SnapEngage.allowChatSound(true); // Example JS API: Enable sounds for Visitors.
}
};
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(se, s);
})();
Please mind that the code above is using a non-existent SnapEngage account widget “xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx”. You should use your own code snippet instead.
Published September 24, 2012
Reader Feedback
No comments yet