NAV Navbar



Sometimes it will be helpful to know the ID of the currently-active widget, especially if you use .setWidgetId() to change the active widget on the fly.

No Parameters


// An example widget ID is returned from the call above
Type Description
String Returns a String that is the full widget ID of the currently active widget. (Alphanumeric plus dashes.)

An example return value of is inside the code example.

Example getWidgetId() Usage

Send a system message to the agent based on the widget ID
SnapEngage.setCallback('StartChat', function(email, msg, type) {
    var success = false;
    var tid;

    function sendWidgetName() {
        var currWidget = SnapEngage.getWidgetId();

        // For each different widget ID, send a message to the agent with that widget's name
        switch (currWidget) {
            case 'xxxxx-xxxx-xxxx-xxxx' :
                success = SnapEngage.sendTextToChat('A Widget\'s Name');
            case 'yyyyyy-yyyy-yyyy-yyyyy' :
                success = SnapEngage.sendTextToChat('Other Widget\'s Name');
            default :
                success = SnapEngage.sendTextToChat('Error fetching Widget Name');

    // Call the function above

    if (!success) {

        // Try again every two seconds until success.
        tid = setTimeout(sendWidgetName, 2000);

Send a message to the agent that changes for each different widget ID. This code sample uses getWidgetId() along with the StartChat JavaScript event and sendTextToChat().