How can I change visitor data?

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: '[email protected]'});

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: '[email protected]'     // 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: '[email protected]'
        },
    };
    (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>

Related Posts

Was this page helpful?
YesNo
In this Article