wix-window

wix-window

The wix-window module contains functionality that pertains to the current browser window.

To use the window module, import wixWindow from the wix-window module:

ICAgaW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93Jzs=
   import wixWindow from 'wix-window';

The APIs in wix-window can only be used in front-end code.

Contents

lightbox A lightbox pops up on your site to grab your visitor's attention.
rendering The Rendering API is used to control when code is run as a page is being loaded.
trackingParameters Objects used when calling the trackEvent() function.
formFactor Gets what kind of device is being used to view the page.
locale Gets the locale of the current environment.
referrer Gets the HTTP referrer header field.
viewMode Gets which mode the site is currently being viewed in.
getBoundingRect( ) Returns information about the window.
getCurrentGeolocation( ) Returns the current geolocation of the user.
getRouterData( ) Returns the data that a router passed to the page in its response.
openLightbox( ) Opens a lightbox and optionally passes it the given data.
openModal( ) Opens a modal window that displays the specified web page.
postMessage( ) Sends a message to the page's parent.
scrollBy( ) Scrolls the page by a given number of pixels.
scrollTo( ) Scrolls the page to a specific location.
trackEvent( ) Sends a tracking event to external analytics tools.
OpenModalOptions An object used when opening a modal window.
WindowSizeInfo An object returned by the getBoundingRect() function that contains information about the window's size, the document's size, and the current scroll position.
formFactor

formFactor

Gets what kind of device is being used to view the page.

Syntax

get formFactor(): "Desktop" | "Mobile"

Description

The formFactor property gets either:

  • "Desktop" - When viewed in a desktop browser.
  • "Mobile" - When viewed in a mobile browser.

Type

String

Examples

Get a device's form factor

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKbGV0IGZvcm1GYWN0b3IgPSB3aXhXaW5kb3cuZm9ybUZhY3RvcjsgIC8vICJNb2JpbGUiCg==
import wixWindow from 'wix-window';

// ...

let formFactor = wixWindow.formFactor;  // "Mobile"
locale

locale

Gets the locale of the current environment.

Syntax

get locale(): String

Description

A locale, also known as an IETF language tag, is an abbreviated code that defines the user's language, country, and other aspects of the user interface such as number format and date format.

Some common locales include:

  • "en" - English
  • "es" - Spanish
  • "de" - German
  • "ja" - Japanese
  • "fr" - French
  • "it" - Italian

Type

String

Examples

Get an environment's locale

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKbGV0IGxvY2FsZSA9IHdpeFdpbmRvdy5sb2NhbGU7ICAvLyAiZW4iCg==
import wixWindow from 'wix-window';

// ...

let locale = wixWindow.locale;  // "en"
referrer

referrer

Gets the HTTP referrer header field.

Syntax

get referrer(): String

Description

The referrer is the address of the previous web page that the user was on before arriving at the current page, typically by clicking a link.

Type

String

Examples

Get the referrer information

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKbGV0IHJlZmVycmVyID0gd2l4V2luZG93LnJlZmVycmVyOyAgLy8gImh0dHA6Ly9zb21lc2l0ZS5jb20iCg==
import wixWindow from 'wix-window';

// ...

let referrer = wixWindow.referrer;  // "http://somesite.com"
viewMode

viewMode

Gets which mode the site is currently being viewed in.

Syntax

get viewMode(): "Preview" | "Site"

Description

The viewMode property gets either:

  • "Preview" - When previewing the site using the Preview button in the Editor.
  • "Site" - When viewing the published site.

Type

String

Examples

Get a window's view mode

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKbGV0IHZpZXdNb2RlID0gd2l4V2luZG93LnZpZXdNb2RlOyAgLy8gIlNpdGUiCg==
import wixWindow from 'wix-window';

// ...

let viewMode = wixWindow.viewMode;  // "Site"
getBoundingRect( )

getBoundingRect( )

Returns information about the window.

function getBoundingRect(): Promise<WindowSizeInfo>

Description

The getBoundingRect() function returns a Promise that resolves to an object containing information about the current window's size, the document's size, and the current scroll position.

Return Value

Returns a Promise

On fulfillment WindowSizeInfo An object containing information about the window's size, the document's size, and the current scroll position.

Examples

Get information about the window

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LmdldEJvdW5kaW5nUmVjdCgpCiAgLnRoZW4oICh3aW5kb3dTaXplSW5mbykgPT4gewogICAgbGV0IHdpbmRvd0hlaWdodCA9IHdpbmRvd1NpemVJbmZvLndpbmRvdy5oZWlnaHQ7ICAgICAgLy8gNTY1CiAgICBsZXQgd2luZG93V2lkdGggPSB3aW5kb3dTaXplSW5mby53aW5kb3cud2lkdGg7ICAgICAgICAvLyAxMjY5CiAgICBsZXQgZG9jdW1lbnRIZWlnaHQgPSB3aW5kb3dTaXplSW5mby5kb2N1bWVudC5oZWlnaHQ7ICAvLyA3ODAKICAgIGxldCBkb2N1bWVudFdpZHRoID0gd2luZG93U2l6ZUluZm8uZG9jdW1lbnQud2lkdGg7ICAgIC8vIDEyNjkKICAgIGxldCBzY3JvbGxYID0gd2luZG93U2l6ZUluZm8uc2Nyb2xsLng7ICAgICAgICAgICAgICAgIC8vIDAKICAgIGxldCBzY3JvbGxZID0gd2luZG93U2l6ZUluZm8uc2Nyb2xsLnk7ICAgICAgICAgICAgICAgIC8vIDEyMAogIH0gKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.getBoundingRect()
  .then( (windowSizeInfo) => {
    let windowHeight = windowSizeInfo.window.height;      // 565
    let windowWidth = windowSizeInfo.window.width;        // 1269
    let documentHeight = windowSizeInfo.document.height;  // 780
    let documentWidth = windowSizeInfo.document.width;    // 1269
    let scrollX = windowSizeInfo.scroll.x;                // 0
    let scrollY = windowSizeInfo.scroll.y;                // 120
  } );
getCurrentGeolocation( )

getCurrentGeolocation( )

Returns the current geolocation of the user.

function getCurrentGeolocation(): Promise<Object>

Description

The getCurrentGeolocation() function returns a Promise that resolves to an object containing the current geolocation of the user.

The object contains the following key:value pairs:

  • "timestamp" - The geolocation timestamp representing the date and time at which the location was retrieved.
  • "coords" - An object that defines the location.
    • "latitude" - The position's latitude in decimal degrees.
    • "longitude" - The position's longitude in decimal degrees.
    • "altitude" - The position's altitude in metres, relative to sea level. This value may be null if the browser cannot provide the data.
    • "accuracy" - The accuracy in meters of the latitude and longitude properties.
    • "altitudeAccuracy" - The accuracy in meters of the altitude property. This value may be null.
    • "heading" - The direction in degrees in which the device is traveling. It indicates how far off from heading true north the device is. If speed is 0, the heading is NaN. This value may be null if the browser cannot provide the data.
    • "speed" - The velocity in meters per second of the device. This value may be null if the browser cannot provide the data.

Return Value

Returns a Promise

On fulfillment Object The coordinates and timestamp of the current location.
On rejection String The user blocked the geolocation popup.

Examples

Get the geolocation data

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LmdldEN1cnJlbnRHZW9sb2NhdGlvbigpCiAgLnRoZW4oIChvYmopID0+IHsKICAgIGxldCB0aW1lc3RhbXAgPSBvYmoudGltZXN0YW1wOyAgICAgICAgICAgICAgICAgIC8vIDE0OTUwMjcxODY5ODQKICAgIGxldCBsYXRpdHVkZSA9IG9iai5jb29yZHMubGF0aXR1ZGU7ICAgICAgICAgICAgIC8vIDMyLjA5NzEwMzYKICAgIGxldCBsb25naXR1ZGUgPSBvYmouY29vcmRzLmxvbmdpdHVkZTsgICAgICAgICAgIC8vIDM0Ljc3NDM5MTA5OTk5OTk5NQogICAgbGV0IGFsdGl0dWRlID0gb2JqLmNvb3Jkcy5hbHRpdHVkZTsgICAgICAgICAgICAgLy8gbnVsbAogICAgbGV0IGFjY3VyYWN5ID0gb2JqLmNvb3Jkcy5hY2N1cmFjeTsgICAgICAgICAgICAgLy8gMjkKICAgIGxldCBhbHRBY2N1cmFjeSA9IG9iai5jb29yZHMuYWx0aXR1ZGVBY2N1cmFjeTsgIC8vIG51bGwKICAgIGxldCBoZWFkaW5nID0gb2JqLmNvb3Jkcy5oZWFkaW5nOyAgICAgICAgICAgICAgIC8vIG51bGwKICAgIGxldCBzcGVlZCA9IG9iai5jb29yZHMuc3BlZWQ7ICAgICAgICAgICAgICAgICAgIC8vIG51bGwKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3I7CiAgfSk7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.getCurrentGeolocation()
  .then( (obj) => {
    let timestamp = obj.timestamp;                  // 1495027186984
    let latitude = obj.coords.latitude;             // 32.0971036
    let longitude = obj.coords.longitude;           // 34.774391099999995
    let altitude = obj.coords.altitude;             // null
    let accuracy = obj.coords.accuracy;             // 29
    let altAccuracy = obj.coords.altitudeAccuracy;  // null
    let heading = obj.coords.heading;               // null
    let speed = obj.coords.speed;                   // null
  } )
  .catch( (error) => {
    let errorMsg = error;
  });
getRouterData( )

getRouterData( )

Returns the data that a router passed to the page in its response.

function getRouterData(): Object

Description

When you create a router and define its functionality in its router() function, you can choose to send data along with the router's response. That data is retrieved in the code of the page that was routed to using the getRouterData() function.

If you call the getRouterData() function from a non-router page or a router page that wasn't sent any data, the function returns null.

Return Value

Object The data returned by the router.

Examples

Get the data passed by a router

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKbGV0IHJvdXRlckRhdGEgPSB3aXhXaW5kb3cuZ2V0Um91dGVyRGF0YSgpOwo=
import wixWindow from 'wix-window';

// ...

let routerData = wixWindow.getRouterData();

See Also

router( ), WixRouterResponse

openLightbox( )

openLightbox( )

Opens a lightbox and optionally passes it the given data.

function openLightbox(name: String[, data: Object]): Promise<Object>

Description

The openLightbox() function returns a Promise which is resolved when the lightbox closes. If the lightbox is closed programmatically using its close() function, and the close() function was invoked with a data parameter, then the Promise resolves to that data object.

If you send a data object to the lightbox, use the getContext() function in the lightbox's code to access the received data.

Parameters

name String The name of the lightbox to open.
data (optional) Object The data to pass to the lightbox.

Return Value

Returns a Promise

On fulfillment Object The returned data from the lightbox.
On rejection Error The error that caused the rejection.

Examples

Open a lightbox

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5MaWdodGJveCgiTGlnaHRib3hOYW1lIik7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.openLightbox("LightboxName");

Open a lightbox and send it data

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5MaWdodGJveCgiTGlnaHRib3hOYW1lIiwgZGF0YU9iaik7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.openLightbox("LightboxName", dataObj);

Open a lightbox and receive data when it is closed

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5MaWdodGJveCgiTGlnaHRib3hOYW1lIikKICAudGhlbiggKGRhdGEpID0+IHsKICAgIGxldCByZWNlaXZlZERhdGEgPSBkYXRhOwogIH0gKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.openLightbox("LightboxName")
  .then( (data) => {
    let receivedData = data;
  } );

Open a lightbox, send it data, and receive data back when it is closed

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5MaWdodGJveCgiTGlnaHRib3hOYW1lIiwgZGF0YU9iaikKICAudGhlbiggKGRhdGEpID0+IHsKICAgIGxldCByZWNlaXZlZERhdGEgPSBkYXRhOwogIH0gKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.openLightbox("LightboxName", dataObj)
  .then( (data) => {
    let receivedData = data;
  } );

See Also

openModal( )

openModal( )

openModal( )

Opens a modal window that displays the specified web page.

function openModal(url: String, options: OpenModalOptions): Promise<void>

Description

A modal window displays the page specified by the url property over your current page. Unlike a lightbox, which is open using the openLightbox() function, the window opened by openModal() is not part of your site structure.

Only one modal window can be open at any given time. Therefore, opening a modal window closes an already open modal window if there is one.

Parameters

url String The URL of the page to show in the modal window.
options OpenModalOptions The options used for the modal window.

Return Value

Returns a Promise

On fulfillment void When the modal window is closed.
On rejection Error The error that caused the rejection.

Examples

Open a modal window

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5Nb2RhbCgiaHR0cHM6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvV2l4LmNvbSIsIHsKICAid2lkdGgiOiA3NTAsCiAgImhlaWdodCI6IDUwMAp9ICk7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.openModal("https://en.wikipedia.org/wiki/Wix.com", {
  "width": 750,
  "height": 500
} );

Open a modal window and log a message when it is closed

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5Nb2RhbCgiaHR0cHM6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvV2l4LmNvbSIsIHsKICAgICJ3aWR0aCI6IDc1MCwKICAgICJoZWlnaHQiOiA1MDAKICB9ICkKICAudGhlbiggKCkgPT4gewogICAgY29uc29sZS5sb2coIk1vZGFsIGNsb3NlZC4iKTsKICB9ICk7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.openModal("https://en.wikipedia.org/wiki/Wix.com", {
    "width": 750,
    "height": 500
  } )
  .then( () => {
    console.log("Modal closed.");
  } );

See Also

openLightbox( )

postMessage( )

postMessage( )

Sends a message to the page's parent.

function postMessage(message: Object[, target: String]): void

Description

If a page is embedded within another site, using an HtmlComponent on a Wix site or an iframe on a non-Wix site, you can use the postMessage() function to send a message from the inner site to the outer site.

When the parent site is a Wix site, use the onMessage() function to receive the message on the parent page.

When the parent site is a non-Wix site, use the page's window.onmessage event handler to read the data property of the received MessageEvent to receive the message on the parent page.

Parameters

message Object The message to send.
target (optional) String The target to send the message to. Must be "parent" or omitted. Defaults to "parent".

Return Value

Returns a Promise

On fulfillment Object The data returned from the modal window.
On rejection Error The error that caused the rejection.

Examples

Send a message to a Wix parent site

LyogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKgogKiBDb2RlIGZvciB0aGUgaW5uZXIgc2l0ZSB0byBwb3N0IGEgbWVzc2FnZSAqCiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICovCmltcG9ydCB3aXhXaW5kb3cgZnJvbSAnd2l4LXdpbmRvdyc7CgovLyAuLi4KCndpeFdpbmRvdy5wb3N0TWVzc2FnZShkYXRhT2JqKTsKCi8qICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqCiAqIENvZGUgZm9yIHRoZSBvdXRlciBzaXRlIHRvIHJlY2VpdmUgYSBtZXNzYWdlICAqCiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqCiAqCiAqICR3KCIjbXlIdG1sQ29tcG9uZW50Iikub25NZXNzYWdlKCAoZXZlbnQsICR4KSA9PiB7CiAqICAgbGV0IG1lc3NhZ2UgPSBldmVudC5kYXRhOwogKiB9ICk7CiAqLwo=
/* * * * * * * * * * * * * * * * * * * * * * *
 * Code for the inner site to post a message *
 * * * * * * * * * * * * * * * * * * * * * * */
import wixWindow from 'wix-window';

// ...

wixWindow.postMessage(dataObj);

/* * * * * * * * * * * * * * * * * * * * * * * * *
 * Code for the outer site to receive a message  *
 * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * $w("#myHtmlComponent").onMessage( (event, $x) => {
 *   let message = event.data;
 * } );
 */

Send a message to a non-Wix parent site

LyogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKgogKiBDb2RlIGZvciB0aGUgaW5uZXIgc2l0ZSB0byBwb3N0IGEgbWVzc2FnZSAqCiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICovCmltcG9ydCB3aXhXaW5kb3cgZnJvbSAnd2l4LXdpbmRvdyc7CgovLyAuLi4KCndpeFdpbmRvdy5wb3N0TWVzc2FnZShkYXRhT2JqKTsKCi8qICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqCiAqIENvZGUgZm9yIHRoZSBvdXRlciBzaXRlIHRvIHJlY2VpdmUgYSBtZXNzYWdlICAqCiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqICogKiAqCiAqCiAqIDxzY3JpcHQ+CiAqICAgd2luZG93LmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCBldmVudCA9PiB7CiAqICAgIGxldCBtZXNzYWdlID0gZXZlbnQuZGF0YTsKICogICB9ICk7CiAqIDwvc2NyaXB0PgogKi8K
/* * * * * * * * * * * * * * * * * * * * * * *
 * Code for the inner site to post a message *
 * * * * * * * * * * * * * * * * * * * * * * */
import wixWindow from 'wix-window';

// ...

wixWindow.postMessage(dataObj);

/* * * * * * * * * * * * * * * * * * * * * * * * *
 * Code for the outer site to receive a message  *
 * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * 
 */
scrollBy( )

scrollBy( )

Scrolls the page by a given number of pixels.

function scrollBy(x: Number, y: Number): Promise<void>

Description

The scrollBy() function returns a Promise that resolves when the current page has been scrolled by the given number of pixels,

The x and y parameters determine the number of horizontal and vertical pixels to scroll the current page. Negative numbers scroll up or to the left and positive numbers scroll down or to the right.

Parameters

x Number The horizontal offset, in pixels, to scroll by.
y Number The vertical offset, in pixels, to scroll by.

Return Value

Returns a Promise

On fulfillment void When the scroll is complete.

Examples

Scroll the page by a given number of pixels

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LnNjcm9sbEJ5KDEwMCwgNTAwKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.scrollBy(100, 500);

Scroll the page by a given number of pixels and log message when done

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LnNjcm9sbEJ5KDEwMCwgNTAwKQogIC50aGVuKCAoICkgPT4gewogICAgY29uc29sZS5sb2coIkRvbmUgd2l0aCBzY3JvbGwiKTsKfSApOwo=
import wixWindow from 'wix-window';

// ...

wixWindow.scrollBy(100, 500)
  .then( ( ) => {
    console.log("Done with scroll");
} );
scrollTo( )

scrollTo( )

Scrolls the page to a specific location.

function scrollTo(x: Number, y: Number): Promise<void>

Description

The scrollTo() function returns a Promise that resolves when the current page has been scrolled to the given location.

The x and y parameters determine the top-left pixel that is displayed on screen after the scroll.

To scroll to a specific element on the page, see the $w.Node scrollTo() function.

Parameters

x Number The horizontal position, in pixels, to scroll to.
y Number The vertical position, in pixels, to scroll to.

Return Value

Returns a Promise

On fulfillment void When the scroll is complete.

Examples

Scroll the page to a location

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LnNjcm9sbFRvKDEwMCwgNTAwKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.scrollTo(100, 500);

Scroll the page to a location and log message when done

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LnNjcm9sbFRvKDEwMCwgNTAwKQogIC50aGVuKCAoICkgPT4gewogICAgY29uc29sZS5sb2coIkRvbmUgd2l0aCBzY3JvbGwiKTsKfSApOwo=
import wixWindow from 'wix-window';

// ...

wixWindow.scrollTo(100, 500)
  .then( ( ) => {
    console.log("Done with scroll");
} );
trackEvent( )

trackEvent( )

Sends a tracking event to external analytics tools.

function trackEvent(eventName: TrackEvent, parameters: trackingParameters): void
type TrackEvent = "AddPaymentInfo" | "AddProductImpression"
| "AddToCart" | "ClickProduct" | "CustomEvent"
| "InitiateCheckout" | "Lead" | "Purchase" | "RemoveFromCart"
| "ViewContent"
type trackingParameters = AddPaymentInfoEvent
| AddProductImpressionEvent | AddToCartEvent | ClickProductEvent
| CustomEvent | InitiateCheckoutEvent | PurchaseEvent
| RemoveFromCartEvent | ViewContentEvent

Description

The trackEvent() function sends an event to analytics tools connected to your site. It can send events to Google Analytics and Facebook Pixel. To learn how to connect analytics tools to your site, see About Tracking Tools & Analytics.

The following events and parameters are available:

  • "AddProductImpression" - parameters - When a user views a product. (Google Analytics only)
  • "ClickProduct" - parameters - When a user clicks on a product. (Google Analytics only)
  • "ViewContent" - parameters - When a key page is viewed.
  • "AddToCart" - parameters - When a user adds a product to the shopping cart.
  • "RemoveFromCart" - parameters - When a user removes a product from the shopping cart. (Google Analytics only)
  • "InitiateCheckout" - parameters - When a user starts the checkout process.
  • "AddPaymentInfo" - parameters - When a user saves payment information.
  • "Purchase" - parameters - When the checkout process is complete.
  • "Lead" - When a user subscribes to a newsletter or submits a contact form.
  • "CustomEvent" - parameters - When a user performs an event not listed above.

Parameters

eventName String The name of the event.
parameters AddPaymentInfoEvent |
AddProductImpressionEvent |
AddToCartEvent |
ClickProductEvent |
CustomEvent |
InitiateCheckoutEvent |
PurchaseEvent |
RemoveFromCartEvent |
ViewContentEvent
The event's parameters.

Examples

Send a trackEvent with parameters

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCndpeFdpbmRvdy50cmFja0V2ZW50KCJWaWV3Q29udGVudCIsIHsKICBpZDogIlAxMjM0NSIsCiAgbmFtZTogIlJlYWxseSBGYXN0IFJ1bm5pbmcgU2hvZXMiLAogIGNhdGVnb3J5OiAiQXBwYXJlbC9TaG9lcyIsCiAgcHJpY2U6IDEyMCwKICBjdXJyZW5jeTogIlVTRCIsCiAgYnJhbmQ6ICJBZGlkYXMiLAogIHZhcmlhbnQ6ICJCbGFjayIsCiAgcG9zaXRpb246IDEKfSApOwo=
import wixWindow from 'wix-window';

wixWindow.trackEvent("ViewContent", {
  id: "P12345",
  name: "Really Fast Running Shoes",
  category: "Apparel/Shoes",
  price: 120,
  currency: "USD",
  brand: "Adidas",
  variant: "Black",
  position: 1
} );

Send a trackEvent that doesn't take any parameters

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCndpeFdpbmRvdy50cmFja0V2ZW50KCJMZWFkIik7Cg==
import wixWindow from 'wix-window';

wixWindow.trackEvent("Lead");

Send a trackEvent from the onReady event handler

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCiR3Lm9uUmVhZHkoZnVuY3Rpb24gKCkgewogIGlmKHdpeFdpbmRvdy5yZW5kZXJpbmcuZW52ID09PSAiYnJvd3NlciIpIHsKICAgIHdpeFdpbmRvdy50cmFja0V2ZW50KCJWaWV3Q29udGVudCIsIHsKICAgICAgaWQ6ICJQMTIzNDUiLAogICAgICBuYW1lOiAiUmVhbGx5IEZhc3QgUnVubmluZyBTaG9lcyIsCiAgICAgIGNhdGVnb3J5OiAiQXBwYXJlbC9TaG9lcyIsCiAgICAgIHByaWNlOiAxMjAsCiAgICAgIGN1cnJlbmN5OiAiVVNEIiwKICAgICAgYnJhbmQ6ICJBZGlkYXMiLAogICAgICB2YXJpYW50OiAiQmxhY2siLAogICAgICBwb3NpdGlvbjogMQogICAgfSApOwogIH0KfSApOwo=
import wixWindow from 'wix-window';

$w.onReady(function () {
  if(wixWindow.rendering.env === "browser") {
    wixWindow.trackEvent("ViewContent", {
      id: "P12345",
      name: "Really Fast Running Shoes",
      category: "Apparel/Shoes",
      price: 120,
      currency: "USD",
      brand: "Adidas",
      variant: "Black",
      position: 1
    } );
  }
} );
OpenModalOptions

OpenModalOptions

An object used when opening a modal window.

Type

Object

Properties

width Number Width of the modal window.
height Number Height of the modal window.

Examples

Open a modal window

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93Lm9wZW5Nb2RhbCgiaHR0cHM6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvV2l4LmNvbSIsIHsKICAid2lkdGgiOiA3NTAsCiAgImhlaWdodCI6IDUwMAp9ICk7Cg==
import wixWindow from 'wix-window';

// ...

wixWindow.openModal("https://en.wikipedia.org/wiki/Wix.com", {
  "width": 750,
  "height": 500
} );

See Also

openModal( )

WindowSizeInfo

WindowSizeInfo

An object returned by the getBoundingRect() function that contains information about the window's size, the document's size, and the current scroll position.

Type

Object

Properties

window Object An object with height and width key:value pairs containing the size of the viewable area of the current browser window.
document Object An object with height and width key:value pairs containing the size of the actual body of the page, which may be larger or smaller than the current window.
scroll Object An object with x and y key:value pairs containing the scroll offset of the page within the window from the top-left corner.

Examples

Get information about the window

aW1wb3J0IHdpeFdpbmRvdyBmcm9tICd3aXgtd2luZG93JzsKCi8vIC4uLgoKd2l4V2luZG93LmdldEJvdW5kaW5nUmVjdCgpCiAgLnRoZW4oICh3aW5kb3dTaXplSW5mbykgPT4gewogICAgbGV0IHdpbmRvd0hlaWdodCA9IHdpbmRvd1NpemVJbmZvLndpbmRvdy5oZWlnaHQ7ICAgICAgLy8gNTY1CiAgICBsZXQgd2luZG93V2lkdGggPSB3aW5kb3dTaXplSW5mby53aW5kb3cud2lkdGg7ICAgICAgICAvLyAxMjY5CiAgICBsZXQgZG9jdW1lbnRIZWlnaHQgPSB3aW5kb3dTaXplSW5mby5kb2N1bWVudC5oZWlnaHQ7ICAvLyA3ODAKICAgIGxldCBkb2N1bWVudFdpZHRoID0gd2luZG93U2l6ZUluZm8uZG9jdW1lbnQud2lkdGg7ICAgIC8vIDEyNjkKICAgIGxldCBzY3JvbGxYID0gd2luZG93U2l6ZUluZm8uc2Nyb2xsLng7ICAgICAgICAgICAgICAgIC8vIDAKICAgIGxldCBzY3JvbGxZID0gd2luZG93U2l6ZUluZm8uc2Nyb2xsLnk7ICAgICAgICAgICAgICAgIC8vIDEyMAogIH0gKTsK
import wixWindow from 'wix-window';

// ...

wixWindow.getBoundingRect()
  .then( (windowSizeInfo) => {
    let windowHeight = windowSizeInfo.window.height;      // 565
    let windowWidth = windowSizeInfo.window.width;        // 1269
    let documentHeight = windowSizeInfo.document.height;  // 780
    let documentWidth = windowSizeInfo.document.width;    // 1269
    let scrollX = windowSizeInfo.scroll.x;                // 0
    let scrollY = windowSizeInfo.scroll.y;                // 120
  } );

See Also

getBoundingRect( )