{"id":13538331,"url":"https://github.com/optimizely/javascript-sdk","last_synced_at":"2025-05-15T04:04:25.610Z","repository":{"id":37883495,"uuid":"64253025","full_name":"optimizely/javascript-sdk","owner":"optimizely","description":"JavaScript SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy).","archived":false,"fork":false,"pushed_at":"2025-05-14T22:47:49.000Z","size":9373,"stargazers_count":81,"open_issues_count":18,"forks_count":83,"subscribers_count":95,"default_branch":"master","last_synced_at":"2025-05-14T23:29:26.700Z","etag":null,"topics":["optimizely-environment-prod","optimizely-environment-public","optimizely-owner-px"],"latest_commit_sha":null,"homepage":"https://www.optimizely.com/products/experiment/feature-experimentation/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/optimizely.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-26T20:40:32.000Z","updated_at":"2025-05-14T13:52:24.000Z","dependencies_parsed_at":"2024-04-08T13:52:54.671Z","dependency_job_id":"f893f74c-4b28-489e-84cc-aee822ea5476","html_url":"https://github.com/optimizely/javascript-sdk","commit_stats":{"total_commits":648,"total_committers":53,"mean_commits":"12.226415094339623","dds":0.8302469135802469,"last_synced_commit":"1adcbdb8dc435afb5583b150678d1112d941c32b"},"previous_names":[],"tags_count":144,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fjavascript-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fjavascript-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fjavascript-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fjavascript-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/optimizely","download_url":"https://codeload.github.com/optimizely/javascript-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249178,"owners_count":22039027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["optimizely-environment-prod","optimizely-environment-public","optimizely-owner-px"],"created_at":"2024-08-01T09:01:10.040Z","updated_at":"2025-05-15T04:04:25.550Z","avatar_url":"https://github.com/optimizely.png","language":"TypeScript","readme":"# Optimizely JavaScript SDK\n\n[![npm](https://img.shields.io/npm/v/%40optimizely%2Foptimizely-sdk.svg)](https://www.npmjs.com/package/@optimizely/optimizely-sdk)\n[![npm](https://img.shields.io/npm/dm/%40optimizely%2Foptimizely-sdk.svg)](https://www.npmjs.com/package/@optimizely/optimizely-sdk)\n[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/optimizely/javascript-sdk/javascript.yml)](https://github.com/optimizely/javascript-sdk/actions)\n[![Coveralls](https://img.shields.io/coveralls/optimizely/javascript-sdk.svg)](https://coveralls.io/github/optimizely/javascript-sdk)\n[![license](https://img.shields.io/github/license/optimizely/javascript-sdk.svg)](https://choosealicense.com/licenses/apache-2.0/)\n\nThis repository houses the JavaScript SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).\n\nOptimizely Feature Experimentation is an A/B testing and feature management tool for product development teams that enables you to 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](https://www.optimizely.com/products/experiment/feature-experimentation/), or see the [developer documentation](https://docs.developers.optimizely.com/feature-experimentation/docs/introduction).\n\nOptimizely Rollouts is [free feature flags](https://www.optimizely.com/free-feature-flagging/) 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.\n\n---\n\n## Get Started\n\n\u003e For **Browser** applications, refer to the [JavaScript SDK's developer documentation](https://docs.developers.optimizely.com/feature-experimentation/docs/javascript-sdk) for detailed instructions on getting started with using the SDK within client-side applications.\n\n\u003e For **Node.js** applications, refer to the [JavaScript (Node) variant of the developer documentation](https://docs.developers.optimizely.com/feature-experimentation/docs/javascript-node-sdk).\n\n\u003e For **Edge Functions**, we provide starter kits that utilize the Optimizely JavaScript SDK for the following platforms:\n\u003e - [Akamai (Edgeworkers)](https://github.com/optimizely/akamai-edgeworker-starter-kit)\n\u003e - [AWS Lambda@Edge](https://github.com/optimizely/aws-lambda-at-edge-starter-kit)\n\u003e - [Cloudflare Worker](https://github.com/optimizely/cloudflare-worker-template)\n\u003e - [Fastly Compute@Edge](https://github.com/optimizely/fastly-compute-starter-kit)\n\u003e - [Vercel Edge Middleware](https://github.com/optimizely/vercel-examples/tree/main/edge-middleware/feature-flag-optimizely)\n\u003e\n\u003e Note: We recommend using the **Lite** version of the sdk for edge platforms. These starter kits also use the **Lite** variant of the JavaScript SDK which excludes the datafile manager and event processor packages.\n\n### Prerequisites\n\nEnsure the SDK supports all of the platforms you're targeting. In particular, the SDK targets modern ES5-compliant JavaScript environment. We officially support:\n- Node.js \u003e= 16.0.0. By extension, environments like AWS Lambda, Google Cloud Functions, and Auth0 Webtasks are supported as well. Older Node.js releases likely work too (try `npm test` to validate for yourself), but are not formally supported.\n- Modern Web Browsers, such as Microsoft Edge 84+, Firefox 91+, Safari 13+, and Chrome 102+, Opera 76+\n\nIn addition, other environments are likely compatible but are not formally supported including:\n- Progressive Web Apps, WebViews, and hybrid mobile apps like those built with React Native and Apache Cordova.\n- [Cloudflare Workers](https://developers.cloudflare.com/workers/) and [Fly](https://fly.io/), both of which are powered by recent releases of V8.\n- Anywhere else you can think of that might embed a JavaScript engine. The sky is the limit; experiment everywhere! 🚀\n\n### Requirements\n\n* JavaScript (Browser): Modern web browser that is ES5-compliant.\n\n* JavaScript (Node): Node 16.0.0+\n\n\n### Install the SDK\n\nOnce you've validated that the SDK supports the platforms you're targeting, fetch the package from [NPM](https://www.npmjs.com/package/@optimizely/optimizely-sdk):\n\nUsing `npm`:\n```sh\nnpm install --save @optimizely/optimizely-sdk\n```\n\nUsing `yarn`:\n```sh\nyarn add @optimizely/optimizely-sdk\n```\n\nUsing `pnpm`:\n```sh\npnpm add @optimizely/optimizely-sdk\n```\n\nUsing `deno` (no installation required):\n```javascript\nimport optimizely from \"npm:@optimizely/optimizely-sdk\"\n```\n## Use the JavaScript SDK (Browser)\n\nSee the [Optimizely Feature Experimentation developer documentation for JavaScript (Browser)](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/javascript-sdk) to learn how to set up your first JavaScript project and use the SDK for client-side applications.\n\n### Initialization (Browser)\n\nThe package has different entry points for different environments. The browser entry point is an ES module, which can be used with an appropriate bundler like **Webpack** or **Rollup**. Additionally, for ease of use during initial evaluations you can include a standalone umd bundle of the SDK in your web page by fetching it from [unpkg](https://unpkg.com/):\n\n```html\n\u003cscript src=\"https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- You can also use the unminified version if necessary --\u003e\n\u003cscript src=\"https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.js\"\u003e\u003c/script\u003e\n```\n\nWhen evaluated, that bundle assigns the SDK's exports to `window.optimizelySdk`. If you wish to use the asset locally (for example, if unpkg is down), you can find it in your local copy of the package at dist/optimizely.browser.umd.min.js. We do not recommend using this method in production settings as it introduces a third-party performance dependency.\n\nAs `window.optimizelySdk` should be a global variable at this point, you can continue to use it like so:\n\n```javascript\nconst optimizelyClient = window.optimizelySdk.createInstance({\n  sdkKey: '\u003cYOUR_SDK_KEY\u003e',\n  // datafile: window.optimizelyDatafile,\n  // etc.\n});\n\noptimizelyClient.onReady().then(({ success, reason }) =\u003e {\n  if (success) {\n      // Create the Optimizely user context, make decisions, and more here!\n  }\n});\n```\n\nRegarding `EventDispatcher`s: In Node.js and browser environments, the default `EventDispatcher` is powered by the [`http/s`](https://nodejs.org/api/http.html) modules and by [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Browser_compatibility), respectively. In all other environments, you must supply your own `EventDispatcher`.\n\n## Use the JavaScript SDK (Node)\n\nSee the [Optimizely Feature Experimentation developer documentation for JavaScript (Node)](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/javascript-node-sdk) to learn how to set up your first JavaScript project and use the SDK for server-side applications.\n\n### Initialization (Node)\n\nThe package has different entry points for different environments. The node entry point is CommonJS module.\n\n```javascript\nconst optimizelySdk = require('@optimizely/optimizely-sdk');\n\nconst optimizelyClient = optimizelySdk.createInstance({\n  sdkKey: '\u003cYOUR_SDK_KEY\u003e',\n  // datafile: window.optimizelyDatafile,\n  // etc.\n});\n\noptimizelyClient.onReady().then(({ success, reason }) =\u003e {\n  if (success) {\n      // Create the Optimizely user context, make decisions, and more here!\n  }\n});\n```\n\nRegarding `EventDispatcher`s: In Node.js environment, the default `EventDispatcher` is powered by the [`http/s`](https://nodejs.org/api/http.html) module.\n\n## SDK Development\n\n### Unit Tests\n\nThere is a mix of testing paradigms used within the JavaScript SDK which include Mocha, Chai, Karma, and Jest, indicated by their respective `*.tests.js` and `*.spec.ts` filenames.\n\nWhen contributing code to the SDK, aim to keep the percentage of code test coverage at the current level ([![Coveralls](https://img.shields.io/coveralls/optimizely/javascript-sdk.svg)](https://coveralls.io/github/optimizely/javascript-sdk)) or above.\n\nTo run unit tests on the primary JavaScript SDK package source code, you can take the following steps:\n\n1. On your command line or terminal, navigate to the `~/javascript-sdk/packages/optimizely-sdk` directory.\n2. Ensure that you have run `npm install` to install all project dependencies.\n3. Run `npm test` to run all test files.\n4. (For cross-browser testing) Run `npm run test-xbrowser` to run tests in many browsers via BrowserStack.\n5. Resolve any tests that fail before continuing with your contribution.\n\nThis information is relevant only if you plan on contributing to the SDK itself.\n\n```sh\n# Prerequisite: Install dependencies.\nnpm install\n\n# Run unit tests.\nnpm test\n\n# Run unit tests in many browsers, currently via BrowserStack.\n# For this to work, the following environment variables must be set:\n#   - BROWSER_STACK_USERNAME\n#   - BROWSER_STACK_PASSWORD\nnpm run test-xbrowser\n```\n\n[/.github/workflows/javascript.yml](/.github/workflows/javascript.yml) contains the definitions for `BROWSER_STACK_USERNAME` and `BROWSER_STACK_ACCESS_KEY` used in the GitHub Actions CI pipeline. When developing locally, you must provide your own credentials in order to run `npm run test-xbrowser`. You can register for an account for free on [the BrowserStack official website here](https://www.browserstack.com/).\n\n### Contributing\n\nFor more information regarding contributing to the Optimizely JavaScript SDK, please read [Contributing](CONTRIBUTING.md).\n\n## Special Notes\n\n### Migrating from 4.x.x\n\nThis version represents a major version change and, as such, introduces some breaking changes. Please refer to the [Changelog](CHANGELOG.md#500---january-19-2024) for more details.\n\n### Feature Management access\n\nTo access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely customer success manager.\n\n## Credits\n\n`@optimizely/optimizely-sdk` is developed and maintained by [Optimizely](https://optimizely.com) and many [contributors](https://github.com/optimizely/javascript-sdk/graphs/contributors). If you're interested in learning more about what Optimizely Feature Experimentation can do for your company you can visit the [official Optimizely Feature Experimentation product page here](https://www.optimizely.com/products/experiment/feature-experimentation/) to learn more.\n\nFirst-party code (under `packages/optimizely-sdk/lib/`, `packages/datafile-manager/lib`, `packages/datafile-manager/src`, `packages/datafile-manager/__test__`, `packages/event-processor/src`, `packages/event-processor/__tests__`, `packages/logging/src`, `packages/logging/__tests__`, `packages/utils/src`, `packages/utils/__tests__`) is copyright Optimizely, Inc. and contributors, licensed under Apache 2.0.\n\n### Other Optimizely SDKs\n\n- Agent - https://github.com/optimizely/agent\n\n- Android - https://github.com/optimizely/android-sdk\n\n- C# - https://github.com/optimizely/csharp-sdk\n\n- Flutter - https://github.com/optimizely/optimizely-flutter-sdk\n\n- Go - https://github.com/optimizely/go-sdk\n\n- Java - https://github.com/optimizely/java-sdk\n\n- PHP - https://github.com/optimizely/php-sdk\n\n- Python - https://github.com/optimizely/python-sdk\n\n- React - https://github.com/optimizely/react-sdk\n\n- Ruby - https://github.com/optimizely/ruby-sdk\n\n- Swift - https://github.com/optimizely/swift-sdk","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fjavascript-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foptimizely%2Fjavascript-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fjavascript-sdk/lists"}