The Full Stack Developer Guide Developer Hub

Welcome to the Full Stack Developer Guide developer hub. You'll find comprehensive guides and documentation to help you start working with the Full Stack Developer Guide as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Get the datafile

Note

The content in this topic is specific to non-mobile SDKs that are version 3.1.x and earlier.

If you're using the JavaScript SDK v3.2.0, see Update datafiles automatically for how to get the datafile.

If you're using the iOS or Android SDK, skip straight to Initialize a mobile SDK, which encompasses getting the datafile and instantiating a client.

The datafile is a JSON representation of your Full Stack project. It contains all the instructions needed to run your experiments.

The datafile is updated immediately after changes to your experiments, but it may take a few minutes to upload to the content delivery network (CDN). If you’re experiencing delays longer than five (5) minutes, please contact support.

In general, you don’t need to access the datafile, but it can be handy if your experiments don’t update as expected. The datafile can help you debug a Full Stack experiment and confirm expected updates.

Important

Be careful changing the datafile's environment key as it will impact the datafile URL your code loads. The environment key displays on the Settings > Datafile page; see the image in Access the datafile via the app.

Get the datafile

Before you instantiate a client, get a local copy of the datafile from our servers. Synchronizing this local copy lets the SDK make immediate decisions on experiments, without waiting for a blocking network request.

Note

The JavaScript code sample below shows window.fetch(). Because Internet Explorer (IE) doesn't support fetch(), you must either use a fetch() polyfill with this sample for it to work with IE browsers or instead use XHR to get the datafile.

For more information, see:

string datafile = string.Empty;
var url = "https://cdn.optimizely.com/json/12345.json";
using(var webClient = new System.Net.WebClient()){

  // To refresh on every request
  webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
  datafile = webClient.DownloadString(url);
}

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

try {
    String url = "https://cdn.optimizely.com/datafiles/QMVJcUKEJZFg8pQ2jhAybK.json";
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(url); 
    String datafile = EntityUtils.toString(
      httpclient.execute(httpget).getEntity());
}
catch (Exception e) {
    System.out.print(e);
    return;
}

const url = 'https://cdn.optimizely.com/json/12345.json';
window
  .fetch(url, { mode: 'cors' })
  .then(response => response.json())
  .then(datafile => {
    const optimizelyClientInstance = optimizelySdk.createInstance({
      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;

$url = 'https://cdn.optimizely.com/datafiles/abcdEFGH123.json';
$datafile = file_get_contents($url);

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

from optimizely import optimizely
import requests

url = 'https://cdn.optimizely.com/datafiles/abcdEFGH123.json'
datafile = requests.get(url).text
optimizely_client = optimizely.Optimizely(datafile)

require 'optimizely'
require 'httparty'

url = 'https://cdn.optimizely.com/datafiles/QMVJcUKEJZFg8pQ2jhAybK.json'
datafile = HTTParty.get(url).body
optimizely_client = Optimizely::Project.new(datafile)

How you synchronize and how often you synchronize depends on your application:

  • Recommended method: Use webhooks to notify your server when the datafile changes so it can retrieve the latest version.
  • Alternative method: Poll the CDN or REST API at a regular interval (such as every minute) for an updated datafile. The length of this interval will vary according to your application requirements.

Note

Exactly when Optimizely fetches an updated datafile from the CDN depends on the specific SDK and version, the synchronization method, and the local cached copy version.

Be sure to synchronize the datafile often enough to stay current with changes in the Optimizely project environment without generating unacceptable network traffic and latency. For more information on how to balance network latency with datafile freshness, see Datafile versioning and management.

Fetch the datafile via REST API

You can access the datafile via Optimizely's authenticated REST API. Note that you'll need to authenticate with an API token. For more information, see Read the datafile of an environment.

https://www.optimizelyapis.com/v2/projects/12345

Access the datafile via the app

To access the datafile for your Full Stack project:

  1. Navigate to Settings > Datafile.
  2. Find the SDK Key/Primary URL for the project and environment whose datafile you want to access.
  3. Click the SDK Key/Primary URL to open the CDN link in a new browser tab or window.

View the datafile via the CDN link

This image shows how the datafile appears when accessed from the CDN link.

Example datafile

See Example datafile to see an example in properly formatted JSON.


Get the datafile


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.