Code Monkey home page Code Monkey 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 dev 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 softvar avatar stephenburgess8 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.