Get started with optimizely CDN

Apache-2.0 licensed

Optimizely is a client-side A/B testing and personalization library for JS websites.

Tags:
  • optimizely

Stable version

Copied!

How to start using optimizely CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with optimizely CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/optimizely/1.6.0/optimizely.min.js"></script>
</head>
<body>
  <button id="button">Click me</button>

  <script>
    // Initialize Optimizely with your project ID
    optimizely.init({
      projectId: 'YOUR_PROJECT_ID',
      webFonts: {
        active: ['Open Sans', 'Roboto'],
        inactive: ['Arial', 'sans-serif']
      }
    });

    // Define your variation
    optimizely.registerVariation('buttonColor', function(experiment) {
      return {
        'button': {
          'backgroundColor': experiment.variation.backgroundColor
        }
      };
    });

    // Create and start an experiment
    optimizely.create('YOUR_EXPERIMENT_NAME', function(experiment) {
      experiment.run('buttonColor', function() {
        document.querySelector('#button').style.backgroundColor = this.variation.button.backgroundColor;
      });
    });
  </script>
</body>
</html>
Copied!

All versions