---
title: Configure a notification listener using the Java SDK
slug: feature-experimentation/docs/set-up-notification-listener-java
docTags: 
createdAt: 2026-08-05T20:40:02.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.

## 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 Java SDK](docId\:WlItbLTrjYBNvKSjoGIFY).
:::

## 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.

```java
import com.optimizely.ab.notification.*;

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

// Remove all Notification Listeners
optimizely.getNotificationCenter().clearAllNotificationListeners();

// Remove all Notification Listeners of a certain type
optimizely.getNotificationCenter().clearNotificationListeners(DecisionNotification.class);
```

## Configure each type of notification listener

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

```java
import com.optimizely.ab.notification.*;
// import your third-party analytics integration here

/**************************************
* SET UP DECISION NOTIFICATION LISTENER
**************************************/
int notificationId = optimizely.addDecisionNotificationHandler((DecisionNotification decisionNotification) -> {
  // Access type on decisionObject to get type of decision
  String decisionType = decisionNotification.getType();
  if ("flag".equals(decisionType)) {
    Map<String, ?> decisionInfo = decisionNotification.getDecisionInfo();
    logger.debug(decisionInfo.get("flagKey"));
    logger.debug(decisionInfo.get("enabled"));
    logger.debug(decisionInfo.get("decisionEventDispatched"));
    // Send data to analytics provider here
  }
});

/**************************************
* SET UP LOG EVENT NOTIFICATION LISTENER
**************************************/
int notificationId = optimizely.addLogEventNotificationHandler(logEvent -> {
	// process the logEvent object here (send to analytics provider, audit/inspect data)
});

/**************************************
* SET UP OPTIMIZELY CONFIG NOTIFICATION LISTENER
**************************************/
// listen to OPTIMIZELY_CONFIG_UPDATE to get updated data
// You will get notifications whenever the datafile is updated except for SDK initialization
optimizely.addUpdateConfigNotificationHandler(config -> {
	OptimizelyConfig optimizelyConfig = optimizely.getOptimizelyConfig();
});

/**************************************
* SET UP TRACK LISTENER
**************************************/
optimizely.addTrackNotificationHandler(trackNotification -> {
	// process the event here (send to analytics provider, audit/inspect data)
});
```
