.getWidgetId()
(Last Updated On: August 20, 2013)
Overview

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.

SnapEngage.getWidgetId();


Returns
Type
String
Values
The full Widget ID of the currently active widget. (Alphanumeric plus dashes.)
Example: 1z1z1z1z1-y2y2-x3x3-w4w4-v5v5v5v5v5v

No Parameters


Example Usage


Send a system message based on the Widget ID
 // Place in JS API section of the "Advanced" Code Snippet

setCallback("StartChat", function(email, msg, type) {
	var success = false,
		tid;

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

		switch (currWidget) {
			case "xxxxx-xxxx-xxxx-xxxx" :
				success = SnapEngage.sendTextToChat("A Widget's Name");
				break;
			case "yyyyyy-yyyy-yyyy-yyyyy" :
				success = SnapEngage.sendTextToChat("Other Widget's Name");
				break;
			default :
				success = SnapEngage.sendTextToChat("Error fetching Widget Name");
				break;
		}
	}

	sendWidgetName();
	if (!success) {
		clearTimeout(tid);
		tid = setTimeout(sendWidgetName, 2000); // Try again every two seconds until success.
	}
});