PriceLab

PriceLab SDK

The PriceLab SDK is our JavaScript library for integrating PriceLab with your website. Use the PriceLab SDK to deploy price tests, surveys, and other experiments. You can get up and running in just three steps.

1. Install

Include the PriceLab SDK on your website by adding a script tag to the <head> of every HTML file on your site.

<script src="https://cdn.pricelab.ai/sdk/v1/pricelab.js"></script>

This script should always be loaded directly from https://cdn.pricelab.ai, rather than included in a bundle or hosted yourself.

2. Setup

Next, create an instance of the PriceLab class by providing your public API key as a parameter to the PriceLab() constructor.

const pl = new PriceLab('YOUR_API_KEY');

Your production API key is scoped to your website's domain. The SDK will only work when installed on the correct domain.

3. Initialize

To correctly target pricing experiments and process the results, the PriceLab SDK needs to know which user is currently signed in to your application.

When a user signs in initialize the SDK by providing the user's ID as a parameter to the PriceLab.init() method.

try {
    await pl.init('USER_ID');
  } catch (err) {
    console.error('Failed to initialize PriceLab:', err);
  }

If your project does not support async/await you can initialize the SDK using traditional promises.

pl.init('USER_ID')
    .then(function () {
      // Succesfully initialized PriceLab!
    })
    .catch(function (err) {
      console.error('Failed to initialize PriceLab:', err);
    });

The SDK should only be initialized once after the user has logged in.

That's it

The SDK will now automatically display the appropriate pricing experiments to your users.

Questions? Contact PriceLab Support