Wix Blocks: Widget API Events

Wix Blocks is open to all Wix Studio users. To get access to Blocks, join Wix Studio.

Add an event when you want to provide information about actions that happen in the widget to the site owner. For example, when a customer adds a product to the cart. 

To add a new event:

  1. Click the Widget API  icon.
  2. Click Add New Public Event or hover over Events and click the  icon. 

3.  Name your event and provide a description. 

4. Fire the event from your widget code.

Use this syntax:

$widget.fireEvent('eventName', {eventObject}).

Define the condition for firing the evnet and, optionally, send event data. For example:

Copy
1
$w(`#button1`).onClick(() => {
2
$widget.fireEvent('addedToCart', {productId: product.id, customerId: customer.id})
3
});

5. You can [catch your event](https://github.com/wix-private/developer-docs/blob/80e70d37c8c493f1ce78a82a00db6453daccf95d/velo-articles/Code in Blocks/(Using%20Your%20Widget%20API%20When%20Editing%20a%20Site.md#access-widget-api-events)) from two places

  • From any site where your widget is installed.
  • From any widget of your app to which you added this widget as an inner widget.

Note: Don't Forget to Document

Make sure to document your widget API by describing any property, event or function you add to it. These descriptions are available to site creators who install your widget.

Was this helpful?
Yes
No