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
  1. Listening to events from Beacon Bar

Adding event listeners in Beacon

Listen to different analytical events emitted by Beacon Bar

Beacon Bar allows you to track and emit various analytical events that provide insights into user behavior and interactions with your application. You can listen to these events by adding event listeners, enabling you to gather valuable data and respond to specific user actions.

Adding an Event Listener

To listen to analytical events emitted by Beacon Bar, you can use the Beacon.addEventListener method. This method takes one parameter, which is a callback function with the following signature:

(eventName, attributes, userId) => {
    // Your event handling logic here
}
  • eventName (string): The name of the event.

  • attributes (object): An object containing attributes passed with the event.

  • userId (string, default: beacon-anonymous): The unique identifier passed during loadUser.

Here's how to add an event listener:

import { Beacon } from '@beacon.li/bar';
Beacon.addEventListener((eventName, attributes, userId) => {
    // Your event handling logic here
});

In the example above, we've added an event listener that will execute the specified event handling logic whenever an analytical event is emitted by Beacon Bar.

Use Cases

Listening to analytical events can be useful for various purposes, such as:

  • Gathering data on user interactions and behaviors.

  • Tracking specific events for analytics and reporting.

  • Responding to user actions or behaviors within your app.

By adding event listeners with @beacon.li/bar, you can gain insights into user engagement and use this data to improve your application's user experience.

Important Considerations

When handling events, ensure that you have a clear understanding of the events you want to listen to and the actions you want to take based on those events. Analytical events can provide valuable information for optimizing your app's functionality and user satisfaction.

By following these steps, you can listen to analytical events emitted by Beacon Bar and respond to user interactions and behaviors effectively.

PreviousListening to events from Beacon BarNextRemoving event listeners in Beacon

Last updated 1 year ago