About Custom Triggers

When you create a new automation on your site, you must select a trigger that causes the automation to run. A trigger is an event that occurs on a site and gets reported to Wix.

An automation only runs when the trigger occurs. For example, if you select the Member logs in trigger, your automation runs when a member logs in. Most triggers are based on similar business logic, like payment information or contact management.

However, you may want to run your automation when an event occurs that isn't defined by existing triggers. Examples include:

  • Creating a new contact when a site visitor clicks a certain button.
  • Send a chat message offering help when a member inputs an invalid value into a text input field.
  • Send a coupon if a visitor is on your site for a certain period of time.

With the Custom Trigger API, you can run an automation for any event that occurs by triggering the automation from your code. This gives you greater control and flexibility over when your automations run.

Supported IDEs

Once you select the code trigger in the automation builder, you can write your code with the following IDEs:

Trigger configuration

There are 2 parts to the trigger configuration:

Trigger ID

When you select the Velo code trigger as your automation trigger, Wix generates a unique trigger ID. When you call runTrigger(), you need to specify the trigger ID. The method then runs the automation associated with the ID. You can run automations from anywhere in your site code, simply by calling runTrigger() with the relevant ID.

Payload schema

In addition to the ID, you can optionally define a payload schema for the trigger to specify when calling runTrigger(). The structure of the payload schema is generated from sample data that you enter when you configure the trigger. For example, if you enter sample data like this:

Copy

Your payload schema will have a structure like this:

Copy

The method's payload field is optional even if you define a payload schema. If you do specify a payload, you can't specify a payload with fields that aren't defined in the schema but you can omit fields. Any fields you include in the payload must match the key and type defined in the schema.

For example, if your payload structure looks like the one above, you can pass the following payloads to runTrigger():

Copy

Some actions may require certain payload fields to be specified. For example, if subsequent actions need to access contact data, be sure to pass the contact ID field.

Contact data in the payload schema

If your payload schema contains 1 or more UUID fields, you can mark one of those fields as a contact ID. When the payload is passed to runTrigger(), Wix looks up the ID in the contact ID field. If the ID corresponds to an existing contact, Wix retrieves the contact’s data and attaches that data to the payload. The data can then be passed to any subsequent actions.

Note: If the ID corresponds to a new contact, you can save the contact data by executing the Create a Contact action after the trigger.

Common errors

Here are some common errors you might encounter and their causes:

Error messageCause
Automation not foundNo automation is found for the trigger ID passed to runTrigger(). This may be because the automation was deleted.
This automation can only be executed within its designated applicationThis only applies to preinstalled automations when an app other than the one that created the automation tries to run it.

See also

Did this help?