# How to Filter Events in JavaScript SDK

<!--Page Type: How-To Guide-->

<!--
Table of Contents:
1. Introduction
2. Filter destinations while loading SDK
3. Filter destinations at event level
4. Client-side event filtering
-->

This guide covers the following event filtering use cases:

- [Send all events to specific destinations](#filter-destinations-while-loading-the-sdk) (web device mode only)
- [Filter destinations at the event level](#filter-destinations-at-event-level)
- [Filter client-side events](#client-side-event-filtering) before sending them to destinations (web device mode only)

## Filter destinations while loading the SDK

You can filter all events sent to [web device mode]({{< ref "destinations/rudderstack-connection-modes.md#device-mode" >}}) destinations by passing an [integrations]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk.md#integrationopts" >}})  object in the [`load` API]({{< ref "https://rudder-hugo-k0pulrr6k-rudder-stack.vercel.app/sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk.md#loading-options" >}}) options. RudderStack then loads and sends events only to the allowed (and enabled) destinations.

{{< info >}}
The `integrations` object in the `load` API only controls the loading of the device mode destinations. The data is **not** propagated to the individual event payloads automatically.

To [use the globally-defined integration options at the event level]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk.md#useglobalintegrationsconfiginevents" >}}), set the `useGlobalIntegrationsConfigInEvents` option of the `load` API to `true`.
{{< /info >}}

A sample snippet to send event data only to the **Amplitude** and **Intercom** destinations:

```javascript
rudderanalytics.load(WRITE_KEY, DATA_PLANE_URL, {
    integrations: {
        All: false,
        "Amplitude": true,
        "Intercom": true
    }
});
```

## Filter destinations at event level

You can control filtering a single event to the allowed (and enabled) destinations.

A sample `track` event instrumentation to send the event only to the **Amplitude** destination:

```javascript
rudderanalytics.track(
    "Order Completed", {
        revenue: 30,
        currency: "USD",
        user_actual_id: 12345
    }, {
        integrations: {
            All: false,
            "Amplitude": true
        }
    }
);
```

{{< warning >}}
The destination name in the `integrations` object should match the name exactly as displayed in the [RudderStack dashboard](https://app.rudderstack.com/directory). It should **not** be the name that you assigned to the destination while setting it up in RudderStack.

{{< figure src="images/dashboard-guides/amplitude-destination-name-webapp.webp" >}}
{{< /warning >}}

### Use the global integrations object

You can also use the globally-defined `integrations` object ( [`useGlobalIntegrationsConfigInEvents`]({{< ref "sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk.md#useglobalintegrationsconfiginevents" >}}) option of the `load` API) to enforce the destination filtering settings at the event level **if** it is not defined in the event already.

{{< info >}}
The SDK gives precedence to the `integrations` object defined at the event level over the globally-defined `integrations` object.
{{< /info >}}

## Client-side event filtering

To implement client-side event filtering for [web device mode]({{< ref "destinations/rudderstack-connection-modes.md#device-mode" >}}) destinations, you can configure the [filtering options]({{< ref "sources/event-streams/sdks/event-filtering.md#event-filtering-options" >}}) in the RudderStack dashboard. This allows you to control which `track` events are sent to specific destinations without modifying your SDK implementation.

**No additional SDK configuration is required**. The JavaScript SDK automatically respects and applies the filtering rules you have set up in the dashboard.

<br />
