3 Ways to set name and email through the JavaScript API

By default, all visitors are assigned unique ID’s that start with a the letter V and a number sequence ex. V1504031129380818. But if you would like to identify customers from visitors, here are three ways you can set the name and email through our javascript API.

1. Secure Javascript disabled

With Secure javascript API Disabled the user’s name and email are available on widget load, use the following script:

<script type="text/javascript">
var Tawk_API=Tawk_API||{};
Tawk_API.visitor = {
name : 'visitor name',
email : 'visitor@email.com'
};

var Tawk_LoadStart=new Date();
<!-- rest of the tawk.to widget code -->
</script>

2. Secure JavaScript enabled

With Secure javascript API Enabled the user’s name and email are available on widget load, use the following script:

<script type="text/javascript">
var Tawk_API=Tawk_API||{};
Tawk_API.visitor = {
name : 'visitor name',
email : 'visitor@email.com',
hash : 'hash-value'
};

var Tawk_LoadStart=new Date();
<!-- rest of the tawk.to widget code -->
</script>

Note:

– Hash value can be computed using the following php example

<?php echo hash_hmac(“sha256″,”visitor@email.com”,”your-api-key”); ?>

Click here to learn how to enable Secure Javascript API
– Make sure that you are using the correct api key

3. Single page app (website) or AJAX login

If you have a single page app (website) or AJAX login, use the setAttribute function. For this you will need to have Secure javascript API Enabled and add the calculated hash value.

<script type="text/javascript">
var Tawk_API=Tawk_API||{};
var Tawk_LoadStart=new Date();
<!-- rest of the tawk.to widget code -->

<script type="text/javascript">
Tawk_API.onLoad = function(){
Tawk_API.setAttributes({
'name' : 'visitor',
'email': 'visitor@email.com',
'hash' : 'hash-value'
}, function (error) {});

};
</script>
<!--End of Tawk.to Script-->

Note:

Click here to learn how to enable Secure Javascript API
– Hash value can be computed using the following php example

<?php echo hash_hmac(“sha256″,”visitor@email.com”,”your-api-key”); ?>

© 2019 tawk.to inc. All Rights Reserved.