Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide
These docs are for v2.0. Click to read the latest docs for v3.0.

Manage bot filtering

Bot filtering allows you to filter events by sending user agents to Optimizely with your events. Optimizely will compare the list of user agents you send to a list of known bots, and filter all user agents that are on the IAB/ABC blacklist.

Enable bot filtering

Navigate to Settings > Advanced > Bot Filtering in the Optimizely app to turn bot filtering on or off. For more information, see our KB article Bot and spider filtering in Optimizely.

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 Activate, Is Feature Enabled, or Track methods, the SDK automatically includes the user’s user agent in the outbound request. If bot filtering is enabled for your project, Optimizely applies bot filtering automatically.

All other Full Stack events

When you track events with an SDK from somewhere other than a web browser, you must pass the user agent to be filtered with your event. You should pass it using the reserved $opt_user_agent attribute in the Track, Activate, Is Feature Enabled, and Get Enabled Features functions. If bot filtering is enabled for your project and the user agent is passed in this way, Optimizely applies bot filtering.

📘

Note

Enable bot filtering in Optimizely first. Before implementing the $opt_user_agent attribute, navigate to Settings > Advanced in the Optimizely app to turn bot filtering on or off.

The example below shows how to pass the $opt_user_agent attribute.

/**
 * Get the user agent and pass it to the Optimizely client as the 
 * attribute $opt_user_agent
 */
using OptimizelySDK.Entity;

var userAgent = "this_could_be_a_bot";

UserAttributes attributes = new UserAttributes
{
  { "device", "iphone" },
  { "location", "Chicago" },
  { "$opt_user_agent", userAgent }
};

// Include user agent when activating an A/B test
optimizelyClient.Activate("some_experiment", "some_user", attributes);

// Include user agent when tracking an event
optimizelyClient.Track("some_conversion_event", "some_user", attributes);

// Include user agent when accessing a feature
optimizelyClient.IsFeatureEnabled("some_feature", "some_user", attributes);
/**
 * Get the user agent and pass it to the Optimizely client as the
 * attribute $opt_user_agent
 */
String userAgent = "this_could_be_a_bot";

Map<String, String> attributes = new HashMap<String, String>();
attributes.put("device", "iphone");
attributes.put("location", "Chicago");
// Set user agent
attributes.put("$opt_user_agent", userAgent);

// Include user agent when activating an A/B test
optimizelyClient.activate("some_experiment", "some_user", attributes);

// Include user agent when tracking an event
optimizelyClient.track("some_conversion_event", "some_user", attributes);

// Include user agent when accessing a feature
optimizelyClient.isFeatureEnabled("some_feature", "some_user", attributes);
/**
 * Server-side JavaScript example.
 * No code is required to enable bot filtering for
 * events sent from a browser.
 *
 * Get the user agent and pass it to the Optimizely client as the
 * attribute $opt_user_agent
 */
var userAgent = "this_could_be_a_bot";
var attributes = {
  device: "iphone",
  location: "Chicago",
  $opt_user_agent: userAgent
};

// Include user agent when activating an A/B test
optimizelyClient.activate("my_experiment", userId, attributes);

// Include user agent when tracking an event
optimizelyClient.track("my_conversion", userId, attributes);

// Include user agent when accessing a feature
optimizelyClient.isFeatureEnabled("price_filter", userId, attributes);
/**
 * Get the user agent and pass it to the Optimizely client 
 *  as the attribute $opt_user_agent
 */

NSString *experimentKey = @"some_experiment";
NSString *userId = @"some_user";
NSDictionary *attributes = @{@"device"              : @"iphone",
                             @"location"            : @"Chicago",
                             @"$opt_user_agent"     : @"this_could_be_a_bot"};

// Include user agent when activating an A/B test
OPTLYVariation *variation = [optimizelyClient activate:experimentKey
                                                userId:userId
                                            attributes:attributes];

// Include user agent when tracking an event
NSString *eventKey = @"some_conversion_event";
[optimizelyClient track:eventKey
                        userId:userId
                    attributes:attributes];
/** 
 * Get the user agent and pass it to the Optimizely client 
 * as the attribute $opt_user_agent
 */
$userAgent = "this_could_be_a_bot";

$attributes = [
  'device' => 'iphone',
  'location' => 'Chicago',
  '$opt_user_agent' => $userAgent
];

// Include user agent when activating an A/B test
$optimizelyClient->activate("some_experiment", "some_user", $attributes);

// Include user agent when tracking an event
$optimizelyClient->track("some_conversion_event", "some_user", $attributes);

// Include user agent when accessing a feature
$optimizelyClient->isFeatureEnabled("some_feature", "some_user", $attributes);
# Get the user agent and pass it to the Optimizely client 
# as the attribute $opt_user_agent

user_agent = 'this_could_be_a_bot'

attributes = {
  'device': 'iphone',
  'location': 'Chicago',
  '$opt_user_agent': user_agent
}

# Include user agent when activating an A/B test
optimizely_client.activate('some_experiment', 'some_user', attributes)

# Include user agent when tracking an event
optimizely_client.track('some_conversion_event', 'some_user', attributes)

# Include user agent when accessing a feature
optimizely_client.is_feature_enabled('some_feature', 'some_user', attributes)
# Get the user agent and pass it to the Optimizely client 
# as the attribute $opt_user_agent

user_agent = 'this_could_be_a_bot'

attributes = {
  'device' => 'iphone',
  'location' => 'Chicago',
  '$opt_user_agent' => user_agent
}

# Include user agent when activating an A/B test
optimizely_client.activate('some_experiment', 'some_user', attributes)

# Include user agent when tracking an event
optimizely_client.track('some_conversion_event', 'some_user', attributes)

# Include user agent when accessing a feature
optimizely_client.is_feature_enabled('some_feature', 'some_user', attributes)
/**
 * Get the user agent and pass it to the Optimizely client 
 *  as the attribute $opt_user_agent
 */

let experimentKey = "some_experiment"
let userId = "some_user"
let attributes = ["device"          : "iphone",
                  "location"        : "Chicago",
                  "$opt_user_agent" : "this_could_be_a_bot"]

// Include user agent when activating an A/B test
optimizelyClient?.activate(experimentKey, userId, attributes)

// Include user agent when tracking an event
let eventKey = 'some_conversion_event'
optimizelyClient?.track(eventKey, userId, attributes)