Analyze User Behavior with Embedded Scripts

Use an embedded script extension to track analytics events on a site and send them to external analytics platforms such as Google Analytics or Facebook Pixel. Call trackEvent() to report standard events or custom events to connected platforms.

Notes:

Listen to standard Wix events

Wix business solutions, such as Wix Stores or Wix Events, trigger standard analytics events when the corresponding visitor actions occur, but these events aren't automatically forwarded to external analytics platforms. To report them, you need to call trackEvent() in your embedded script code.

For example, to report an AddToCart event when a visitor adds a product to their cart:

  1. In the embedded script extension's .html file, reference a local JavaScript module:

    Copy
  2. In the module code, import the analytics module and call trackEvent() with the standard event name and relevant data. For example, to report an AddToCart event:

    Copy

The event is reported to all analytics platforms connected to the site.

Track custom events

You can define and track custom events for visitor behaviors not covered by standard events, and report them to connected external analytics platforms:

  1. In the embedded script extension's .html file, reference a local JavaScript module:

    Copy
  2. In the module code, import the analytics module and call trackEvent() with the event name and any relevant event data:

    Copy

The event is reported to all analytics platforms connected to the site.

Note: Some external analytics platforms require that the custom event contains certain properties, such as eventCategory and eventAction.

Register event handlers

You can call registerEventListener() to register an event handler that runs whenever any analytics event occurs, either standard or custom.

Use this for debugging, logging, or forwarding events to a custom destination. To run handlers for only specific event types, use conditional logic in your code:

Copy

See also

Did this help?