Beacon API Docs
  • Beacon - Installation
  • Beacon - Usage
    • Beacon Usage - Overview
    • Usage in a Next.js Environment
    • Open and Close Programmatically
  • Native Routing in Beacon
    • Vanilla JS - Native Routing Example
    • React JS - Native Routing Example
    • Vue JS - Native Routing Example
    • Angular JS - Native Routing Example
  • Loading User Data into BeaconBar
  • Loading Session Data into Beacon Bar
  • Callbacks in Beacon
    • Add Callbacks in Beacon
    • Remove Callbacks in Beacon
    • React Example for Callbacks
  • Trigger smart journeys From Your App
  • Execute Command From Your App
  • Open Help Docs From Your App
  • Emitting Events to Beacon
  • Listening to events from Beacon Bar
    • Adding event listeners in Beacon
    • Removing event listeners in Beacon
    • React Example for Event Listeners in Beacon
  • List of events emitted by Beacon Bar
  • Implementing Content Security Policy (CSP) for Beacon Integration
Powered by GitBook
On this page

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.

PreviousOpen Help Docs From Your AppNextListening to events from Beacon Bar

Last updated 1 year ago