Third-parties bots can skew your experiment results by crawling your website and triggering events you only want to count for "real" visitors. Optimizely can solve this for you by filtering out bots that are on the IAB/ABC blacklist. All you have to do is include the user agent for an event when you send that event to Optimizely.
Bot filtering does not apply to past bot events, so it is best to 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.
Navigate to Settings > Advanced > Bot Filtering in the [Optimizely app](https://app.optimizely.com to turn bot filtering on or off. For more information, see our article Bot and spider filtering in Optimizely.
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 it can be filtered with your event. 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 in this way, Optimizely applies bot filtering.
Enable bot filtering in Optimizely first
Before implementing the
$opt_user_agentattribute, navigate to Settings > Advanced in the Optimizely app to turn bot filtering on or off.
The example below shows how to pass the
// Get the user agent and pass it to the Optimizely user context // as the attribute $opt_user_agent let user_agent = "this_could_be_a_bot" 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")
Updated 4 months ago