How to set custom context variables?
-
Hi,
How can I send custom data as context variables to the chat?
Thanks
-
Hello @nicoter.
Could you please describe in more detail your issue?Hi @intelahelp
The goal is to track conversion with e.g. Microsoft advertising (Bing ads).
When auto-tagging of MSCLKID is enabled, the URL will contain a unique ID named MSCLKID which can be stored in a cookie. Next I need to pass the value of the MSCLKID as context variable to the Watson assistant so I can save it with the conversations (which get sent to to our email).
Thanks
Hello @nicoter.
All context variables are stored in your browser’s Local Storage, so to add new ones you don’t need to save a unique identifier with the name MSCLKID in a cookie. It can be immediately added to the object with context variables using JavaScript code, for example, you can add the following code to your site:window.onload = function(){ // get current url let currentUrl = window.location.href; let url = new URL(currentUrl); // get access to URLSearchParams object let search_params = url.searchParams; // get url parameter value of the MSCLKID let msclkid = search_params.get('MSCLKID'); if(msclkid) { // get Local Storage item 'watson_bot_state' let watsonBotState = JSON.parse(localStorage.getItem('watson_bot_state')); // get context variables object from 'watson_bot_state' let contextVariables = watsonBotState.context.skills['main skill'].user_defined; // adding new context variables contextVariables.MSCLKID = msclkid; // rewriting Local Storage item 'watson_bot_state' with a new context variable localStorage.setItem('watson_bot_state', JSON.stringify(watsonBotState)); } }Hello @nicoter.
We haven’t heard from you recently.
Do you still have any questions or need our assistance?
We will gladly help you.Topic was in a Waiting state for longer than 7 days, Topic was automatically resolved
Hi,
Thanks for the code and explanation.
I didn’t test it yet as we were considering moving away from IBM Watson because of the serious performance issues.
Since this has been resolved to some degree (pages with the chatbot window are still very slow), I’ll look into this soon.
Thanks for your patience and help!
Thank you for letting us know.
The topic ‘How to set custom context variables?’ is closed to new replies.