---
title: Configure a notification listener using the Ruby SDK
slug: feature-experimentation/docs/set-up-notification-listener-ruby
docTags: 
createdAt: 2026-08-05T20:39:53.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 follow code examples assume you have already [initialized the Ruby SDK](docId\:GZzK3CQxBF2g4uWupfu70) and have created an `optimizely_client` 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.

```ruby
# Remove Notification Listener
optimizely_client.notification_center.remove_notification_listener(notification_id)

# Remove all Notification Listeners
optimizely_client.notification_center.clear_all_notification_listeners()

# Remove all Notification Listeners of a certain type
optimizely_client.notification_center.clear_notification_listeners(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:DECISION])
```

## Configure each type of notification listener

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

```ruby
# frozen_string_literal: true

# import your third-party analytics integration here

#######################################
# SET UP DECISION NOTIFICATION LISTENER
#######################################

def on_decision(decision_type, _user_id, _attributes, decision_info)
  # Add a DECISION Notification Listener for type FLAG
  return unless decision_type == 'flag'

  # Access information about feature flag, for example, key and enabled status
  puts decision_info[:flag_key]
  puts decision_info[:enabled]
  puts decision_info[:decision_event_dispatched]
  # Send data to analytics provider here
end

optimizely_client.notification_center.add_notification_listener(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:DECISION], method(:on_decision))

#######################################
# SET UP LOG EVENT NOTIFICATION LISTENER
#######################################

def on_log_event(log_event) end

optimizely_client.notification_center.add_notification_listener(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT], method(:on_log_event))

#######################################
# 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
def on_config_update
  config = optimizely_client.get_optimizely_config
end

optimizely_client.notification_center.add_notification_listener(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:OPTIMIZELY_CONFIG_UPDATE], method(:on_config_update))

#######################################
# SET UP TRACK LISTENER
#######################################

def on_track(event_key, user_id, attributes, event_tags, _event)
  # process the event here (send to analytics provider, audit/inspect data)
end

optimizely_client.notification_center.add_notification_listener(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK], method(:on_track))
```
