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 GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket
These docs are for v2.0. Click to read the latest docs for v3.0.

Instantiate a client

đŸ“˜

Note

This topic doesn't apply to most mobile use cases. If you're using the iOS SDK or Android SDK, see Initialize a mobile SDK, which describes getting the datafile and instantiating a client.

Once you have a datafile, you can instantiate an Optimizely client. Any time you retrieve an updated datafile, just re-instantiate the same client.

For simple applications, all you need to provide to instantiate a client is a datafile specifying the project configuration for a given environment. For most advanced implementations, you'll want to customize the client for your specific requirements.

using OptimizelySDK;

// Instantiate an Optimizely client
Optimizely OptimizelyClient = new Optimizely(datafile);
import com.optimizely.ab.Optimizely;

// Instantiate an Optimizely client
Optimizely optimizelyClient = Optimizely.builder(datafile, eventHandler).build();
var optimizely = require('@optimizely/optimizely-sdk');

// Instantiate an Optimizely client
var optimizelyClientInstance = optimizely.createInstance({ datafile: datafile });

/* Alternatively, if you don't use CommonJS or npm, you can install
*  the minified snippet and use the globally exported variable as follows
*/
var optimizelyClientInstance = window.optimizelyClient.createInstance({ datafile: datafile });
// Minimal client
const optimizely = require("@optimizely/optimizely-sdk");
const rp = require("request-promise");

// TODO: replace with your datafile URL
const DATAFILE_URL =
  "https://cdn.optimizely.com/datafiles/QMVJcUKEJZFg8pQ2jhAybK.json";
const datafile = await rp({ uri: DATAFILE_URL, json: true });
console.log("Datafile:", datafile);
var optimizelyClient = optimizely.createInstance({
  datafile
});
// Use optimizelyClient to run experiments
use Optimizely\Optimizely;

// Instantiate an Optimizely client
$optimizelyClient = new Optimizely($datafile);
from optimizely import optimizely

# Instantiate an Optimizely client
optimizely_client = optimizely.Optimizely(datafile)
require "optimizely"

# Initialize an Optimizely client
optimizely_client = Optimizely::Project.new(datafile)

There are several other optional parameters for configuring the Optimizely client. See the Customize an SDK and the API reference sections.