Submit FeedbackJoin Developer Community

Initialize SDK

To initialize the OptimizelyClient you will need either the SDK key or hard-coded JSON datafile.

Basic initialization with SDK Key

import optly ""

// Instantiates a client that syncs the datafile in the background
optlyClient, er := optly.Client("SDK_KEY_HERE")

Static client instance

If you do not want the client to periodically sync the datafile in the background, you can instantiate a static client. This is useful for using the SDK in short-lived environments, such as Lambda functions. You can use the OptimizelyFactory for these more advanced use cases:

import ""

optimizelyFactory := &client.OptimizelyFactory{
          Datafile: []byte("DATAFILE_JSON_STRING_HERE"),

// Instantiate a static client (no datafile polling)
staticOptlyClient, err := optimizelyFactory.StaticClient()

If you want the SDK to initialize and perform just a one-time remote datafile fetch you can pass in the SDK key instead and instantiate a static client:

import ""

optimizelyFactory := &client.OptimizelyFactory{
          SDKKey: "[SDK_KEY_HERE]",

// Instantiate a static client that will pull down the datafile one time
staticOptlyClient, err := optimizelyFactory.StaticClient()

Advanced configuration

You can further customize the top-level components of the SDKs: Event Processor, Config Manager, and Decision Service using the OptimizelyFactory:

import (

optimizelyFactory := &client.OptimizelyFactory{
          SDKKey: "[SDK_KEY_HERE]",

datafilePollingInteval := 2 * time.Second
eventBatchSize := 20
eventQueueSize := 1500
eventFlushInterval := 10 * time.Second

// Instantiate a client with custom configuration
optimizelyClient, _ := optimizelyFactory.Client(
        client.WithPollingConfigManager(datafilePollingInterval, nil),

For more details on configuring the event batching please see Event Batching

Use authenticated datafile in secure environment


Beta feature

Contact your Customer Success Manager if you are interested in becoming an early user of authenticated datafiles as part of the beta secure environment feature.

You can fetch the Optimizely datafile from an authenticated endpoint using a server-side (only) Optimizely SDK. To use an authenticated datafile, download your Optimizely environment's access token from the Optimizely app at Settings>Environments. Select your secure environment, and copy the Datafile access token. The example below shows how to initialize the Optimizely client using an access token and sdk_key, enabling the client to fetch the authenticated datafile and complete initialization.

// fetch the datafile from an authenticated endpoint
sdkKey := `<YOUR_SKD_KEY>`
factory := client.OptimizelyFactory{SDKKey: sdkKey}
optimizelyClient, err := factory.Client(client.WithDatafileAccessToken(accessToken))

Did this page help you?