Insert Custom Data into Session
The Cue widget allows you to pass custom data from a web page into a user's session that can be used in a flow.
Ensure you do not perform sensitive actions in flows with data submitted via this method, as this method can be used by any public user via the console in their browser.
Passing Custom Data
You can use CueWidget.updateInitialSessionData()
to pass a flat object of key-value pairs into the user's session when a new session starts. You can then access this data in your flow logic. You can also pass null
or undefined
to unset these values.
Since CueWidget
methods may not be available immediately when the page loads, ensure that window.CueWidget
is accessible before calling any methods. The safest approach is to use the onReady
callback function.
Example Implementation
<script>
window.cueWidgetConfig = {
id: "00000000-0000-0000-0000-000000000000", // Replace with your widget ID
onReady: function () {
// Set custom data to be included in a new session. E.g. Tracking ID.
CueWidget.updateInitialSessionData({
trackingId: "a8f5f167f44f4964e6c998dee827110c",
});
},
};
var s = document.createElement("script");
s.dataset.cueWidgetScript = "true";
if (window.requirejs && window.requirejs.defined) {
s.src = "https://webchat.cuedesk.com/widget.iife.js";
} else {
s.src = "https://webchat.cuedesk.com/widget.js";
}
document.head.appendChild(s);
</script>
For the above example, once a user starts a new web chat conversation, you will be able to access the tracking ID in your flow with: {{session.trackingId}}
Checking Widget Availability
If you need to update session data outside of onReady, ensure CueWidget is available before calling any methods:
if (window.CueWidget && CueWidget.isReady) {
CueWidget.updateInitialSessionData({ trackingId: "12345" });
} else {
console.warn("CueWidget is not yet ready.");
}
By following this approach, you ensure that CueWidget
methods are only called when the SDK is fully loaded and accessible.