
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
cordova-plugin-optimizely
Advanced tools
Cordova Plugin for the Optimizely iOS and Android SDKs
Allows developers developing hybrids apps using Cordova platforms such as Phonegap, Crosswalk, Ionic, Intel XDK to use the Optimizely SDKs for A/B testing and beyond!
cordova plugin add https://github.com/optimizely/optimizely-cordova-plugin
cordova plugin add cordova-plugin-optimizely
Use the cordova CLI to remove the plugin
cordova plugin remove cordova-plugin-optimizely
If you haven't already, sign up for an account at Optimizely
Create a Android or iOS project
Grab your project token
Register Live Variables and Code Blocks
Call startOptimizely with your token
window.optimizely.startOptimizely(<token>)
.then(
function(result) {
// success callback
},
function(error) {
// error callback
}
)
The optimizely cordova plugin allows cordova based apps to use the Live Variable and Code Block features of the Optimizely Mobile SDKs. Visual experiments are currently not supported.
Live Variables allow you to designate variables in your app that can be assigned values in the Optimizely editor. These values can be modified by Optimizely's editor even after you have released your app to the app store. For example, you might want to create an experiment that tests various values for gravity.
To register a live variable you can call the Optimizely API:
window.optimizely.numberVariable('gravity', 9.8)
.then(
function() {
// this callback function will execute once the variable has been registered with the Optimizely SDK
},
function(errorMsg) {
// error callback
}
);
To use the live variable:
window.optimizely.numberForKey('gravity')
.then(
function(variableValue) {
// this callback function will execute once the plugin has retrieved the stored value for the given variable key.
},
function(errorMsg) {
// error callback
}
);
Code Blocks allow developers to create variations that execute different code paths. For example, one use case might be to test various checkout flows.
To register a code block:
window.optimizely.codeBlock('checkoutFlow', ['single_page', 'multi_page'])
.then(
function() {
// success callback
},
function(errorMsg) {
// error callback
}
);
To use a code block:
window.optimizely.executeCodeBlock(
'checkoutFlow',
[
function() {
// single page checkout flow
},
function() {
// multi page checkout flow
}
],
this,
function(errorMsg) {
// error callback
}
)
Aside from the APIs for registering and using Live Variables and Code Blocks, the plugin also exposes the following APIs:
window.optimizely.enabledEditor()
window.optimizely.refreshExperimentData()
window.optimizely.setCustomTag(tagName, tagValue)
window.optimizely.startOptimizely(projectToken)
window.optimizely.trackEvent('eventName')
window.optimizely.trackRevenueWithDescription(100, 'revenueDescription')
All API calls return a Promise object using the ES6 promise specification.
For more information on these APIs please visit Android Docs or iOS Docs
More documentation coming soon!
FAQs
Cordova plugin for the Optimizely Mobile SDKs
The npm package cordova-plugin-optimizely receives a total of 2 weekly downloads. As such, cordova-plugin-optimizely popularity was classified as not popular.
We found that cordova-plugin-optimizely demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.