Git Product home page Git Product logo

mida-node's Introduction

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 distinctId = 'USER_DISTINCT_ID';
const featureFlagKey = 'FEATURE_FLAG_KEY';

// Use the `onFeatureFlags` method to reload the feature flags for the current user:
await mida.onFeatureFlags(distinctId);

const isEnabled = await mida.isFeatureEnabled(featureFlagKey);
if (isEnabled) {
// Feature flag is enabled, perform corresponding actions
}

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.

mida-node's People

Contributors

donaldng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.