Code Monkey home page Code Monkey logo

mida-php's Introduction

Mida PHP

Mida is a PHP library for interacting with the Mida API, allowing you to perform experiments, track events, and manage feature flags in your projects.

Installation

To use Mida in your PHP project, you can install it using Composer. Simply add the following lines to your composer.json file and run the composer install command:

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "mida-php",
            "version": "1.0",
            "source": {
                "url": "https://github.com/mida-so/mida-php.git",
                "type": "git",
                "reference": "master"
            }
        }
    }
],
"require" : {
    "guzzlehttp/guzzle": "^7.0"
}

Usage

To use the Mida class in your project, follow these steps:

  1. Include the Mida class in your PHP file:

    require_once 'Mida.php';
  2. Create an instance of the Mida class by passing your Mida project key and optional configuration options:

    $publicKey = "your_mida_project_key";
    $options = []; // Optional configuration options
    $mida = new Mida($publicKey, $options);
  3. Perform experiments by calling the getExperiment method and passing the experiment key and user distinct ID:

    $experimentKey = "your_experiment_key";
    $distinctId = "user_distinct_id";
    try {
        $version = $mida->getExperiment($experimentKey, $distinctId);
        if ($version) {
            echo "Experiment version: $version";
        } else {
            echo "No version available for this experiment";
        }
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
  4. Track events by calling the setEvent method and passing the event name, user distinct ID, and optional event attributes:

    $eventName = "your_event_name";
    $distinctId = "user_distinct_id";
    $properties = [
        "plan" => "Basic",
        "paid" => "yes"
    ];
    
    try {
        $mida->setEvent($eventName, $distinctId, $properties);
        echo "Event tracked successfully";
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
  5. Set user attributes by calling the setAttribute method and passing the user distinct ID and properties:

    $distinctId = "user_distinct_id";
    $properties = [
        "name" => "John Doe",
        "email" => "[email protected]"
    ];
    
    try {
        $mida->setAttribute($distinctId, $properties);
        echo "User attributes set successfully";
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
  6. Check if a feature flag is enabled by calling the isFeatureEnabled method and passing the feature flag key:

    $featureFlagKey = "your_feature_flag_key";
    
    if ($mida->isFeatureEnabled($featureFlagKey)) {
        echo "Feature flag is enabled";
    } else {
        echo "Feature flag is disabled";
    }
  7. Reload feature flags by calling the reloadFeatureFlags method:

    try {
        $mida->reloadFeatureFlags();
        echo "Feature flags reloaded successfully";
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }

Contributing

Contributions to Mida are welcome! If you encounter any bugs or have suggestions for improvement, please open an issue or submit a pull request.

License

This library is released under the MIT License.

Contact

For any inquiries or support requests, please contact our team at [email protected].

mida-php's People

Contributors

donaldng avatar

Watchers

 avatar

mida-php's Issues

Adding attribute to an event

Hello,

I am using server side for the varients featuring the getExperiment is working fine, But I need to pass attributes to an event. Like once a goal is achieved/ an event is triggered, some data should pass with event for maintaining clear vision of the records. Can we do that, Please let me know.

An another problem that I've face is that when I pass attributes to a user. In the events user list at the dashboard the attribute column is empty, Like where the user attributes will be visible on my mida console.

Thanks!

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.