Giter VIP home page Giter VIP logo

vwo-php-sdk's Introduction

VWO PHP SDK

Latest Stable Version CI Coverage StatusLicense

This open source library provides you server-side testing capabilities.

Requirements

PHP >= 5.6

Installation

Install the latest version with

composer require vwo/vwo-php-sdk

Basic Usage

Use the below code for inital setup.

<?php
require_once('vendor/autoload.php');
require_once('userStorage.php'); // Optional :if you are using UserStorage service feature
require_once('customLogger.php');// Optional :if you are using custom logging feature

use vwo\VWO;

$accountId = REPLACE_WITH_VWO_ACCOUNT_ID; // eg: 123456
$sdkKey = 'REPLACE_WITH_TOKEN'; // eg: can be found in VWO app - FullStack project
$campaignKey = 'CAMPAIGN_UNIQUE_TEST_KEY';
$userId = 'USER_ID';
$goalIdentifier = 'REPLACE_WITH_CAMPAIGN_GOAL_IDENTIFIER';

// to fetch the settings i.e campaigns, variations and goals
$settingsFile = VWO::getSettingsFile($accountId, $sdkKey);

$sdkConfig = [
  'settingsFile' => $settingsFile,
  'isDevelopmentMode' => 0,  // optional: 1 to enable the dev mode
  'logging' => new CustomLogger(), // optional
  'userStorageService' => new userStorageService() // optional
];

$vwoClient = new VWO($sdkConfig);

// to get the variation name along with add a visitor hit to vwo app stats
$variation = $vwoClient->activate($campaignKey, $userId, $options);
// Or, to get the variation name
$variation = $vwoClient->getVariationName($campaignKey, $userId, $options);

// add code here to use variation
//...

/**
*send the track api hit to the vwo app stats to increase conversions
* $revenue is optional send in case if there is any revenue inside $options
*/

$vwoClient->track($campaignKey, $userId, $goalIdentifier, $options);

Code for implementing User Storage Service

<?php
require_once('vendor/autoload.php');
use vwo\Utils\UserStorageInterface;
Class UserStorage implements UserStorageInterface{
  /**
    * @param $userId
    * @param $campaignKey
    *
    * @return array
    */
  public function get($userId, $campaignKey) {
    // search in DB/Storage system
    $variation = $db->fetch($userId, $campaignKey); // replace with your implementation

    return[
      'userId' => $userId,
      'campaignKey' => $campaignKey,
      'variationName' => $variation
    ];
  }

  /**
    * @param $campaignUserMapping
    * @return bool - could be changed
    */
  public function set($campaignUserMapping) {
    // S...code to store in DB/storage system
    return True;
  }
}

Code for implementing Custom Logger

<?php
require_once('vendor/autoload.php');
use vwo\Logger\LoggerInterface;

/**
 * Class CustomLogger
 */
Class CustomLogger implements LoggerInterface{
  /**
    * @param $message
    * @param $level
    *
    * @return
    */
  public function log($message, $level){
    // use $level and log $message to either print or store them for later use
  }

}

Documentation

Refer Official VWO Documentation

Third-party Resources and Credits

Refer third-party-attributions.txt

Changelog

Refer CHANGELOG.md

Development and Test Cases

  1. Set development environment
composer run-script start
  1. Run test cases
composer run-script test
  1. Run linter
composer run-script test
  1. Run code beautifier
composer run-script phpcbf

License

Apache License, Version 2.0

Copyright 2019-2022 Wingify Software Pvt. Ltd.

vwo-php-sdk's People

Contributors

abbas-khaliq avatar griffinmarc avatar kasperfranz avatar rohitesh-wingify avatar softvar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vwo-php-sdk's Issues

Laravel requires a higher level of Ramsey/UUID

Hello,

I'm attempting to install this SDK in a new project after having implemented it in another project. The new project is a Laravel project using v9.2.0. This version of Laravel requires ramsey/uuid with a version of ^4.2.2.

In the initial commit for vwo-php-sdk, ramsey/uuid is required with a version of ^3.8. Because of this lower version of the library, I'm unable to install the vwo-php-sdk in my project.

Here's the output from when I try to require the package:

composer require vwo/vwo-php-sdk

Your requirements could not be resolved to an installable set of packages.

Problem 1
    - Root composer.json requires vwo/vwo-php-sdk ^1.36 -> satisfiable by vwo/vwo-php-sdk[v1.36.0, v1.36.1, v1.36.2].
    - vwo/vwo-php-sdk[v1.36.0, ..., v1.36.2] require ramsey/uuid ^3.8 -> found ramsey/uuid[3.8.0, ..., 3.x-dev] but the package is fixed to 4.2.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

composer require vwo/vwo-php-sdk -W

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires vwo/vwo-php-sdk ^1.36 -> satisfiable by vwo/vwo-php-sdk[v1.36.0, v1.36.1, v1.36.2].
    - vwo/vwo-php-sdk[v1.36.0, ..., v1.36.2] require ramsey/uuid ^3.8 -> found ramsey/uuid[3.8.0, ..., 3.x-dev] but these were not loaded, likely because it conflicts with another require.

composer require vwo/vwo-php-sdk:*
no matches found: vwo/vwo-php-sdk:*

According to the ramsey/uuid page on the major version update, it should require only minimal changes to update to version 4. If you'd like, I could create a pull request to update this. What I think may work well is this requirement:

If you maintain a public project that uses ramsey/uuid version 3 and you find that your code does not require any changes to upgrade to version 4, consider using the following version constraint in your project’s composer.json file:

composer require ramsey/uuid:"^3 || ^4"

This should allow other projects with an older version of ramsey/uuid to continue using version 3. What I'm not sure about is if there are any changes that would need to be made in the vwo-php-sdk in order to accomodate version 4. For my part, I don't believe we will be using this UUID functionality, but I'm not sure.

Until this is resolved, I'm planning to use a fork of this repo to be able to install the SDK in Laravel. I will proceed with a forked version of the repo using the require statement listed above, until hopefully this project can be installed in a Laravel project with a recent Laravel version.

The way I am accomplishing this is to have created a branch in my fork called dev-uuid-version (the dev- prefix is important for the convention) with the above change to the requirement.

Then, in the project that I'm trying to install this package in, I've updated the composer.json to include a link to my forked repository.

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/stephenburgess8/vwo-php-sdk"
        }
    ]

Then for the vwo-php-sdk, I've changed the requirement to be

"vwo/vwo-php-sdk": "dev-uuid-version" as per the branch I named that way.

Doing this, I am able to successfully install the vwo-php-sdk. I will continue working on my implementation for now, and will report any bugs or issues I encounter. Let me know if you'd like me to make a pull request with the change in the requirement to allow both versions 3 and 4. Thanks.

Murmur file name

The namespace for murmur is wrong and causing this error on installation on composer 2:

Class vwo\Utils\Murmur located in ./vendor/vwo/vwo-php-sdk/src/Utils/murmur.php does not comply with psr-4 autoloading standard. Skipping.

README - demo code provided uses the wrong function!

On the main README.md file you provide a sample code to illustrate the usage of the SDK, but your using a "private" function getVariation() instead of using the public function getVariationName() of the VWO SDK class.

Wrong function (Private)

<?php
$vwoClient = new VWO($sdkConfig);
$variation = $vwoClient->getVariation($campaignKey, $userId, $options);

Correct function (Public)

<?php
$vwoClient = new VWO($sdkConfig);
$variation = $vwoClient->getVariationName($campaignKey, $userId, $options);

Please correct this, since its misleading.

Thank You

Codesniffer - require

Hi,

Thank you for providing this SDK.

When looking through the composer file for the project - I can see that php_codesniffer is required for this SDK.

I am guessing that php_codesniffer is only required for dev?

If that is the case can it be moved to the dev requirements?

Thank you

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.