> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Add a Backend Events Extension in Studio Two

## Article: Add a Backend Events Extension in Studio Two

## Article Link: https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/add-a-backend-events-extension-in-studio-two.md

## Article Content:

# Add a Backend Events Extension in Studio Two

A [Backend Events](https://dev.wix.com/docs/overview/extensions-framework/backend-extensions/event-extensions.md) extension provides custom server-side logic that runs when a Wix platform event fires. For what it is, see [About Backend Events](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/about-backend-events.md).

Follow the instructions below to:

1. Add a Backend Events extension to your site project.
2. Customize the event handler.
3. Check the event handler.
4. Publish your site with the extension.

> **Note:** You can also ask **Aria**, Wix's AI assistant, to create and customize the extension.

## Step 1 | Add a Backend Events extension

To add a Backend Events extension:

1. In the Studio Two editor, open the **Code** tab.
2. In the VS Code sidebar, open the **Wix Extension Builder**.

   ![the Wix Extension Builder in the VS Code activity bar](https://wixmp-833713b177cebf373f611808.wixmp.com/images/6bff2816a5bfe47ed855a1859cd89d5a.png)

3. Under **Create an Extension**, choose **Backend**, then **Backend Events**.
4. Fill in the form:
   - **Event folder**: Lowercase alphanumeric and hyphens only.
5. Click **Generate**.

You can find the new files under `src/extensions/backend/events/<event-folder>/`. The extension is registered in your project's `extensions.ts` and listed under **My Extensions**. For what each file is for, see [Event Extension Files and Code](https://dev.wix.com/docs/backend-extensions/backend-events/event-extension-files-and-code.md).

## Step 2 | Customize your Backend Events extension

You can edit the generated files to match the event handling you need. Change the code yourself, or ask the AI in the **Code** tab to help. When you're happy with the handler, move on to the next step.

For example, to write a log entry when a contact is created:

The generated handler imports `contacts` from `@wix/crm`. A new Studio Two project doesn't include that package. In the **Code** tab terminal, run `npm install @wix/crm`. For the install steps, see [Work with npm Packages](https://dev.wix.com/docs/studio-two/code-your-site/developer-environment/packages/work-with-npm-packages.md).

The event also needs a permission before Wix calls the handler. The generated file's header links that permission on the [Contact Created](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts/contact-v4/contact-created.md) event. Add the permission before you check the handler.

1. Open `<event-folder>.ts`.
2. At the top of the file, import the monitoring client from `@wix/essentials`:

   ```ts
   import { monitoring } from '@wix/essentials';
   ```

3. Inside the event handler, replace the placeholder comment with your logic:

   ```ts
   monitoring.getMonitoringClient().captureMessage('Contact created');
   ```

4. Save the file.

The finished file looks like this:

```ts
import { contacts } from '@wix/crm';
import { monitoring } from '@wix/essentials';

export default contacts.onContactCreated((event) => {
  monitoring.getMonitoringClient().captureMessage('Contact created');
});
```

For other events, and for the details of the handler, see [Build a Backend Events Extension in Studio Two](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/build-a-backend-events-extension-in-studio-two.md).

## Step 3 | Check the event handler

To check the event handler:

1. Trigger the event your handler listens for. For the Contact Created example, create a contact in the dashboard's **Customers & Leads > Contacts** page, or submit a form on the live site.
2. In the site dashboard, open **Developer Tools > Logs**.

Your handler's log entry appears on the **Logs** page. For other event types, see the [API Reference](https://dev.wix.com/docs/api-reference?apiView=SDK.md) for how to trigger them.

## Step 4 | Publish your site

When you're ready, click **Publish** in the Studio Two editor to ship the extension with your site.

## See also

- [About Backend Events](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/about-backend-events.md)
- [Build a Backend Events Extension in Studio Two](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/build-a-backend-events-extension-in-studio-two.md)
- [About Studio Two Extensions](https://dev.wix.com/docs/studio-two/get-started/about-studio-two-extensions.md)
- [Event Extensions](https://dev.wix.com/docs/overview/extensions-framework/backend-extensions/event-extensions.md)