---
title: Configure a notification listener using the JavaScript SDK v6+
slug: feature-experimentation/docs/set-up-a-notification-listener-using-the-javascript-sdk
docTags: 
createdAt: 2026-08-05T20:39:59.000Z
---

Notification listeners trigger a callback function that you define when certain actions are triggered in the SDK.

The most common use case is to send a stream of all feature flag decisions to an analytics provider or to an internal data warehouse to join it with other data that you have about your users.

## Minimum SDK version

v6.0.0+

For versions 5.3.5 and earlier, see [JavaScript (Browser) SDK](docId\:iYEM6cOT51dak_I7ellNY) or [JavaScript (Node) SDK](docId\:qykXcla2WZgtq4LHGWSfU). See the [SDK compatibility matrix](docId:2shbZfPCkPAZ0mlZpL1TU) documentation for a list of current SDK releases and the features they support.

## Notification listener types

For information about notification listener types and use cases, see [Notification listeners](docId:0d__cjuKECyJGqgTV0_5e).

:::hint{type="info"}
**Note**
The following code examples assume you have already [initialized the JavaScript SDK](docId:2bQ4KAFcVOAesqDOcmtCZ) and have created an `optimizelyClient` instance.
:::

## Add and remove all notification listeners

The following example code shows how to add a listener, remove a listener, remove all listeners of a specific type (such as all decision listeners), and remove all listeners.

```javascript
import {
  createInstance,
  createPollingProjectConfigManager,
  NOTIFICATION_TYPES,
} from "@optimizely/optimizely-sdk";

const SDK_KEY = "YOUR_SDK_KEY";

const pollingConfigManager = createPollingProjectConfigManager({
  sdkKey: SDK_KEY,
});

const optimizely = createInstance({
  projectConfigManager: pollingConfigManager,
});


// Add Notification Listener
const notificationId = optimizely.notificationCenter.addNotificationListener(
  NOTIFICATION_TYPES.DECISION,
  ({ type, userId, attributes, decisionInfo }) => {
    console.log(type, userId, attributes, decisionInfo);
  }
);

// Remove Notification Listener
optimizely.notificationCenter.removeNotificationListener(notificationId);

// Remove All Notification Listeners
optimizely.notificationCenter.clearAllNotificationListeners();

// Remove all Notification Listeners of a certain type
optimizely.notificationCenter.clearNotificationListeners(
  NOTIFICATION_TYPES.DECISION
);
```

## Configure each type of notification listener

The following example code shows how to configure each type of notification listener.

```javascript
import {
  createInstance,
  createPollingProjectConfigManager,
  NOTIFICATION_TYPES,
} from "@optimizely/optimizely-sdk";

const SDK_KEY = "YOUR_SDK_KEY";

const pollingConfigManager = createPollingProjectConfigManager({
  sdkKey: SDK_KEY,
});

const optimizely = createInstance({
  projectConfigManager: pollingConfigManager,
});

/////////////////////////////////////////////
// CONFIGURE DECISION NOTIFICATION LISTENER //
/////////////////////////////////////////////
const onDecision = ({ type, userId, attributes, decisionInfo }) => {
  // Add a DECISION Notification Listener for type FLAG
  if (type === "flag") {
    // Access information about feature, for example, key and enabled status
    console.log(decisionInfo["flagKey"]);
    console.log(decisionInfo["enabled"]);
    console.log(decisionInfo["decisionEventDispatched"]);
    // Send data to analytics provider here
  }
};

const notificationId = optimizely.notificationCenter.addNotificationListener(
  NOTIFICATION_TYPES.DECISION,
  onDecision
);

///////////////////////////////////////////////
// CONFIGURE LOG EVENT NOTIFICATION LISTENER //
///////////////////////////////////////////////
const onLogEvent = (logEvent) => {
  // process the logEvent object here (send to analytics provider, audit/inspect data)
};

optimizely.notificationCenter.addNotificationListener(
  NOTIFICATION_TYPES.LOG_EVENT,
  onLogEvent
);

///////////////////////////////////////////////////////
// CONFIGURE OPTIMIZELY CONFIG NOTIFICATION LISTENER //
///////////////////////////////////////////////////////
// listen to OPTIMIZELY_CONFIG_UPDATE to get updated data
// You get notifications whenever the datafile is updated except for SDK initialization
const onConfigUpdateListener = () => {
  const config = optimizely.getOptimizelyConfig();
};

optimizely.notificationCenter.addNotificationListener(
  NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE,
  onConfigUpdateListener
);

///////////////////////////////////////////
// CONFIGURE TRACK NOTIFICATION LISTENER //
///////////////////////////////////////////
const onTrack = (event) => {
  // process the event here (send to analytics provider, audit or inspect data)
};

optimizely.notificationCenter.addNotificationListener(
  NOTIFICATION_TYPES.TRACK,
  onTrack
);
```
