npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@molassesapp/molasses-js

v0.8.0

Published

A JavaScript/Typescript SDK for Molasses. It allows you to evaluate user's status for a feature. It also helps simplify logging events for A/B testing.

Downloads

7

Readme

Molasses-JS

codecov Build status

Molasses-JS includes the Browser (with TypeScript support) SDK for Molasses. It allows you to evaluate a user's status for a feature. It also helps simplify logging events for A/B testing.

Molasses-JS - Once initialized, it takes microseconds to evaluate if a user is active.

Install

npm install @molassesapp/molasses-js

yarn add @molassesapp/molasses-js

<script src="https://cdn.jsdelivr.net/npm/@molassesapp/[email protected]/dist/molasses.min.js"></script>

Usage

To Require:

import { MolassesClient } from "@molassesapp/molasses-js"
// or
const { MolassesClient } = require("@molassesapp/molasses-js")
// or if using a script tag
var MolassesClient = MolassesJS.MolassesClient

Start by initializing the client with an APIKey. If you decide not to track analytics events (experiment started, experiment success) you can turn them off by setting the sendEvents field to false

// Initialize with your API Key
const client = new MolassesClient({
  APIKey: "testapikey",
})

// Then init which is a promise
await client.init()

Check if feature is active

You can call isActive with the key name and optionally a user's information. The ID field is used to determine whether a user is part of a percentage of users and uniquely identies a user. If you have other user segments based on user parameterss you can pass those in the params field.

// Once initialized you can start calling isActive
client.isActive("FOO_TEST", {
  id: "123",
  params: {
    isBetaUser: "true",
  },
})

You can check if a feature is active for a user who is anonymous by just calling isActive with the key. You won't be able to do percentage roll outs or track that user's behavior.

client.isActive("FOO_TEST")

Track Events

If you want to track any event call the track method. track takes the event's name, the molasses User and any additional parameters for the event.

client.track(
  "Checkout complete",
  {
    version: "v2.3.0",
  },
  {
    id: "baz",
    params: {
      teamId: "12356",
    },
  },
)

Experiments

If you are not auto tracking experiments, to track whether an experiment has started you can call the experimentStarted method. experimentStarted takes the feature's name, the molasses User and any additional parameters for the event.

client.experimentStarted(
  "GOOGLE_SSO",
  {
    version: "v2.3.0",
  },
  {
    id: "baz",
    params: {
      teamId: "12356",
    },
  },
)

To track whether an experiment was successful you can call the experimentSuccess method. experimentSuccess takes the feature's name, the molasses User and any additional parameters for the event.

client.experimentSuccess(
  "GOOGLE_SSO",

  {
    version: "v2.3.0",
  },
  {
    id: "baz",
    params: {
      teamId: "12356",
    },
  },
)

Methods

new MolassesClient(options)

Creates a new Molasses client. It takes a set of options.

Options

| Field | Required | Type | Description | | ---------------- | -------- | --------- | ------------------------------------------------------------------------------------ | | apiKey | required | string | The API Key for the current environment | | URL | optional | string | the base URL for Molasses | | autoSendEvents | optional | boolean | Whether to automatically send analytic events back to Molasses. Defaults to false. |

init(): Promise<void>

Fetches configuration of features and begins polling

isActive(featureKey: string): boolean

Will check if feature is active for ALL users

isActive(featureKey: string, user: User): boolean

Will check if the feature is active for this particular based on the segment they are in.

track(eventName: string, additionalInformation: string[InputType], user: User)

Will send a track event. This includes the event name, the user data, and other metadata. If you want to include additional metadata use the additionalInformation argument.

experimentStarted(featureKey: string, additionalInformation: string[InputType], user: User)

Will send an event started message when a user starts an a/b tests. This includes, whether user was in the experimental group (control or experiment), the experiment that was being tested and other metadata. If you want to include additional metadata use the additionalInformation argument.

experimentSuccess(featureKey: string, additionalInformation: string[InputType], user: User): void

Will send an event success message when a user completes a set goal. This includes, whether user was in the experimental group (control or experiment), the experiment that was being tested and other metadata. If you want to include additional metadata use the additionalInformation argument.

identify(user: User): void

Sets the user as the default user for isActive and experimentSuccess so those methods can be called without a User

resetUser(): void

Resets the user from identify to undefined

reinit(): Promise<void>

Goes to the Molasses server and fetchs a new configuraiton