About Custom Actions

When you create a new automation on your site, you're presented with a variety of actions to execute after your automation is triggered. The actions available to you depend on the apps that are installed on your site.

However, if none of the available actions execute the behavior you want, you also have the option to create your own custom action. This action is independent of any app and applies only to the site it's created on.

You can create custom actions with the Automations Action service plugin. The service plugin lets you code a custom action directly in the automation builder.

Examples of actions you can create with the Action service plugin include:

  • Create custom email notifications for specific events.
  • Trigger third-party APIs when a subscriber signs up on your site.
  • Log specific actions into a custom database for business analysis.

Supported IDEs

You can implement custom actions using:

  • The code editor (Wix Studio and Wix Editor).
  • The Wix IDE (Wix Studio).

Custom action code

To create a custom action, you select the Run Velo code action in the automation builder. Wix creates a Javascript file where you write your action code. You then edit this file in a modal inside the builder.

Wix automatically populates the JS file with the following code:

Copy

You must write all your code inside the invoke() method. Wix calls this method each time the automation is triggered, and runs any code inside. It expects an empty object in return, so make sure to leave the return statement as it appears.

To write your action code, use the Wix APIs just like you would in your site's public or backend files.

When you create a custom action for the first time, Wix adds the Automations Action service plugin to your site's backend code files. Under the Action service plugin, Wix adds a folder for each subsequent custom action you create. This folder contains a copy of the action code you write in the builder. However, any changes you make in the backend file aren't reflected when the automation runs. Write and edit your action code only in the automation builder.

Working directly in the automation builder also allows you to:

  • Easily verify you are working with the correct trigger.
  • View the full trigger payload.
  • Edit sample data provided by Wix and test your code with it.

Payload data

Depending on the trigger you select, your action expects to receive a payload when the automation is triggered. You can view the payload structure under the Payload view tab while writing your code in the builder. The structure is read-only.

You can access payload data in your code with dot notation. For example:

Copy

Editing the automation

To edit your action code, return to the automation in the builder and make your changes directly in the custom action modal.

The code file you create for your custom action is associated with the original trigger you selected. Editing the trigger configuration doesn't affect the custom action. However, if you change the trigger, a new code file will be created and you'll have to write new code. The initial file you create is still saved, and if you restore the trigger it is associated with, you'll be able to access it again in the automation.

See also

Did this help?