Giter VIP home page Giter VIP logo

optimizely-cordova-plugin's Introduction

Optimizely Cordova Plugin

iOS Build Build Status

Android Build Circle CI

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!

Table of Contents

  1. Usage
  2. Available Features
  3. Live Variables
  4. Code Blocks
  5. APIs

Installation

Edge

cordova plugin add https://github.com/optimizely/optimizely-cordova-plugin

Stable (via npm)

cordova plugin add cordova-plugin-optimizely

Uninstall plugin

Use the cordova CLI to remove the plugin

cordova plugin remove cordova-plugin-optimizely

Start A/B Testing!

  1. If you haven't already, sign up for an account at Optimizely

  2. Create a Android or iOS project

  3. Grab your project token

  4. Register Live Variables and Code Blocks

  5. Call startOptimizely with your token

window.optimizely.startOptimizely(<token>)
  .then(
    function(result) {
      // success callback
    },
    function(error) {
      // error callback
    }
  )

Available Features

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.

1. Live Variables

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
    }
  );

2. Code Blocks

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
  }
)

APIs

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.