tawk / tawk-drupal

10 stars 9 forks source link

Failed to set Visitors name and mail from Drupal module #1

Closed pablo-tapia closed 3 years ago

pablo-tapia commented 8 years ago

I'm using the module in a development site, the widget is loading nicely and it's using the remote configurations I set on my dashboard. Now I'm trying to set the name and email by default when the user access the site but so far I'm out of luck.

Here's the code I'm using:

### global `$user;

$user = user_load($user->uid);
$name = (int) $user->uid > 0 ? $user->field_first_name['und'][0]['value'] .' '. $user>field_last_name['und'][0]['value'] : $user->name;
  $email = (int) $user->uid > 0 ? $user->mail : '';

  return t('<!--Start of Tawk.to Script-->
    <script type="text/javascript">
        var Tawk_API = Tawk_API || {}, Tawk_LoadStart = new Date();
        (function(){
            var s1 = document.createElement("script"), s0 = document.getElementsByTagName("script")[0];
            s1.async = true;
            s1.src = "https://embed.tawk.to/@p/@w";
            s1.charset = "UTF-8";
            s1.setAttribute("crossorigin","*");
            s0.parentNode.insertBefore(s1,s0);
        })();

        Tawk_API.onLoad = function() {
            Tawk_API.visitor = {
                name  : \'@n\',
                email : \'@m\'
            };
            console.log("@m");
        };
    </script><!--End of Tawk.to Script-->', array('@p' => $page_id, '@w' => $widget_id, '@m' => $email, '@n' => $name));

(BTW I'm using the t function which I believe makes sense because it's cleaner code)

The events are loading correctly and the variable is set with the correct data but the widget never get's the name, it always ask me to set it manually. Am I doing something wrong here?

GeekOfAges commented 3 years ago

This issue has been fixed on master and visitor details are being set here