Support » Plugin: LiveChat - WP live chat plugin for WordPress » Loading different group based on device

  • Resolved ryann0tgosling

    (@ryann0tgosling)


    Hello guys!

    I have integrated your LiveChat plugin with my WordPress and I was wondering if there is any way to specify which group created by me should load for which device.

    To provide a better explanation, let me give you an example:
    Let’s say that a customer is visiting my page from his iPhone. Is it possible for LiveChat to load a specific group for that customer, as opposed to a customer visiting my website from desktop computer?

    I will truly appreciate any tip/advice from you guys!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author LiveChat

    (@livechat)

    Great question, @ryann0tgosling!

    If you have a mobile version of your website with a sub-domain as such m.yourwebsite.com, you can load a specific group for mobile users using the URL rules functionality https://www.livechatinc.com/kb/setting-up-url-rules-for-groups/#changing-customization (/user visits a page address/ + /that contains/ + m.yourwebsite.com).

    Hope this helps.

    Plugin Author LiveChat

    (@livechat)

    Hello again @ryann0tgosling! We have got one additional solution for you. If you’d like to truly load specific groups based on a mobile device (group A for iPhone users for example), we have prepared a PHP script that will do just that. It will require adding LiveChat code to your WordPress manually (instead of a plugin) but it will do the work. You can check the example representing both, the script and the LiveChat code below:

    <?php 
    function getUserAgent()
    {
        $agent = null;
    
        
            $agent = $_SERVER['HTTP_USER_AGENT'];
            if ( stripos($agent, 'iPhone') !== false ) {
                $agent = 'iphone';
            }  elseif ( stripos($agent, 'iPad') !== false ) {
                $agent = 'ipad';
            } elseif ( stripos($agent, 'Android') !== false ) {
                $agent = 'android';
            } elseif ( stripos($agent, 'Chrome') !== false ) {
                $agent = 'chrome';
            } elseif ( stripos($agent, 'Safari') !== false ) {
                $agent = 'safari';
            } elseif ( stripos($agent, 'Firefox') !== false ) {
                $agent = 'firefox';
            } 
        
    
        return $agent;
    }
    
    $agent = getUserAgent();
    
    $group = 0;
    
    if($agent === 'iphone' || $agent === 'ipad' || $agent === 'android')
    {
        $group = X;
    }
    else if($agent === 'chrome' || $agent === 'safari' || $agent === 'firefox')
    {
        $group = X;
    }
    
    ?>
    <script type="text/javascript">
                var __lc = {};
                __lc.license = 7536651;
                __lc.group = <?php echo $group; ?>;
                (function () {
                    var lc = document.createElement('script');
                    lc.type = 'text/javascript';
                    lc.async = true;
                    lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
                    var s = document.getElementsByTagName('script')[0];
                    s.parentNode.insertBefore(lc, s);
                })();
                
                
     </script>

    This script detects the mobile user agent and, based on that, can load a different group. In the example above the script will load different group for iOS and Android visitors and different groups for desktop visitors.

    NOTE that the group is represented by X – remember to replace X with the numeric representation of your group ID. How to find it? The easiest way is to go to your LiveChat Groups section (or click here to get right there) > choose a group > the ID of this group will be displayed at the end of the URL.

    I hope that we were able to help! In case of any additional issues, please don’t hesitate to ask.

    • This reply was modified 2 years, 9 months ago by LiveChat. Reason: Added code formatting
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loading different group based on device’ is closed to new replies.