# Emitting Events to Beacon

#### Emit custom events to Beacon Bar and use them in rules and journeys.

You can enhance the functionality of Beacon Bar by emitting custom events from your app. These events can carry specific information and attributes and can be used to trigger rules and journeys, allowing you to tailor user interactions and experiences.

#### Emitting a Custom Event

To emit a custom event to Beacon Bar, you can use the `Beacon.trackEvent` method. This method takes two parameters:

1. `eventName` (string): The name of the event. Only alphanumeric characters (a-zA-Z0-9), underscores (\_), and hyphens (-) are allowed.
2. `attributes` (object, optional): An object containing attributes to be passed with the event.

Here's how to use it:

```
import { Beacon } from '@beacon.li/bar';
Beacon.trackEvent('event_name', {
    // Your attributes here
});
```

In the example above, we are emitting a custom event with the name `'event_name'` and optional attributes. These attributes can include any additional information you want to associate with the event.

#### Event Attributes

Event attributes can be used to provide context or additional data to your custom events. For example, you might include user information, timestamps, or specific details related to the event.

#### Use Cases

Emitting custom events can be beneficial for various scenarios, such as:

* Tracking user interactions or actions within your app.
* Providing context to Beacon Bar for more personalized responses.
* Triggering rules or journeys based on specific user behaviors or events.

By emitting custom events using `@beacon.li/bar`, you can create dynamic and engaging experiences for your users, tailoring your support and communication based on their actions.

#### Important Considerations

When defining custom events and attributes, ensure that you have a clear understanding of the events you want to track and how they align with your app's functionality and user experience.

By following these steps, you can emit custom events to Beacon Bar and use them in rules and journeys to enhance user interactions and engagement.


---

# 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://api.beacon.li/emitting-events-to-beacon.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.
