Skip to main content

Intro

The Experience JS SDK provides functions to customize and extend experiences published with Wyng. The SDK comprises these major functional areas:

  • Action Dispatcher
  • Event Listener
  • Setting Values
  • Overriding Components
  • Custom Metrics

This SDK allows developers to programmatically interact with experiences through a global wyng object. You can write custom javascript that sets a value, dispatches an event, or registers a callback function for a given event.

Your code may be published as part of the experience by using the "Custom JavaScript" field in the experience editor. Alternatively, if the experience is embedded on a web page as an inline embed, you can access the SDK from other JavaScript code on the web page.

The SDK is located at the window level and scoped by experience ID. The methods can be accessed through window.wyng['YOUR EXPERIENCE ID']. For convenience, when inserting JavaScript through the "Custom JavaScript" field in the experience editor, you may use the special _WYNG_ID_ tag, which will automatically be replaced with the active experience ID.

We recommend you scope your custom code with an Immediately-Invoked Function Expression to avoid unintended interactions with other JavaScript when embedding the experience on a web page.

A good starting point is something like this:

(function() {
const sdk = window.wyng['_WYNG_ID_'];
// YOUR CUSTOM JAVASCRIPT
})();

Local User ID

Across Wyng platforms an anonymous Local User ID will be assigned to a visitor. This ID is used to identify return visitors, and is scoped by the fully qualified domain of the containing web page, and stored in browser localStorage on the visitor's device.

Example

Get the value of the Local User ID. If no value has been set yet, a value will be randomly generated.

window.wyng['_WYNG_ID_'].getLocalUserId()