---
title: Filter out bots
slug: feature-experimentation/docs/manage-bot-filtering
docTags: 
createdAt: 2026-08-05T20:39:59.000Z
---

Third-party bots can skew your experiment results by crawling your website and triggering events you only want to count for real users. Optimizely filters out bots on the IAB/ABC blocklist. To block bots, include the user agent for an event when you send that event to Optimizely.

For information on how Optimizely filters bots, see [Filter bots and spiders](docId:9bl9V_PV4CzJh_EguSTxH).

:::hint{type="info"}
**Note**
Bot filtering does not apply to past bot events, so you should configure it before you start the experiment. Otherwise, if you enable filtering halfway through an experiment, you might have to discard (or export and manually filter) any bot-contaminated event data from the start of the experiment.
:::

## Enable bot filtering

To exclude bot traffic, first [enable the feature in the UI](docId:9bl9V_PV4CzJh_EguSTxH). Then, depending on your SDK and where events are sent from, you may need to send additional information. If you are using the [JavaScript SDK client-side](docId\:M9EFcaOQEp5o_npzc6uG7), you are done. Otherwise, you must [send the reserved  $opt\_user\_agent  attribute](docId\:M9EFcaOQEp5o_npzc6uG7) containing the user agent to the user context. See the following sections for step-by-step directions.

### Enable in the UI

See [Enable bot filtering in Feature Experimentation](docId:9bl9V_PV4CzJh_EguSTxH) in the end-user documentation for steps to toggle bot filtering on or off for your project.

### Client-side JavaScript events

No additional JavaScript code is required to enable bot filtering for events sent from browsers. When you track an event by calling the JavaScript SDK's [\`Track Event method\`](docId\:m3uU-JFwOjZgWUBjhQfn2) the SDK automatically includes the user's user agent in the outbound request (see [\`Track Event method for SDK versions 5.3.5 and lower\`](docId\:dtQJ11RFUGmfz559B_i18)). If bot filtering is enabled for your project, Optimizely filters bots automatically.

### All other events

When you track events with an SDK from somewhere other than a web browser, you must pass the user agent to the user context so Optimizely can filter bot traffic from your results. You should pass it using the reserved `$opt_user_agent` attribute in user-based methods. If bot filtering is enabled for your project and the user agent is passed this way, Optimizely applies bot filtering.

:::hint{type="warning"}
**Important**
Before implementing the `$opt_user_agent` attribute, [Enable bot filtering](docId\:XgllFIgMAg9q1veDvoFQ9) in your project first.
:::

The following code example shows how to pass the `$opt_user_agent` attribute:

```swift
// Get the user agent and pass it to the Optimizely user context 
// as the attribute $opt_user_agent

let attributes = ["device"          : "iphone",
                  "location"        : "Chicago",
                  "$opt_user_agent" : "this_could_be_a_bot"]

user = optimizely.createUserContext(userId: "test-user-id", attributes: attributes)

// now any user-based call filters out the bot
let decision = user.decide(key: "flag_1")
try? user.trackEvent(eventKey: "my_purchase_event_key")
```

See each SDK's reference section for information.

- [Create a user context using the Android SDK](docId\:gR9wq-XMrQQOtGcWhpyqQ)
- [Create a user context using the C# SDK](docId\:NMLEiJmrOW1XL9kGEplxb)
- [Create a user context using the Flutter SDK](docId:5k27nwFPeEn1-v7XWz1HT)
- [Create a user context using the Go SDK](docId\:UnFDhdqan0QQo54R4_7a3)
- [Create a user context using the Java SDK](docId\:AdphTGCbC7b8i3krPoZIc)
- [Create a user context using the PHP SDK](docId:6QxzVc8cTzURcLkeCt_sf)
- [Create a user context using the Python SDK](docId\:IQktksuBns7WFb6Xv_OVE)
- [Track event for the React SDK](docId\:t8DEKX6FHRjIR4UiXr0Yh)
- [Track event for the React Native SDK](docId:0yISQpKrQP3cySgKUzHy7)
- [Create a user context using the Ruby SDK](docId\:EZ82PrPXF05kJvmd7OoxE)
- [Create a user context using the Swift SDK](docId\:MbsuKcGHantE-rEn9zRfw)
