---
title: Add Listener
slug: performance-edge/api/add-listener
docTags: 
createdAt: 2026-06-23T06:59:31.198Z
---

Listen to a snippet lifecycle event.

## Description

Listen to a specific event from somewhere in the snippet's execution. Your handler function will be invoked for each applicable lifecycle event that occurs **after** the handler is registered. It is **not** retroactively invoked for events that may have occurred prior to handler registration.

You can listen to the following types of events:

```javascript
window.optimizelyEdge.push(addListener);
```

```javascript
window.optimizelyEdge.push({
  "type": "addListener",
  "filter": {
    "type": "lifecycle",
    "name": "initialized"
  },
  "handler": function(event) {
    console.log("Project " + window["optimizely"].get("data").projectId + " is initialized");
  }
});
```

## Parameters

This table provides general information about required and optional parameters.

| Parameter                              | Type     | Description                                                                                                                        |
| -------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| **addListener** *required*             | object   | An object with the `type` field set to `addListener`. The other fields are the function arguments.                                 |
| **addListener.type** *required*        | string   | The argument indicating that you are using the addListener function.                                                               |
| **addListener.filter** *optional*      | object   | By setting a filter, you can define for which type of events or what category of events the handler is called.                     |
| **addListener.handler** *optional*     | function | The function that will be called when the event occurs.                                                                            |
| **addListener.filter.type** *required* | string   | The category of an event. Possible values: `lifecycle` and `analytics`.                                                            |
| **addListener.filter.name** *optional* | string   | The name of the event type. The value can be: `campaignDecided`, `pageActivated`, `initialized`, `originsSynced`, or `trackEvent`. |

