How to Change Visitor Information in txt.me
If a visitor’s profile details change, you can update the information agents see during an active chat. This article shows how to set visitor information with the txt.me JavaScript SDK, either during a chat or when initializing a chatbox.
Change visitor information during an active chat
If a visitor has logged into your website, txt.me can use the profile data. So your agents will know with whom they have the conversation.
Using JS SDK
This method from the txt.me JS SDK can be called to change visitor’s parameters from your front-end:
txtme.api.setCustomUserParams({name: 'Visitor', email: 'visitor@example.com'});
If you are not sure if the chatbox has already been initialized or not, then hook to the txtmeReady event:
window.addEventListener('txtmeReady', function(){
let txtmeUserParams = {
name: 'Visitor', // optional
email: 'visitor@example.com' // optional
}
txtme.api.setCustomUserParams(txtmeUserParams);
}, false);
Both name and emails parameters are optional, you can change just name or just email.
The change is instantaneous, the agents in the
When initializing a chatbox
Using JS SDK
When creating a new chatbox, it is possible to pass an array of parameters including visitor’s data.
Use the following code as an example. Replace the 00000000000000000000000000000000 with your widget’s id.
<script type="text/javascript">
window.txtmeData = {
user: {
name: 'Visitor',
email: 'visitor@example.com'
},
};
(function (w,d,c,i) {
w[c]=w[c]||[];
var n = d.getElementsByTagName('script')[0],
s = d.createElement('script');
s.src = 'https://v2.txt.me/livechat/js/wrapper/' + i;
s.type = 'text/javascript';
s.async = true;
n.parentNode.insertBefore(s, n);
})(window,document,'txtmeData','00000000000000000000000000000000');
</script>