# Custom Events

### **What Are Custom Events?**

Custom events allow you to track specific actions or interactions users perform on your website that are important to your business goals. These actions could be anything from adding an item to the cart, clicking on a specific button, or completing a form. By sending custom events, you can gain more detailed insights into user behaviour and fine-tune your marketing strategies accordingly.

### **How to Send Custom Events to SiteBehaviour**

You can easily send custom events from your website to the SiteBehaviour portal using a simple JavaScript snippet. Follow the instructions below to implement it:

#### <mark style="color:green;">Step-by-Step Guide to Sending Custom Events:</mark>

1. **Choose an Event Name**:
   * You can name your custom event anything that reflects the action you want to track. For example, if you want to track when a user adds an item to their cart, you might call the event **"Add To Cart"**.
2. **Use the JavaScript Snippet**:

   * To send a custom event, use the following JavaScript function:

   ```javascript
   window.sbVisitorCustomEvent("Event Name");
   ```

   Replace **"Event Name"** with the name of the custom event you'd like to track.
3. **Example: Add to Cart Event**:

   * If you want to track when users add items to their cart, the code would look like this:

   ```javascript
   window.sbVisitorCustomEvent("Add To Cart");
   ```
4. **Where to Place the Code**:
   * This JavaScript snippet should be placed in the section of your website where the event occurs. For example, if you want to track clicks on an "Add to Cart" button, place this snippet within the function that handles the button click event.

#### Example of Button Click Implementation:

```javascript
document.getElementById("addToCartButton").addEventListener("click", function() {
   window.sbVisitorCustomEvent("Add To Cart");
});
```

### Why Use Custom Events?

* **Track Specific User Actions**: Custom events let you track granular actions that are relevant to your business.
* **Improve Marketing Insights**: Understanding exactly what users are doing on your website can help optimize your strategies and better serve your audience.
* **Enhance Reporting**: With custom events, you can create more detailed reports in your SiteBehaviour portal, giving you deeper insights into user interactions.

If you have any questions or need assistance, feel free to reach out—we're here to help!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sitebehaviour.com/get-started/custom-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
