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. Beacon - Usage

Usage in a Next.js Environment

PreviousBeacon Usage - OverviewNextOpen and Close Programmatically

Last updated 1 year ago

If you're using Next.js, you'll need to load beacon slightly differently, due to its server-side rendering capabilities. Here's how to do it:

Installation

Before you can use beacon in a Next.js environment, ensure you have installed it using npm as explained in the section of our documentation.

Importing Beacon

In your Next.js code, import the beacon module in the same way as in a regular JavaScript environment:

Loading Beacon

To load Beacon in a Next.js application, make sure you check if the window object is defined before calling Beacon.load. This helps avoid issues with server-side rendering. Here's an example:

import { Beacon } from '@beacon.li/bar';

if (typeof window !== 'undefined') {
    Beacon.load('ORG_ID');
}

With this setup, BeaconBar will be loaded only on the client-side, ensuring compatibility with Next.js.

Installation