Optimizely.SDK
3.11.2
Prefix Reserved
See the version list below for details.
dotnet add package Optimizely.SDK --version 3.11.2
NuGet\Install-Package Optimizely.SDK -Version 3.11.2
<PackageReference Include="Optimizely.SDK" Version="3.11.2" />
paket add Optimizely.SDK --version 3.11.2
#r "nuget: Optimizely.SDK, 3.11.2"
// Install Optimizely.SDK as a Cake Addin #addin nuget:?package=Optimizely.SDK&version=3.11.2 // Install Optimizely.SDK as a Cake Tool #tool nuget:?package=Optimizely.SDK&version=3.11.2
Optimizely C# SDK
This repository houses the .Net based C# SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).
Optimizely Feature Experimentation is an A/B testing and feature management tool for product development teams, letting you experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at Optimizely.com, or see the developer documentation.
Optimizely Rollouts is free feature flags for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.
Get Started
Refer to the C# SDK's developer documentation for detailed instructions on getting started with using the SDK.
Install the C# SDK
The SDK can be installed through NuGet:
PM> Install-Package Optimizely.SDK
An ASP.Net MVC sample project demonstrating how to use the SDK is available as well:
PM> Install-Package Optimizely.SDK.Sample
Simply compile and run the Sample application to see it in use. Note that the way the Demo App stores data in memory is not recommended for production use and is merely illustrates how to use the SDK.
Feature Management Access
To access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely customer success manager.
Use the C# SDK
See the Optimizely Feature Experimentation developer documentation to learn how to set up your first C# project and use the SDK.
Initialization
Create the Optimizely Client, for example:
private static Optimizely Optimizely =
new Optimizely(
datafile: myProjectConfig,
eventDispatcher: myEventDispatcher,
logger: myLogger,
errorHandler: myErrorHandler,
skipJsonValidation: false);
Since this class parses the Project Config file, you should not create this per request.
APIs
This class exposes three main calls:
- Activate
- Track
- GetVariation
Activate and Track are used in the demonstration app. See the Optimizely documentation regarding how to use these.
Plug-in Interfaces
The Optimizely client object accepts the following plug-ins:
IEventDispatcher
handles the HTTP requests to Optimizely. The default implementation is an asynchronous "fire and forget".ILogger
exposes a single method, Log, to record activity in the SDK. An example of a class to bridge the SDK's Log to Log4Net is provided in the Demo Application.IErrorHandler
allows you to implement custom logic when Exceptions are thrown. Note that Exception information is already included in the Log.ProjectConfigManager
exposes method for retrieving ProjectConfig instance. Examples includeFallbackProjectConfigManager
andHttpProjectConfigManager
.EventProcessor
provides an intermediary processing stage within event production. It's assumed that the EventProcessor dispatches events via a provided EventDispatcher. Examples includeForwardingEventProcessor
andBatchEventProcessor
. These are optional plug-ins and default behavior is implement if none are provided.
OptimizelyFactory
OptimizelyFactory
provides basic utility to instantiate the Optimizely SDK with a minimal number of configuration options.
OptimizelyFactory
does not capture all configuration and initialization options. For more use cases,
build the resources via their respective builder classes.
Use OptimizelyFactory
You must provide the SDK key at runtime, either directly via the factory method:
Optimizely optimizely = OptimizelyFactory.newDefaultInstance(<<SDK_KEY>>);
You can also provide default datafile with the SDK key.
Optimizely optimizely = OptimizelyFactory.newDefaultInstance(<<SDK_KEY>>, <<Fallback>>);
Using App.config in OptimizelyFactory
OptimizelyFactory provides support of setting configuration variables in App.config: User can provide variables using following procedure:
- In App.config file of your project in <configuration> add following:
<configSections>
<section name="optlySDKConfigSection"
type="OptimizelySDK.OptimizelySDKConfigSection, OptimizelySDK, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
- Now add optlySDKConfigSection below <configSections>. In this section you can add and set following HttpProjectConfigManager and BatchEventProcessor variables:
<optlySDKConfigSection>
<HttpProjectConfig sdkKey="43214321"
url="www.testurl.com"
format="https://cdn.optimizely.com/data/{0}.json"
pollingInterval="2000"
blockingTimeOutPeriod="10000"
datafileAccessToken="testingtoken123"
autoUpdate="true"
defaultStart="true">
</HttpProjectConfig>
<BatchEventProcessor batchSize="10"
flushInterval="2000"
timeoutInterval="10000"
defaultStart="true">
</BatchEventProcessor>
</optlySDKConfigSection>
- After setting these variables you can instantiate the Optimizely SDK using function:
Optimizely optimizely = OptimizelyFactory.newDefaultInstance();
BatchEventProcessor
BatchEventProcessor is a batched implementation of the EventProcessor * Events passed to the BatchEventProcessor are immediately added to a BlockingQueue. * The BatchEventProcessor maintains a single consumer thread that pulls events off of the BlockingQueue and buffers them for either a configured batch size or for a maximum duration before the resulting LogEvent is sent to the NotificationManager.
Use BatchEventProcessor
EventProcessor eventProcessor = new BatchEventProcessor.Builder()
.WithMaxBatchSize(MaxEventBatchSize)
.WithFlushInterval(MaxEventFlushInterval)
.WithEventDispatcher(eventDispatcher)
.WithNotificationCenter(notificationCenter)
.Build();
Max Event Batch Size
The Max event batch size is used to limit eventQueue batch size and events will be dispatched when limit reaches.
Flush Interval
The FlushInterval is used to specify a delay between consecutive flush events call. Event batch will be dispatched after meeting this specified timeSpan.
Event Dispatcher
Custom EventDispatcher can be passed.
Notification Center
Custom NotificationCenter can be passed.
HttpProjectConfigManager
HttpProjectConfigManager
is an implementation of the abstract PollingProjectConfigManager
.
The Poll
method is extended and makes an HTTP GET request to the configured URL to asynchronously download the
project datafile and initialize an instance of the ProjectConfig.
By default, HttpProjectConfigManager
will block until the first successful datafile retrieval, up to a configurable timeout.
Set the frequency of the polling method and the blocking timeout with HttpProjectConfigManager.Builder
.
Use HttpProjectConfigManager
HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()
.WithSdkKey(sdkKey)
.WithPollingInterval(TimeSpan.FromMinutes(1))
.Build();
SDK key
The SDK key is used to compose the outbound HTTP request to the default datafile location on the Optimizely CDN.
Polling interval
The polling interval is used to specify a fixed delay between consecutive HTTP requests for the datafile. Between 1 to 4294967294 miliseconds is valid duration. Otherwise default 5 minutes will be used.
Blocking Timeout Period
The blocking timeout period is used to specify a maximum time to wait for initial bootstrapping. Between 1 to 4294967294 miliseconds is valid blocking timeout period. Otherwise default value 15 seconds will be used.
Initial datafile
You can provide an initial datafile via the builder to bootstrap the ProjectConfigManager
so that it can be used immediately without blocking execution.
URL
The URL is used to specify the location of datafile.
Format
This option enables user to provide a custom URL format to fetch the datafile.
Start by default
This option is used to specify whether to start the config manager on initialization or not. If no value is provided, by default it is true and will start polling datafile from remote immediately.
Datafile access token
This option is used to provide token for datafile belonging to a secure environment.
SDK Development
Contributing
Please see CONTRIBUTING.
Third Party Licenses
Optimizely SDK uses third party software: murmurhash-signed, Newtonsoft.Json, and NJsonSchema.
Other Optimzely SDKs
Flutter - https://github.com/optimizely/optimizely-flutter-sdk
JavaScript - https://github.com/optimizely/javascript-sdk
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 3.5
- murmurhash-signed (>= 1.0.2)
- Newtonsoft.Json (>= 9.0.1)
-
.NETFramework 4.0
- murmurhash-signed (>= 1.0.2)
- Newtonsoft.Json (>= 9.0.1)
-
.NETFramework 4.5
- murmurhash-signed (>= 1.0.2)
- Newtonsoft.Json (>= 9.0.1)
- NJsonSchema (>= 8.30.6304.31883)
-
.NETStandard 1.6
- murmurhash-signed (>= 1.0.2)
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 9.0.1)
- NJsonSchema (>= 8.33.6323.36213)
-
.NETStandard 2.0
- murmurhash-signed (>= 1.0.2)
- NETStandard.Library (>= 2.0.3)
- Newtonsoft.Json (>= 9.0.1)
- NJsonSchema (>= 8.33.6323.36213)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.0.0 | 167,608 | 1/16/2024 |
4.0.0-beta | 1,251 | 5/3/2023 |
3.11.4 | 184,870 | 7/28/2023 |
3.11.3 | 2,897 | 7/19/2023 |
3.11.2.1 | 115,259 | 3/24/2023 |
3.11.2 | 7,003 | 3/17/2023 |
3.11.1 | 291,468 | 8/3/2022 |
3.11.0 | 307,830 | 1/13/2022 |
3.10.0 | 130,470 | 9/16/2021 |
3.9.1 | 54,668 | 7/19/2021 |
3.9.0 | 76,613 | 3/29/2021 |
3.8.0 | 24,521 | 2/17/2021 |
3.7.1 | 46,324 | 11/18/2020 |
3.7.0 | 3,659 | 11/3/2020 |
3.6.0 | 31,267 | 10/1/2020 |
3.5.0 | 34,866 | 7/7/2020 |
3.4.1 | 46,057 | 4/30/2020 |
3.4.0 | 124,270 | 1/24/2020 |
3.3.0 | 29,771 | 9/26/2019 |
3.2.0 | 14,233 | 7/23/2019 |
3.1.1 | 872 | 6/19/2019 |
3.1.0 | 23,726 | 5/9/2019 |
3.0.0 | 124,440 | 3/1/2019 |
2.2.2 | 2,099 | 1/31/2019 |
2.2.1 | 21,800 | 11/5/2018 |
2.2.0 | 921 | 10/26/2018 |
2.1.0 | 18,835 | 6/28/2018 |
2.0.1 | 9,051 | 6/20/2018 |
2.0.0 | 2,499 | 4/19/2018 |
2.0.0-beta1 | 975 | 4/3/2018 |
1.3.1 | 2,113 | 2/16/2018 |
1.3.0 | 3,048 | 1/6/2018 |
1.2.1 | 1,129 | 11/6/2017 |
1.2.0 | 1,035 | 10/4/2017 |
1.1.1 | 1,005 | 9/11/2017 |
1.1.0 | 1,719 | 6/7/2017 |
1.0.0 | 12,435 | 5/18/2017 |
0.1.0 | 2,615 | 4/14/2017 |