Chameleon JavaScript Library
Easily add Chameleon to your product!
The Chameleon JavaScript Library is a set of methods attached to a global chmln
object intended to be used by applications to display Chameleon Experiences to users.
Installation via NPM
This library is available as a package on NPM. To install into a project using NPM with a front-end packager such as Webpack or Browserify:
npm install --save @chamaeleonidae/chmln
You can grab your token then require the lib like a standard Node.js module:
const chmln = require('@chamaeleonidae/chmln');
chmln.init('YOUR_TOKEN', { fastUrl: 'https://fast.chameleon.io/' });
Note for accounts created before 2022-05-21 you must omit the fastUrl
If you're unsure, verify your account-specific instructions on the installation page.
chmln.init('YOUR_TOKEN');
To use Chameleon as first-party (i.e. via chameleon.your-product.com
), first contact us to set this up, then use this updated script with your custom domain.
chmln.init('YOUR_TOKEN', { fastUrl: 'https://chameleon.your-product.com/' });
Usage
First, follow the installation process above. The script loads asynchronously and won’t affect your page loading times.
Next, identify your users by sending a unique ID (this normally matches the UIDs from your database). Without this, Chameleon can’t display Experiences to users. You should also send additional user data (such as “email address”, “role”) or company data (such as “plan type”, “subdomain”) so you can target Experiences to the right users, at the right time.
chmln.identify(USER.ID_IN_DB, {
email: USER.EMAIL,
created: USER.SIGN_UP_DATE,
name: USER.NAME,
role: USER.ROLE,
logins: USER.LOGIN_COUNT,
project: USER.PROJECT_ID,
company: {
uid: COMPANY.ID_IN_DB,
created: COMPANY.SIGN_UP_DATE,
name: COMPANY.NAME,
trial_ends: COMPANY.TRIAL_ENDS,
version: COMPANY.VERSION,
plan: COMPANY.PLAN,
spend: COMPANY.CLV
}
});
Optionally you have the ability to track user events:
chmln.track(PLAN_CHANGED);
chmln.track(ACTIVATED);