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
1
addEventListener(eventName, handler)

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
1
$(document).ready(function() {
2
Wix.Worker.addEventListener(Wix.Events.PAGE_NAVIGATION, function(page) {
3
console.log("Visitor navigated to page" + page.toPage);
4
});
5
});

currentMember

Retrieves the current Site Member, if one exists.

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

Syntax:

Copy
1
currentMember(callback)

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
1
getSiteInfo(callback)

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
1
getSiteMap(callback)

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
1
[
2
{
3
"type": "PageLink",
4
"pageId": "#c1dmp",
5
"title": "HOME",
6
"hidden": false,
7
"isHomePage": true,
8
"url": "http://my.wixsite.com/1-dp"
9
},
10
{
11
"type": "PageLink",
12
"pageId": "#kyck4",
13
"title": "Page",
14
"hidden": false,
15
"isHomePage": false,
16
"url": "http://my.wixsite.com/1-dp/page"
17
},
18
{
19
"type": "AnchorLink",
20
"anchorName": "Anchor",
21
"anchorDataId": "#dataItem-iyk5xcst",
22
"pageId": "#c1dmp",
23
"title": "anchor link",
24
"hidden": false,
25
"isHomePage": true,
26
"url": "http://my.wixsite.com/1-dp"
27
},
28
{
29
"type": "ExternalLink",
30
"target": "_blank",
31
"url": "http://google.com",
32
"title": "external",
33
"hidden": false
34
},
35
{
36
"type": "EmailLink",
37
"recipient": "site@a.com",
38
"subject": "dffg",
39
"title": "email",
40
"hidden": false
41
},
42
{
43
"type": "PhoneLink",
44
"phoneNumber": "123544216142",
45
"title": "phone",
46
"hidden": false
47
},
48
{
49
"type": "DocumentLink",
50
"docId": "7a9325_da6cc4b5cb65468bafbd937a9133aed0.pdf",
51
"name": "file1.pdf",
52
"title": "document",
53
"hidden": false,
54
"url": "http://media.wix.com/ugd/7a9325_da6cc4b5cb65468bafbd937a9133aed0.pdf"
55
},
56
{
57
"type": "DynamicPageLink",
58
"routerId": "routers-iympnnog",
59
"innerRoute": "fgfg",
60
"title": "dynamic page",
61
"hidden": false
62
},
63
{
64
"type": "MenuHeader",
65
"title": "Menu Header",
66
"hidden": false,
67
"subPages": [
68
{
69
"type": "PageLink",
70
"pageId": "#rsdvc",
71
"title": "New Page",
72
"hidden": false,
73
"isHomePage": false,
74
"url": "http://my.wixsite.com/1-dp/new-page"
75
}
76
]
77
}
78
]

Example:

Copy
1
Wix.Worker.getSiteMap(function(siteMap) {
2
// do something with the site pages
3
});

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
1
isApplicationInstalled(appDefinitionId, callback)

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
1
Wix.Worker.isApplicationInstalled(
2
'1380b703-ce81-ff05-f115-39571d94dfcd',
3
function(isInstalled){console.log(isInstalled)}
4
);

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
1
isAppSectionInstalled(sectionId,\[options\],callback)

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
1
Wix.Worker.isAppSectionInstalled('page_component_id', function(isInstalled) {
2
console.log (isInstalled)
3
};);

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
1
removeEventListener (eventName, callBackOrId)

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
1
Wix.Worker.Utils.getCurrentConsentPolicy() → Object

Object Data:

Copy
1
{
2
"defaultPolicy": false, // True = this policy is the default policy for the site as defined by the site owner. False = the user actively accepted/set this policy.
3
"policy": {
4
"functional": false,
5
"analytics": false,
6
"advertising": false,
7
"dataToThirdParty": false,
8
"essential": true
9
},
10
"createdDate": "2020-04-03T21:00:00.000Z" //optional
11
}

Example:

Copy
1
var policyDetails = Wix.Worker.Utils.getCurrentConsentPolicy();
2
if (defaultPolicy.policy.dataToThirdParty) {
3
// For example, if true you may be allowed to share data with Facebook. (You must check with your legal team first.)
4
}

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
1
Utils.getDeviceType( ) → String

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
1
Utils.getInstanceId( ) → String

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
1
Utils.getIpAndPort( ) → String

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
1
Utils.getViewMode( ) → String

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
1
Utils.navigateToSection(options, onFailure)

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
1
Wix.Worker.Utils.onConsentPolicyChanged(callback)

Parameters:

NameTypeDescription
callbackfunctionCallback function to receive the new policy

Example:

Copy
1
Wix.Worker.Utils.onConsentPolicyChanged((data)=> {
2
console.log(data);
3
});
4
// will log something with the following structure:
5
{
6
"defaultPolicy": false,
7
"policy": {
8
"functional": false,
9
"analytics": false,
10
"advertising": false,
11
"dataToThirdParty": false,
12
"essential": true
13
},
14
"createdDate": "2020-04-03T21:00:00.000Z"
15
}

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
1
PubSub.publish(eventName, data, isPersistent)

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
1
PubSub.unbscribe(eventName, callBack, receivePastEvents)

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
1
PubSub.unsubscribe(eventName, function)

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).
Was this helpful?
Yes
No