Wix.Worker

addEventListener

Allows the worker component to listen to events that happen in the editor or website.

SDK Version: SDK 1.11.0 - 1.96.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Make sure to register event listeners when the document loads, since previous listeners might be invalidated when we load your app.

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)Wix.EventsUnique event identifier, listed in the table below
callback (required)Function A callback function that is called by the SDK once an event occurs.

The events that you can currently listen to are:

EventEvent DataDescription
COMPONENT_DELETED{}Issued when the user deletes a site component. Note: This event is only sent to the component that was deleted, so use the Wix.PubSub.publish method to alert other site components in your app about this event. For worker components, use Wix.Worker.PubSub.publish. Availability: Since 1.13.0
DEVICE_TYPE_CHANGED{ deviceType: 'desktop' or 'mobile' }Issued when the user switches between the desktop editor and mobile editor. Availability: Since 1.45.0
EDIT_MODE_CHANGE {editMode: 'editor'  or 'preview'}Issued when a user toggles between preview and edit mode in the editor. Availability: Since 1.11.0
INSTANCE_CHANGED{instance: instanceValue}Issued when a component in your app called Wix.revalidateSession in the live site. Availability: Since 1.96.0
KEY_DOWN{charCode:0, keyCode:39}Issued when the user presses one of these keys on the keyboard: left/right arrows, esc, enter, space bar. Availability: Since 1.76.0
KEY_UP{charCode:0, keyCode:39}Issued when the user presses one of these keys on the keyboard: left/right arrows, esc, enter, space bar. Availability: Since 1.76.0
MEMBER_DETAILS_UPDATEDFor example: "attributes": {"name": "John Doe", "firstName": "John", "lastName": "Doe", "imageUrl": "https://myImage.jpg", "nickname": "Johnny "}}Issued when a member changes their personal details. Availability: Since 1.89.0
PAGE_NAVIGATION{"toPage": "Page1", "fromPage": "Page2"}Issued on any page navigation in the website. Availability: Since 1.25.0
PAGE_NAVIGATION_IN{"toPage": "Page1", "fromPage": "Page2"}Issued on any page in navigation in the website. This event is a utility event on top of the PAGE_NAVIGATION event. Availability: Since 1.25.0
PAGE_NAVIGATION_OUT{"toPage": "Page1", "fromPage": "Page2"}Issued on any page out navigation in the website. This event is a utility event on top of the PAGE_NAVIGATION event. Availability: Since 1.25.0
PUBLIC_DATA_CHANGED{   key1: value1   }Issued when app data is changed using Wix.Data.Public methods. Note that all registered components will get this event. Availability: Since 1.74.0
SCROLL{"scrollTop": 4, "scrollLeft": 0, "documentHeight":  724, "documentWidth":  1227, "x": 124, "y": 131, "height": 682, "width": 978, "left": 124.5, "bottom": 809, "right": 1102.5, "top": 127}Issued when scroll happens inside the site. The event data contains multiple details that helps the app determine its behavior considering its position in the site, the browser window dimensions, and the scrolling state: * ScrollTop - site's scroll position on the y axis, * scrollLeft - site's scroll position on the x axis, * documentHeight - site's document height, * documentWidth - site's document width, * x - app offset within the site's page on the x axis, * y - app offset within the site's page on the y axis, * height - app height, * width - app width, * left - app top-left offset from the left, * bottom - app top-left offset from the bottom, * right - app top-left offset from the right, * top - app top-left offset from the top. Availability: Since 1.25.0
SETTINGS_UPDATEDCustom jsonIssued by the App Settings endpoint when new settings are applied by the user. Availability: Since 1.17.0
SITE_METADATA_CHANGED{  title: 'example title',  description: 'example description' }Issued when the page metadata (title, description) changes. Availability: Since 1.75.0
SITE_PUBLISHED{}Issued when the user publishes the website. Availability: Since 1.13.0
SITE_SAVED{}Issued when the user saves the website. Availability: Since 1.62.0
STATE_CHANGED{newState: 'state'}Issued when the website state changed. Read more about the component's state and deep linking here. Availability: Since 1.29.0
STYLE_PARAMS_CHANGE{colors: Object, numbers: Object, booleans: Object, fonts: Object}Issued when the user changed a color, font, number, or boolean value in your app’s settings panel. Availability: Since 1.22.0
THEME_CHANGE{fonts: Object, siteTextPresets: Object, siteColors: Array (30 colors of palette), style: Object}Issued when the user changed the site’s color palette. Availability: Since 1.22.0
WINDOW_PLACEMENT_CHANGED"BOTTOM_RIGHT"Issued when the user changed the position of a fixed-position widget. Availability: Since 1.18.0
Copy

currentMember

Retrieves the current Site Member, if one exists.

SDK Version: SDK 1.6.0+
Display: Live Site
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
callback (required)FunctionCallback function to receive member details

Value passed to callback:

An object containing the user’s details:

NameTypeDescription
nameStringMember's name
emailStringMember's email
idStringMember's ID
ownerBooleanTrue if the member is either the site owner or one of the site's contributors

getSiteInfo

Retrieves information about the host site.

SDK Version: SDK 1.3.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
callback (required)FunctionCallback function to receive the site info 

Value passed to callback:

An object containing the site info:

NameTypeDescription
baseUrl String Base url of the current site, for example: http://user.wix.com/site-name, http://www.domain.com
pageTitle String The page title that is used for SEO. This title includes both the site and page title (e.g., “My Store - Animal Shirt”).
pageTitleOnlyStringThe name of the page - without the site title (e.g., “Animal Shirt”).
referrer String The referrer header of the HTTP request 
siteDescriptionString The description of the site that is used for SEO 
siteKeywordsString The keywords which are related to the site and are used for SEO 
siteTitle String The title of the site that is used for SEO 
url String The URL (taken from the location.href property). The URL includes the internal site state, for example: http://user.wixsite.com/site-name/pageTitle http://www.domain.com/pageTitle. Returns the site URL only when using getSiteInfo in the live site and preview mode. When using it in Editor mode, returns the Editor URL.

getSiteMap

Retrieves all items in the site structure, including:

  • Items in the site’s menu – pages (including subpages), links, and menu headers.
  • Hidden pages – pages that are in the site, but not in the site menu. For example, a “Thank You” page that’s shown only after a site visitor makes a purchase.

SDK Version: SDK 1.81.0+
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Note:
Use this method instead of getSitePages, which is now deprecated.

Parameters:

NameTypeDescription
callback (required)FunctionCallback function to receive the site structure

Value passed to callback:

An array of objects, where each object represents an item in the site structure.

Warning:
To use this object later (for example, if you want to navigate to a link on the user’s site), save this object in your database as is – don’t change it in any way.

Each object contains data about the item. The data sent depends on the item – check out our examples below.

Parameters:

NameTypeDescription
typeStringType of link the item represents - for example ‘PageLink’ or ‘AnchorLink’. The data returned depends on the item - for example, an ‘AnchorLink’ object will include the anchorName and anchorDataId properties. Check out our examples below.
pageIdStringThe page ID. Note: If the user added a page anchor to the site’s menu, then this method returns an object for the anchor - so there might be multiple objects with the same page ID.
titleStringThe item title
hiddenBooleanReturns true if this page is hidden
isHomePageBooleanReturns true if this page is the site's home page
urlStringURL of this item
subPagesArray [objects](Page objects only) If the page has subpages, returns an ordered set of subpages. Each subpage object contains more information about the subpage (id, title, hide, isHomePage, url).

Here’s an example of an array passed to the callback:

Copy

Example:

Copy

isApplicationInstalled

Allows you to check if another one of your apps is installed.

SDK Version: SDK 1.87.0+
Editor Version: New Editor
Display: Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
appDefinitionId (required)StringApp ID, as specified in the Developers Center
callback (required)FunctionCallback function that receives a boolean indicating if the app is installed in the site: function(isInstalled) {}

Example:

Copy

isAppSectionInstalled

Allows you to check if the user added one of your app’s hidden or custom pages (like a thank you or checkout page).

SDK Version: SDK 1.89.0+
Editor Version: New Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
sectionId (required)StringID of the Page component, as specified in the Developers Center
optionsObjectOptions for this method
options.appDefinitionIdStringIf the Page component is in a different one of your apps, enter that app’s ID (specified in the Developers Center)
callback (required)FunctionCallback function that receives a boolean indicating if the Page component is installed in the site: function(isInstalled) {}

Example:

Copy

removeEventListener

Allows to remove previously assigned event listeners that were specified using Wix.addEventListener.

SDK Version: SDK 1.25.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)Wix.EventsUnique event identifier
CallBackOrId (required)FunctionA callback function that was used with addEventListener, or an id returned by addEventListener

Utils.getCurrentConsentPolicy

Returns an object containing the user's current policy.

SDK Version: SDK 1.537.0
Display: Live Site
Components: Worker

Important:
Use this method in the live site only. Although it works in the Editor/Preview, it will not return the real policy of the user.

Syntax:

Copy

Object Data:

Copy

Example:

Copy

Utils.getDeviceType

Returns a String which represents the current device type: Desktop or Mobile.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Utils.getInstanceId

Returns a String which represents the app instance ID.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Utils.getIpAndPort

Returns a String which represents the app IP and port.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Utils.getViewMode

Returns a String which represents the current view mode.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Utils.navigateToSection

Navigates to your page component – either to the page component itself or to one of your app’s internal pages.

SDK Version: SDK 1.95.0+
Editor Version: New Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
options (required)ObjectID of the page component to navigate to, as well as optional parameters for this method
options.sectionId (required)StringID of the page component, as specified in the Developers Center
options.appDefinitionIdStringIf navigating to a page component in a different app, enter that app’s ID (specified in the Developers Center)
options.queryParamsObjectQuery parameters to add to the page URL when navigating to it, in key value pairs. For example: {param1:value1, param2:value2,...}. These query params are included in the iframe URL (e.g., ?param1=value1&param2=value2).
options.stateStringThe new app's state to push into the editor history stack
options.shouldRefreshIframeBooleanIndicates if the app iframe should be refreshed when navigating to the page. Default value is true. When queryParams are defined, shouldRefreshIframealways defaults to true.
options.noTransitionBooleanIndicates if there should be a transition when navigating to the page. Default value is false.
onFailure (required)Function This will be called if the hosting site does not include the section app, or if the caller's application does not include a section

Utils.onConsentPolicyChanged

Retrieves the user's new policy.

SDK Version: SDK 1.537.0
Display: Live Site
Components: Worker

Important:
Use this method in the live site only. Although it may work in the Editor/Preview, it will not give you real data.

Syntax:

Copy

Parameters:

NameTypeDescription
callbackfunctionCallback function to receive the new policy

Example:

Copy

PubSub.publish

Broadcasts an event to other Site components of a multicomponent app. If the components span multiple pages, they will be notified when they are rendered.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)StringThe name of the event to publish
data (required)ObjectThe object to send to subscribers for this event type
isPersistent (required)Boolean Indicates whether this event is persisted for event subscribers who have not yet subscribed

PubSub.subscribe

Subscribes to events from other components of a multicomponent app. If the components span multiple pages, they will be notified once they are rendered. It is also possible to receive all notifications prior to rendering by specifying a flag when subscribing to events. If the flag is set, the component will be notified immediately of any prior events of the type it is registered to receive.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required)String The name of the event to subscribe to
callBack (required)FunctionFunction that will respond to events sent from other components of the broadcasting app. it will be given the event object itself and the source of the event
receivePastEventsBooleanA flag to indicate that all past instances of the registered event should be sent to registered listener. This will happen immediately upon registration

PubSub.unsubscribe

Unsubscribes from receiving further events. The id from the initial subscribe call is used to unsubscribe from further notifications.

SDK Version: SDK 1.30.0+
Editor Version: New Editor, Old Editor
Display: Live Site, Preview
Components: Worker

Syntax:

Copy

Parameters:

NameTypeDescription
eventName (required) String The name of the event to unsubscribe from
function (required) Function The function that will respond to events sent from other extensions of the broadcasting app. it will be given the event object itself and the source of the event

Deprecated

getSitePages

SDK Version: Deprecated

Note:
Now that this method is deprecated, use the getSiteMap method instead.

Retrieves all pages in this site. A page can be:

  • An item in the site’s menu – a page, subpage, external link, link to a page anchor, or menu header.
  • A hidden page/subpage – these pages are part of the site, but they’re not part of the site menu. For example, a “Thank You” page that’s shown only after a site visitor makes a purchase.

Parameters:

NameTypeDescription
optionsObjectOptions for this method
callback (required)FunctionA callback function to receive the site structure

Value passed to callback:

An array of objects, where each object represents a page in the site.

The objects are ordered according to the site’s structure shown in the Pages menu of the Wix Editor. If a page has subpages, they are passed as an array of objects nested inside the page object.

Each page/subpage object contains the following properties:

NameTypeDescription
idStringThe page/subpage ID. If the user added a page anchor to the site’s menu, then this method returns an object for the anchor - so there might be multiple objects with the same page ID
titleStringThe title of the page/subpage
hideBooleanReturns true if this page/subpage is hidden
isHomePageBooleanReturns true if this page/subpage is the site's home page
subPagesArray [objects](Page objects only) If the page has subPages, returns an ordered set of subpages. Each subpage object contains more information about the subpage (id, title, hide, isHomePage, url).
Did this help?