> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Using listeners

> Register and remove listeners with the median-js-bridge npm package to respond to native app events such as app resume and push notification taps.

The median-js-bridge NPM package allows you to register listener functions that respond to native events triggered within your app. These listeners function similarly to standard JavaScript callbacks but offer a more streamlined and reliable integration with native mobile features.

Listeners are event-driven functions that execute when a native event is triggered. Even if an event occurs *before* the listener is registered, the event will be queued and delivered once the listener initializes, ensuring reliable event capture.

## Listener implementation

### Registering event listeners

Listeners are added using the `.addListener()` method available on specific plugin interfaces. Each listener returns a `listenerId`, which can be used later to remove the listener.

### Example: App resumed event

Median JavaScript Bridge

```javascript JavaScript theme={null}
const listenerId = Median.appResumed.addListener(() => {
    console.log("App resumed listener triggered");
});
```

### Example: OneSignal push notification

Respond to push notifications sent via OneSignal.

Related: [Handling Notifications Taps](https://docs.median.co/docs/handling-notifications-taps.md)

Median JavaScript Bridge

```javascript JavaScript theme={null}
const listenerId = Median.onesignal.pushOpened.addListener((data) => {
    console.log(JSON.stringify(data));
});
```

### Example: Share into app

Handle data shared into your app using the share intent.

Related: [Share into app](https://docs.median.co/docs/share-into-app.md)

Median JavaScript Bridge

```javascript JavaScript theme={null}
const listenerId = Median.shareIntoApp.shareResult.addListener((data) => {
    console.log(data.url, data.subject);
});
```

### Example: Device shake (haptics plugin)

Capture device shake gestures for enhanced interaction.

Related: [Haptics](https://docs.median.co/docs/haptics.md)

Median JavaScript Bridge

```javascript JavaScript theme={null}
const listenerId = Median.deviceShake.addListener(() => {
    console.log("Device shake listener");
});
```

### Example: AppsFlyer conversion data

Receive install attribution and conversion data from AppsFlyer.

Related: [AppsFlyer](https://docs.median.co/docs/appsflyer.md)

Median JavaScript Bridge

```javascript JavaScript theme={null}
const listenerId = Median.appsflyer.conversionData.addListener((conversionDataMap) => {
    console.log(conversionDataMap.af_status);
});
```

## Removing event listeners

To stop listening for a specific event, use the `.removeListener()` method with the stored `listenerId`.

Median JavaScript Bridge

```javascript JavaScript theme={null}
Median.deviceShake.removeListener(listenerId);
```

## Best practices for listener management

* Always store the `listenerId` if you intend to remove the listener later.
* Register listeners early, ideally within a component’s `useEffect` or lifecycle hook.
* Remove listeners on unmount to avoid memory leaks in Single-Page Applications (SPAs).


## Related topics

- [NPM package overview](https://docs.median.co/docs/npm-package.md)
- [AgeSafety](https://docs.median.co/docs/age-safety.md)
- [SPA navigation](https://docs.median.co/docs/npm-package-spa-navigation.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.