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.
Before using this code, make sure you have the following set up:
- Flutter and Dart installed on your machine
- A Mida.so account with project and experiment key
- Download this plugin
- Import the necessary dependencies by adding in as plugin with path as following command into pubspec.yaml:
dev_dependencies:
mida:
path: ../mida-core
To use the server-side A/B testing and feature flags code, follow these steps:
- Import the
Mida
package into your code:
import 'package:mida/mida.dart';
- Create an instance of the
Mida
class by providing your Mida project key:
final mida = Mida(publicKey: 'YOUR_PROJECT_KEY');
- 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:
final version = await mida.getExperiment(experimentKey: 'EXPERIMENT_KEY', distinctId: 'USER_DISTINCT_ID');
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
}
- 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:
final event = await mida.setEvent(eventName: 'EVENT_NAME', distinctId: 'USER_DISTINCT_ID');
- 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:
final track = await mida.setAttribute(properties: {gender: 'male', company_name: 'Apple Inc'}, distinctId: 'USER_DISTINCT_ID');
projectKey
: (required) Your Mida project key.userId
: (optional) Your default user ID.
experimentKey
: (required) The key of the experiment you want to get the version of.distinctId
: (optional) The distinct ID of the user that other than default user ID.- Returns a Response that resolves to the version of the experiment.
eventName
: (required) The name of the event you want to log.distinctId
: (optional) The distinct ID of the user that other than default user ID.- Returns a Response that resolves when the event is successfully logged.
properties
: (required) An object containing the attribute key-value pairs.distinctId
: (optional) The distinct ID of the user that other than default user ID.- Returns a Response that resolves when the attributes are successfully set.
Contributions are welcome! If you find any issues or have suggestions for improvement, please create a pull request.
This code is open source and available under the MIT License.