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

mida-node

v1.0.4

Published

Mida Node.js integration

Downloads

84

Readme

Mida.so - Server-side A/B Testing and Feature Flags

This is a server-side A/B testing and feature flags code that allows you to integrate with the Mida platform. The code is written in JavaScript and can be used in a Node.js environment.

Prerequisites

Before using this code, make sure you have the following set up:

  • Node.js installed on your machine
  • A Mida.so account with project and experiment key

Installation

  1. Install the necessary dependencies by running the following command:
npm install mida-node

Usage

To use the server-side A/B testing and feature flags code, follow these steps:

  1. Import the Mida class into your code:
const Mida = require('mida-node');
  1. Create an instance of the Mida class by providing your Mida project key:
const mida = new Mida('YOUR_PROJECT_KEY');

A/B Testing

  1. Use the getExperiment method to retrieve the current version of an experiment for a user. You need to provide the experiment key and the distinct ID of the user:
const experimentKey = 'EXPERIMENT_KEY';
const distinctId = 'USER_DISTINCT_ID';
const version = await mida.getExperiment(experimentKey, distinctId);
if (version === 'Control') {
// Handle Control logic
}
if (version === 'Variant 1') {
// Handle Variant 1 logic
}
// Depending on how many variants you have created
if (version === 'Variant 2') {
// Handle Variant 2 logic
}
  1. Use the setEvent method to log an event for a user. You need to provide the event name and the distinct ID of the user:
const eventName = 'EVENT_NAME';
const distinctId = 'USER_DISTINCT_ID';
await mida.setEvent(eventName, distinctId)

User Attributes

  1. Use the setAttribute method to set user attributes for a specific user. You need to provide the distinct ID of the user and an object containing the attribute key-value pairs:
const distinctId = 'USER_DISTINCT_ID';
const attributes = {
gender: 'male',
company_name: 'Apple Inc'
};
await mida.setAttribute(distinctId, attributes);

Feature Flags

  1. Use the isFeatureEnabled method to check if a feature flag is enabled for the current user:
const featureFlagKey = 'FEATURE_FLAG_KEY';
const isEnabled = await mida.isFeatureEnabled(featureFlagKey);
if (isEnabled) {
// Feature flag is enabled, perform corresponding actions
} else {
// Feature flag is disabled, perform alternative actions
}
  1. Use the onFeatureFlags method to reload the feature flags for the current user:
await mida.onFeatureFlags();

API Reference

Mida(projectKey, options)

  • projectKey: (required) Your Mida project key.
  • options: (optional) An object of additional options.

getExperiment(experimentKey, distinctId)

  • experimentKey: (required) The key of the experiment you want to get the version of.
  • distinctId: (required) The distinct ID of the user. Returns a Promise that resolves to the version of the experiment.

setEvent(eventName, distinctId)

  • eventName: (required) The name of the event you want to log.
  • distinctId: (required) The distinct ID of the user. Returns a Promise that resolves when the event is successfully logged.

setAttribute(distinctId, properties)

  • distinctId: (required) The distinct ID of the user.
  • properties: (required) An object containing the attribute key-value pairs. Returns a Promise that resolves when the attributes are successfully set.

isFeatureEnabled(key)

  • key: (required) The key of the feature flag you want to check. Returns a Promise that resolves to a boolean indicating whether the feature flag is enabled or not.

onFeatureFlags(distinctId)

  • distinctId: (optional) The distinct ID of the user. Returns a Promise that resolves when the feature flags are successfully reloaded.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please create a pull request.

License

This code is open source and available under the MIT License.