- YouTube Video: https://youtu.be/0k5HQVmlItc
- Webinar Recording: Coming Soon!
- Node version >= 8.1
- npm version >= 5.6
Note: This functionality requires an Optimizely plan with access to "Event Data Export"
The following uses the open source command line tool oevents.
oevents bash script (any OS X and most GNU/Linux distributions)| # myapp.rb | |
| require 'sinatra' | |
| require './optly' | |
| get '/' do | |
| enabled = Optly.instance.client.is_feature_enabled('hello_world', 'user123', { | |
| 'customerId' => 123, | |
| 'isVIP' => true | |
| }) |
| enabled = Optly.instance.client.is_feature_enabled('hello_world', 'user123', { | |
| 'customerId' => 123, | |
| 'isVIP' => true | |
| }) | |
| enabled ? 'Hello World! You got the hello_world feature!' : 'You did not get the hello_world feature' |
| # myapp.rb | |
| require 'sinatra' | |
| require './optly' # Imports the Optimizely singleton | |
| get '/' do | |
| 'Hello world!' | |
| end |
| # myapp.rb | |
| require 'sinatra' | |
| get '/' do | |
| 'Hello world!' | |
| end |
| # optly.rb | |
| require 'singleton' | |
| require 'logger' | |
| require 'optimizely/optimizely_factory' | |
| class Optly | |
| include Singleton | |
| def initialize | |
| sdk_key = '<Your_SDK_Key>' |
| func handleRequest(c *gin.Context) { | |
| userObj := map[string]string{"userId": "user123"} | |
| jsonString, _ := json.Marshal(userObj) | |
| req, _ := http.NewRequest("POST", "http://localhost:8080/v1/activate", bytes.NewBuffer(jsonString)) | |
| q := req.URL.Query() | |
| q.Add("featureKey", "hello_world") |
| <html> | |
| <head> | |
| <script src="https://unpkg.com/@optimizely/[email protected]/dist/optimizely.browser.umd.min.js"></script> | |
| <script src="https://cdn.optimizely.com/datafiles/V7kE2tbrJaYGmtRF5W5QXf.json/tag.js"></script> | |
| </head> | |
| <body> | |
| <h1>Hello World</h1> | |
| <p id="subtitle">This is a subtitle</p> | |
| </body> | |
| <script> |
Requirements: Node >= 8.1 and npm >= 5.6