Support » Plugin: Chatbot with IBM Watson » How to set custom context variables?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support intelahelp

    (@intelahelp)

    Hello @nicoter.
    Could you please describe in more detail your issue?

    Thread Starter nicoter

    (@nicoter)

    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

    Plugin Support intelahelp

    (@intelahelp)

    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));
        }
    }
    
    
    Plugin Support intelahelp

    (@intelahelp)

    Hello @nicoter.

    We haven’t heard from you recently.
    Do you still have any questions or need our assistance?
    We will gladly help you.

    Plugin Support intelahelp

    (@intelahelp)

    Topic was in a Waiting state for longer than 7 days, Topic was automatically resolved

    Thread Starter nicoter

    (@nicoter)

    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!

    Plugin Support intelahelp

    (@intelahelp)

    Thank you for letting us know.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to set custom context variables?’ is closed to new replies.