Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket

Filter out bots

This topic describes how to filter out third-party bot data that may skew your experiment results in Optimizely Full Stack.

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.

📘

Note

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.

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 help support 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 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.

🚧

Important

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)