Viewing 15 replies - 1 through 15 (of 18 total)
  • I just found Tawk.to today (very impressed) and asked them about this as well. They have a recently released API which makes what you’re asking possible:
    https://www.tawk.to/javascript-api/

    I’ve coded a solution for you – place this in your functions.php file:

    function tawk_populate_user_info()
    {
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            echo "
    <script>
    Tawk_API = Tawk_API || {};
    Tawk_API.visitor = {
    	name  : '{$current_user->user_firstname} {$current_user->user_lastname}',
    	email : '{$current_user->user_email}'
    };
    </script>";
        } else{
            echo "
            <script>
            Tawk_API = Tawk_API || {};
            Tawk_API.hideWidget();
            </script>
            ";
        }
    }
    
    add_action('wp_footer', 'tawk_populate_user_info',100);

    Almost exactly what I am looking for!

    Is there a chance of displaying these as well as part of the chat somewhere:

    Current page / post name (the last 5 pages history would be awesome)
    The role(s) of the user

    (I currently use Smartsupp which give these things and saves a ton of basic questions as I can see what they have been doing and what access (role) they have!)

    Any suggestions would be great!

    HI – ref my previous questions

    I signed up with Tawk and found that they have answered almost everything but still would need the following to appear during a chat for all logged in users:

    user’s display name
    user’s email address (also needed for the tickets)
    user role(s)

    That would be awesome! Any ideas how to approach this?

    Bingo!!!

    I shifted from Zopim to Tawk.to today and I faced same issue in their portal. For me, that’s a very important feature they are missing out. With this feature, we can popup a personalized chat to those users.

    @mrbrian does this solution usernames in Visitor Monitoring as well?

    Yes it does :). Shows their name and email address in Visitor Monitoring before they even start a chat.

    I copied this code in wp-content/themes/{theme-name}/functions.php but in Monitoring I cannot see their names. Do I have to make any additional settings?

    Check the source of your page and ensure the javascript code is being placed in the footer. If it’s not – you’re either not logged in, the page is being cached, or your code is not in the current theme.

    @247web It’s currently not possible to pass anything other than the name and email address to Tawk.to. As far as current post/page they are on Tawk already does that – there is an activity timeline for every chat session.

    Hi @mrbrian

    Sorry, I am still not able to see name of visitors.

    1) I double checked and found that visitors are logged in.

    2) I emptied my whole website cache.

    3) I installed plugin in https://edudrona.com/. Tawk.to’s code is in bottom of page. Can you please have a check once.

    Your Tawk.to code is different than mine. I guess because I use the code given by Tawk.to website rather than this plugin.

    In my code, replace:
    Tawk_API = Tawk_API || {};

    with:
    Tawk_API = $_Tawk_API || {};

    I replaced this line in both the places but it’s still not working. I am getting error in Javascript console as well after replacing this code.

    edudrona.com/:3478 Uncaught SyntaxError: Unexpected token ||

    Here’s revised code:

    function tawk_populate_user_info()
    {
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            echo "
    <script>
    $_Tawk_API.visitor = {
    	name  : '{$current_user->user_firstname} {$current_user->user_lastname}',
    	email : '{$current_user->user_email}'
    };
    </script>";
        } else{
            echo "
            <script>
            $_Tawk_API.hideWidget();
            </script>
            ";
        }
    }
    
    add_action('wp_footer', 'tawk_populate_user_info',100);

    Hi Mr Brian

    Thanks for your script and your time – its most appreciated. Unfortunately the script is definitely not working after much testing, clearing caches, different IP address for chats, etc. etc.

    Writes correct info to the footer after \$ escaping for the API lines.
    It is not populating any Name or Email fields inside the Tawk Dashboard.
    I am using the “official” Tawk plugin downloaded yesterday

    Such a pity because its great that Tawk has a Support ticketing.
    Looks as though I will have to go back to Smartsupp.

    Thanks for your help again.

    Ah, I forgot php would see those as functions. I don’t know why this plugin adds $ for the javascript variables anyway. Last try, this should work.

    function tawk_populate_user_info()
    {
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            echo '
    <script>
    $_Tawk_API.visitor = {
    	name  : "' . $current_user->user_firstname . ' ' . $current_user->user_lastname . '",
    	email : "' . $current_user->user_email . '"
    };
    </script>';
    }
    add_action('wp_footer', 'tawk_populate_user_info',100);
Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Should get username and email automatically for logged-in users’ is closed to new replies.